Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Error in Axes.redraw_in_frame in use of ExitStack: push() takes 2 positional arguments but 3 were given #18539

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
radarsat1 opened this issue Sep 22, 2020 · 2 comments · Fixed by #18540
Milestone

Comments

@radarsat1
Copy link
Contributor

Bug report

Code that was working in 3.2.1 uses redraw_in_frame, now broken in 3.3.0 and 3.3.2, even though this API has not changed.

Bug summary

Use of Axes.redraw_in_frame leads to an error calling function ExitStack.push().

Code for reproduction

Can be reproduced by running this small program,

import matplotlib.pyplot as plt
fig, ax = plt.subplots(1,1)
ax.plot([1,2,3])
fig.canvas.draw()
ax.redraw_in_frame()

Actual outcome

results in,

$ python3 redraw_test.py 
Traceback (most recent call last):
  File "redraw_test.py", line 7, in <module>
    ax.redraw_in_frame()
  File "/home/stephen.sinclair/.local/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2777, in redraw_in_frame
    stack.push(artist.set_visible, artist.get_visible())
TypeError: push() takes 2 positional arguments but 3 were given

Tested only in Python 3.6 and Python 3.7, but according to docs, the API for contextlib.ExitStack.push has not changed with Python 3.8, so error should be the same.

Expected outcome

Function redraw_in_frame gives no error.

Matplotlib version

Code worked with matplotlib 3.2.1, but broken in 3.3.2.

  • Operating system: Ubuntu 18.04
  • Matplotlib version: 3.3.2
  • Matplotlib backend: TkAgg, Agg.
  • Python version: 3.6, 3.7.
  • Jupyter version (if applicable): n/a
  • Other libraries: n/a

Installed via pip3.

@anntzer
Copy link
Contributor

anntzer commented Sep 22, 2020

woops, that should have been

diff --git i/lib/matplotlib/axes/_base.py w/lib/matplotlib/axes/_base.py
index 40a4af463..4832a2900 100644
--- i/lib/matplotlib/axes/_base.py
+++ w/lib/matplotlib/axes/_base.py
@@ -2828,7 +2828,7 @@ class _AxesBase(martist.Artist):
         with ExitStack() as stack:
             for artist in [*self._get_axis_list(),
                            self.title, self._left_title, self._right_title]:
-                stack.push(artist.set_visible, artist.get_visible())
+                stack.callback(artist.set_visible, artist.get_visible())
                 artist.set_visible(False)
             self.draw(self.figure._cachedRenderer)

@radarsat1
Copy link
Contributor Author

Yes, that fixes it for me, thanks!

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.

3 participants