-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathplot_curve_finite.py
36 lines (28 loc) · 1.1 KB
/
plot_curve_finite.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import matplotlib.pyplot as plt
import numpy as np
from local.ec.static import XY
from local.ec.core import MAX_COORDINATE, PARAMETER_A, PARAMETER_B
def plot():
# Initialize the plot
fig, ax = plt.subplots()
ax.set_title("Elliptic curve $y^2 \equiv x^3 + {}x + {}$ (mod {})".format(PARAMETER_A.value, PARAMETER_B.value, MAX_COORDINATE))
ax.set_xlabel("x")
ax.set_ylabel("y")
# Initialize an array of zeros (white squares)
points = np.zeros((MAX_COORDINATE, MAX_COORDINATE))
# Add points on the curve
for (dlog, xy) in enumerate(XY):
if xy:
# Inverted coordinates
# because imshow treats first component as rows (y coordinate)
# and second component as columns (x coordinate)
points[xy[1], xy[0]] = 1
ax.text(xy[0], xy[1], str(dlog), ha="center", va="center", color="white")
# Plot the curve
# Set origin to the bottom left
# because imshow places it at the top left by default
ax.imshow(points, cmap='gray_r', origin='lower')
# Show plot
plt.show()
if __name__ == "__main__":
plot()