Python elliptic curves - matplotlib

I teach myself about matplotlib and Python, and it's hard for me to plot for an elliptic curve. I have an equation but i don't do y^2

This is as much trouble as I was able to catch up with myself:

 from mpl_toolkits.axes_grid.axislines import SubplotZero import matplotlib.pyplot as plt import numpy as np from pylab import * def plotGraph(): fig = plt.figure(1) ax = SubplotZero(fig, 111) fig.add_subplot(ax) for direction in ["xzero", "yzero"]: ax.axis[direction].set_axisline_style("-|>") ax.axis[direction].set_visible(True) a = 5; b = 25 x = np.arange(-50.0, 50.0, 1.0) y = pow(x,3) + a*x + b xmin = -50; xmax = 50; ymin = -50; ymax = 50 v = [xmin, xmax, ymin, ymax] ax.axis(v) ax.plot(x, pow(y,2)) #grid() #ax.grid(color='r', linestyle='-', linewidth=2) show() def main(): plotGraph() if __name__ == '__main__': main() 

axis() is because I was also trying to get a clearer diagram with grid lines, and I thought grid() take care of that too, but apparently not. I was also going to try to make it interactive when you click on the points you need, and it calculates, but looking at the documents, it seems that there are many options for interacting with the mouse, but I donโ€™t see the interaction with the mouse that creates an event by clicking at a point on the graph (after I read it a third time, I'm still missing).

I am just switching from a resume summary to matplotlib , but I don't see what I'm doing wrong here. The graph of the elliptic curve leaves, does not even close.

This is probably a beginnerโ€™s mistake, so a junior programmer who takes a second to read this will probably see very quickly why I donโ€™t get the curve I want.

+6
source share
1 answer

Yes, you are right, you do not y^2 . To build an elliptical curve in matplotlib I used this code (tested on Python 3):

 import numpy as np import matplotlib.pyplot as plt def main(): a = -1 b = 1 y, x = np.ogrid[-5:5:100j, -5:5:100j] plt.contour(x.ravel(), y.ravel(), pow(y, 2) - pow(x, 3) - x * a - b, [0]) plt.grid() plt.show() if __name__ == '__main__': main() 

I have this plot: enter image description here

That's what you need?

+13
source

Source: https://habr.com/ru/post/957294/


All Articles