How can I keep the grid spacing consistent in pyplot

If I use this code

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-1.0, 1.0, 100)
y = np.linspace(-1.0, 1.0, 100)
X, Y = np.meshgrid(x,y)
F = X**2 + Y**2 - 0.6

which I found here, it works, but the spacing on the graph is distorted based on the window size. Is there a way around this?

1 answer

  • answered 2018-07-11 02:41 sacul

    You're looking to adjust the aspect ratio, which you can do using plt.gca().set_aspect('equal'):


    enter image description here