1

How do I get a figure to have a 1:1 aspect ratio? I currently have the following figure

import matplotlib.pyplot as plt

circle1 = plt.Circle((0.5, 0.5), 0.2, color='r')
fig, ax = plt.subplots()
ax.add_artist(circle1)

But the x-axis is bigger than the y-axis. I tried using the command I found here :

import matplotlib.pyplot as plt

circle1 = plt.Circle((0.5, 0.5), 0.2, color='r')
fig, ax = plt.subplots()
ax.add_artist(circle1)

plt.axes().set_aspect('equal', 'datalim')

but then the circle I drew disappears.

How can I set an equal aspect ratio?

usernumber
  • 1,958
  • 1
  • 21
  • 58

2 Answers2

1

Add the aspect kw to your fig, ax statement:

fig, ax = plt.subplots(subplot_kw={'aspect': 1})
mauve
  • 2,707
  • 1
  • 20
  • 34
1

If you want to change the aspect ratio of your ax at any time rather than when it's created, you can call:

ax.set_aspect("equal")

as documented here.

Guimoute
  • 4,407
  • 3
  • 12
  • 28