Skip to content

Autoscale does not work for ax.arrow() #12712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
CakeUser321 opened this issue Nov 2, 2018 · 3 comments · Fixed by #15392
Closed

Autoscale does not work for ax.arrow() #12712

CakeUser321 opened this issue Nov 2, 2018 · 3 comments · Fixed by #15392
Milestone

Comments

@CakeUser321
Copy link

CakeUser321 commented Nov 2, 2018

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]

plot_issue

Outcome with setting limits manually

plot_right

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.

@jklymak
Copy link
Member

jklymak commented Nov 2, 2018

ax.arrow() adds the arrow as an artist, not a patch, and it doesn't call self.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
Copy link
Contributor

choyiny commented 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 an Arrow is created in the Axes)

To reproduce:

fig, ax = plt.subplots()
    # ax.set_xlim(0, 5)
    # ax.set_ylim(0, 5)
    ax.plot([1, 2], [2, 1], label='foo')
    ax.arrow(3, 3, 3, 3)
    plt.show()

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
Copy link

teto commented Mar 25, 2020

great news. Thanks for solving this !

@QuLogic QuLogic added this to the v3.3.0 milestone Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants