Python matplotlib fails to draw the Acnode (isolated point) on the Elliptic Curve y^2+x^3+x^2=0

Viewed 108

I'm using the below code to draw the ECC curve y^2+x^3+x^2 =0

import numpy as np
import matplotlib.pyplot as plt
import math
def main():
    
    fig = plt.figure()
    ax = fig.add_subplot(111)

    y, x = np.ogrid[-2:2:1000j, -2:2:1000j]
    ax.contour(x.ravel(), y.ravel(), pow(y, 2) + pow(x, 3) + pow(x, 2) , [0],colors='red')

    ax.grid()
    plt.show()

if __name__ == '__main__':
    main()

The output is

enter image description here

The expected image, however, is this

enter image description here

As we can see, the isolated point at (0,0) is not drawn. Any suggestions to solve this issue?

1 Answers

As already mentioned in the comment, it seems that a single point is not displayed as a contour. The best solution would be if the application indicates such points in some way by itself. Perhaps the library allows this, but I have not found a way and therefore show two workarounds here:

Option 1:

The isolated point at (0,0) could be marked explicitly:

ax.plot(0, 0, color="red", marker = "o", markersize = 2.5, zorder = 10)

In the case of multiple points, a masked array is a good choice, here.

enter image description here

Option 2:

The plot can be slightly varied around z = 0, e.g. z = 0.0002:

z = pow(y,2) + pow(x, 2) + pow(x, 3)
ax.contour(x.ravel(), y.ravel(), z, [0.0002], colors='red', zorder=10)

This will move the whole plot. Alternatively, the area around the isolated point alone could be shifted (by adding a second contour call with a small x,y grid around the isolated point at (0,0)). This does not change the rest.

enter image description here

Related