Closed
Description
Bug report
As already stated in this stack overflow thread, when drawing arrows with the arrow()-method, the scale of the plot is not adjusted as expected. A workaround is to set the limits of the plot manually or to plot additional, invisible points near the arrows.
Code for Reproducing the bug
import matplotlib.pyplot as plt
import matplotlib
import sys
print(matplotlib.__version__)
print(sys.version)
fig, ax = plt.subplots()
#ax.set_xlim(0, 5)
#ax.set_ylim(0, 5)
ax.arrow(1, 1, 1, 1)
plt.show()
Output:
3.0.1
3.7.0 (default, Oct 9 2018, 10:31:47)
[GCC 7.3.0]
Outcome with setting limits manually
Matplotlib version
- Operating system: Xubuntu 18.04
- Matplotlib version: 3.0.1
- Matplotlib backend (
print(matplotlib.get_backend())
): Qt5Agg - Python version: 3.7.0
- Jupyter version (if applicable):
- Other libraries:
I installed matplotlib by using anaconda.
I didn't specify a channel, so I guess it was the main channel.
Metadata
Metadata
Assignees
Labels
No labels
Activity
jklymak commentedon Nov 2, 2018
ax.arrow()
adds the arrow as an artist, not a patch, and it doesn't callself.autoscale_view()
. I'm not sure why it doesn't or if there is a reason for that. It would be easy to add, but may have un-intended consequneces...choyiny commentedon Mar 5, 2019
After doing some investigating into the bug, I realized that if the view is set by
plt.plot()
, and then an arrow is drawn, the arrow won't be in the view. (Thus why self.autoscale_view() should be called after anArrow
is created in the Axes)To reproduce:
Note how only the graph will only show the line drawn by
ax.plot()
Adding the arrow as a patch and calling
self.autoscale_view()
does fix the problem with the above problem, but will do some further investigation before creating a PR for this.Edit: Seems like #13593 is relevant here, we should probably not call
autoscale_view()
here.teto commentedon Mar 25, 2020
great news. Thanks for solving this !