How can I set the aspect ratio? Ask Question

How can I set the aspect ratio? Ask Question

I'm trying to make a square plot (using imshow), i.e. aspect ratio of 1:1, but I can't. None of these work:

import matplotlib.pyplot as plt

ax = fig.add_subplot(111,aspect='equal')
ax = fig.add_subplot(111,aspect=1.0)
ax.set_aspect('equal')
plt.axes().set_aspect('equal')

It seems like the calls are just being ignored (a problem I often seem to have with matplotlib).

ベストアンサー1

A simple option using plt.gca() to get current axes and set aspect

plt.gca().set_aspect('equal')

in place of your last line

おすすめ記事