matplotlib.pyplot, preserve aspect ratio of the plot

Posted by Headcrab on Stack Overflow See other posts from Stack Overflow or by Headcrab
Published on 2010-05-29T11:48:15Z Indexed on 2010/05/29 11:52 UTC
Read the original article Hit count: 255

Filed under:
|
|

Assuming we have a polygon coordinates as polygon = [(x1, y1), (x2, y2), ...], the following code displays the polygon:

import matplotlib.pyplot as plt
plt.fill(*zip(*polygon))
plt.show()

By default it is trying to adjust the aspect ratio so that the polygon (or whatever other diagram) fits inside the window, and automatically changing it so that it fits even after resizing. Which is great in many cases, except when you are trying to estimate visually if the image is distorted. How to fix the aspect ratio to be strictly 1:1?

(Not sure if "aspect ratio" is the right term here, so in case it is not - I need both X and Y axes to have 1:1 scale, so that (0, 1) on both X and Y takes an exact same amount of screen space. And I need to keep it 1:1 no matter how I resize the window.)

© Stack Overflow or respective owner

Related posts about python

Related posts about matplotlib