Trying to draw a simple arrow in Matplotlib using the following:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.arrow(1, 1, 1, 1)
plt.show()
which results in an empty plot.
If the arrow specifications are changed to ax.arrow(0, 0, 1, 1)
then I do see an arrow in the final plot. So I suspected that it is probably an issue with the scaling of the axes, so I modified the code based on recommendations in Matplotlib autoscale to the following:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.arrow(1, 1, 1, 1)
ax.relim()
ax.autoscale_view()
plt.show()
which also does not work.
I found that manually setting the limits as in the following works
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.arrow(1, 1, 1, 1)
ax.set_xlim(0, 5)
ax.set_ylim(0, 5)
plt.show()
Strange also was my discovery that ax.set_xlim()
alone or ax.set_ylim()
alone do not work I have to set both the limits for the arrow to become visible.
Questions:
- Does
ax.arrow
require special handling? - Am I missing some commands apart from
ax.relim()
andax.autoscale_view()
? - Why do I have to set both
xlim
andylim
?
Versions:
- Python: 3.5.1
- Matplotlib: 1.5.1
- Linux: 64 bit Archlinux