开发者

Matplotlib - matching axes unit length (resolution)

开发者 https://www.devze.com 2023-04-13 02:09 出处:网络
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 ap

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()
0

精彩评论

暂无评论...
验证码 换一张
取 消