poplitea
poplitea

Reputation: 3727

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 accomplished by manually setting an pixels-per-unit-ratio for both axes. Is this possible? If so, how?

Upvotes: 2

Views: 1663

Answers (1)

Avaris
Avaris

Reputation: 36715

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

Upvotes: 4

Related Questions