8000 Merge pull request #12450 from anntzer/defaultcanvas · matplotlib/matplotlib@8fd45c0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8fd45c0

Browse files
authored
Merge pull request #12450 from anntzer/defaultcanvas
ENH: Attach a FigureCanvasBase by default to Figures.
2 parents 6b1383a + 380c531 commit 8fd45c0

File tree

4 files changed

+17
-27
lines changed

4 files changed

+17
-27
lines changed

lib/matplotlib/artist.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,7 @@ def pickable(self):
449449
--------
450450
set_picker, get_picker, pick
451451
"""
452-
return (self.figure is not None and
453-
self.figure.canvas is not None and
454-
self._picker is not None)
452+
return self.figure is not None and self._picker is not None
455453

456454
def pick(self, mouseevent):
457455
"""

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3245,8 +3245,7 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,
32453245
if other is not self:
32463246
other.set_xlim(self.viewLim.intervalx,
32473247
emit=False, auto=auto)
3248-
if (other.figure != self.figure and
3249-
other.figure.canvas is not None):
3248+
if other.figure != self.figure:
32503249
other.figure.canvas.draw_idle()
32513250
self.stale = True
32523251
return left, right
@@ -3634,8 +3633,7 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
36343633
if other is not self:
36353634
other.set_ylim(self.viewLim.intervaly,
36363635
emit=False, auto=auto)
3637-
if (other.figure != self.figure and
3638-
other.figure.canvas is not None):
3636+
if other.figure != self.figure:
36393637
other.figure.canvas.draw_idle()
36403638
self.stale = True
36413639
return bottom, top

lib/matplotlib/figure.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import matplotlib.artist as martist
2525
from matplotlib.artist import Artist, allow_rasterization
26+
from matplotlib.backend_bases import FigureCanvasBase
2627
import matplotlib.cbook as cbook
2728
import matplotlib.colorbar as cbar
2829
import matplotlib.image as mimage
@@ -364,7 +365,7 @@ def __init__(self,
364365
self._set_artist_props(self.patch)
365366
self.patch.set_antialiased(False)
366367

367-
self.canvas = None
368+
FigureCanvasBase(self) # Set self.canvas.
368369
self._suptitle = None
369370

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

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,7 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False,
652652
if other is not self:
653653
other.set_xlim(self.xy_viewLim.intervalx,
654654
emit=False, auto=auto)
655-
if (other.figure != self.figure and
656-
other.figure.canvas is not None):
655+
if other.figure != self.figure:
657656
other.figure.canvas.draw_idle()
658657
self.stale = True
659658
return left, right
@@ -711,8 +710,7 @@ def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False,
711710
if other is not self:
712711
other.set_ylim(self.xy_viewLim.intervaly,
713712
emit=False, auto=auto)
714-
if (other.figure != self.figure and
715-
other.figure.canvas is not None):
713+
if other.figure != self.figure:
716714
other.figure.canvas.draw_idle()
717715
self.stale = True
718716
return bottom, top
@@ -770,8 +768,7 @@ def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False,
770768
if other is not self:
771769
other.set_zlim(self.zz_viewLim.intervalx,
772770
emit=False, auto=auto)
773-
if (other.figure != self.figure and
774-
other.figure.canvas is not None):
771+
if other.figure != self.figure:
775772
other.figure.canvas.draw_idle()
776773
self.stale = True
777774
return bottom, top
@@ -1070,17 +1067,14 @@ def mouse_init(self, rotate_btn=1, zoom_btn=3):
10701067
10711068
"""
10721069
self.button_pressed = None
1073-
canv = self.figure.canvas
1074-
if canv is not None:
1075-
c1 = canv.mpl_connect('motion_notify_event', self._on_move)
1076-
c2 = canv.mpl_connect('button_press_event', self._button_press)
1077-
c3 = canv.mpl_connect('button_release_event', self._button_release)
1078-
self._cids = [c1, c2, c3]
1079-
else:
1080-
cbook._warn_external("Axes3D.figure.canvas is 'None', mouse "
1081-
"rotation disabled. Set canvas then call "
1082-
"Axes3D.mouse_init().")
1083-
1070+
self._cids = [
1071+
self.figure.canvas.mpl_connect(
1072+
'motion_notify_event', self._on_move),
1073+
self.figure.canvas.mpl_connect(
1074+
'button_press_event', self._button_press),
1075+
self.figure.canvas.mpl_connect(
1076+
'button_release_event', self._button_release),
1077+
]
10841078
# coerce scalars into array-like, then convert into
10851079
# a regular list to avoid comparisons against None
10861080
# which breaks in recent versions of numpy.

0 commit comments

Comments
 (0)
0