Matplotlib - matching axes unit length (resolution)
I need to match the resolution of x- and y-axes in matplotlib, so that the linear function y=x
would plot as an exactly 45° line, and so that a mathematically plotted circle (r^2=x^2+y^2
) would appear round.
This because I'm plotting geographical data, and would like a given distance measured along the x-axis to equal the distance measured along the y-axis. I'm rather new to MatPlotLib, and have problems finding the answer in the documentation.
Edit: This could be a开发者_开发技巧ccomplished by manually setting an pixels-per-unit-ratio for both axes. Is this possible? If so, how?
You can do that with axes.set_aspect
. For example:
import matplotlib.pyplot as plt
f = plt.figure()
x = f.gca()
x.set_aspect("equal")
x.plot(range(10),range(10))
plt.show()
精彩评论