Skip to content

Attach a FigureCanvasBase by default to Figures. #12450

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

Merged
merged 1 commit into from
Nov 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,7 @@ def pickable(self):
--------
set_picker, get_picker, pick
"""
return (self.figure is not None and
self.figure.canvas is not None and
self._picker is not None)
return self.figure is not None and self._picker is not None

def pick(self, mouseevent):
"""
Expand Down
6 changes: 2 additions & 4 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3241,8 +3241,7 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,
if other is not self:
other.set_xlim(self.viewLim.intervalx,
emit=False, auto=auto)
if (other.figure != self.figure and
other.figure.canvas is not None):
if other.figure != self.figure:
other.figure.canvas.draw_idle()
self.stale = True
return left, right
Expand Down Expand Up @@ -3630,8 +3629,7 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
if other is not self:
other.set_ylim(self.viewLim.intervaly,
emit=False, auto=auto)
if (other.figure != self.figure and
other.figure.canvas is not None):
if other.figure != self.figure:
other.figure.canvas.draw_idle()
self.stale = True
return bottom, top
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import matplotlib.artist as martist
from matplotlib.artist import Artist, allow_rasterization
from matplotlib.backend_bases import FigureCanvasBase
import matplotlib.cbook as cbook
import matplotlib.colorbar as cbar
import matplotlib.image as mimage
Expand Down Expand Up @@ -364,7 +365,7 @@ def __init__(self,
self._set_artist_props(self.patch)
self.patch.set_antialiased(False)

self.canvas = None
FigureCanvasBase(self) # Set self.canvas.
self._suptitle = None

if subplotpars is None:
Expand Down Expand Up @@ -398,8 +399,7 @@ def __init__(self,
def _repr_html_(self):
# We can't use "isinstance" here, because then we'd end up importing
# webagg unconditiionally.
if (self.canvas is not None and
'WebAgg' in self.canvas.__class__.__name__):
if 'WebAgg' in type(self.canvas).__name__:
from matplotlib.backends import backend_webagg
return backend_webagg.ipython_inline_display(self)

Expand Down
28 changes: 11 additions & 17 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,7 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False,
if other is not self:
other.set_xlim(self.xy_viewLim.intervalx,
emit=False, auto=auto)
if (other.figure != self.figure and
other.figure.canvas is not None):
if other.figure != self.figure:
other.figure.canvas.draw_idle()
self.stale = True
return left, right
Expand Down Expand Up @@ -711,8 +710,7 @@ def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False,
if other is not self:
other.set_ylim(self.xy_viewLim.intervaly,
emit=False, auto=auto)
if (other.figure != self.figure and
other.figure.canvas is not None):
if other.figure != self.figure:
other.figure.canvas.draw_idle()
self.stale = True
return bottom, top
Expand Down Expand Up @@ -770,8 +768,7 @@ def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False,
if other is not self:
other.set_zlim(self.zz_viewLim.intervalx,
emit=False, auto=auto)
if (other.figure != self.figure and
other.figure.canvas is not None):
if other.figure != self.figure:
other.figure.canvas.draw_idle()
self.stale = True
return bottom, top
Expand Down Expand Up @@ -1070,17 +1067,14 @@ def mouse_init(self, rotate_btn=1, zoom_btn=3):

"""
self.button_pressed = None
canv = self.figure.canvas
if canv is not None:
c1 = canv.mpl_connect('motion_notify_event', self._on_move)
c2 = canv.mpl_connect('button_press_event', self._button_press)
c3 = canv.mpl_connect('button_release_event', self._button_release)
self._cids = [c1, c2, c3]
else:
cbook._warn_external("Axes3D.figure.canvas is 'None', mouse "
"rotation disabled. Set canvas then call "
"Axes3D.mouse_init().")

self._cids = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concerned that if we are hitting this code path with the base canvas and then it gets replaced the subscriptions will not work.

On the other hand, you are no worse than you are now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I'll leave it as it is until someone complains :)

self.figure.canvas.mpl_connect(
'motion_notify_event', self._on_move),
self.figure.canvas.mpl_connect(
'button_press_event', self._button_press),
self.figure.canvas.mpl_connect(
'button_release_event', self._button_release),
]
# coerce scalars into array-like, then convert into
# a regular list to avoid comparisons against None
# which breaks in recent versions of numpy.
Expand Down