0

I plot arrows:

plt.quiver([0, 0, 0], [0, 0, 0], [1, -2, 4], [1, 2, -7], angles='xy', scale_units='xy', scale=1)
plt.xlim(-10, 10)
plt.ylim(-10, 10)
plt.show()

But it gives me axes with a different aspect ratio: enter image description here

I added plt.axis('equal') after the first line and I got: enter image description here

But it violated xlim and ylim conditions.

How to make proper scaling with correct limits?

Community
  • 1
  • 1
Kenenbek Arzymatov
  • 8,439
  • 19
  • 58
  • 109

1 Answers1

1

If you are looking for square plot then set figsize of the plot

plt.figure(figsize=(5,5))
plt.quiver([0, 0, 0], [0, 0, 0], [1, -2, 4], [1, 2, -7], angles='xy', scale_units='xy', scale=1)
plt.xlim(-10, 10)
plt.ylim(-10, 10)
plt.show()

enter image description here

Edit

As suggested by @importanceofbeingernest, setting figsize to square is not guaranteed to result in a square plot. The correct approach is to set the aspect ratio.

plt.quiver([0, 0, 0], [0, 0, 0], [1, -2, 4], [1, 2, -7], angles='xy', scale_units='xy', scale=1)
plt.xlim(-10, 10)
plt.ylim(-10, 10)
plt.gca().set_aspect('equal', adjustable='box')
plt.show()

Docs: https://matplotlib.org/api/axes_api.html#aspect-ratio

mujjiga
  • 16,186
  • 2
  • 33
  • 51
  • A square figure does not necessarily give a square plot. In fact, if you take your image and analyse it in a graphics program you'll see that the axes is not square. – ImportanceOfBeingErnest Mar 25 '19 at 22:00
  • @ImportanceOfBeingErnest, you are correct, I have checked the docs. Updated with the solution that sets the aspect ratio. – mujjiga Mar 25 '19 at 22:08