Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4da4cf9

Browse filesBrowse files
authored
Merge pull request #18746 from anntzer/autofigure
Make figure parameter optional when constructing canvases.
2 parents a77d68b + b316d4b commit 4da4cf9
Copy full SHA for 4da4cf9

File tree

Expand file treeCollapse file tree

8 files changed

+18
-9
lines changed
Filter options
Expand file treeCollapse file tree

8 files changed

+18
-9
lines changed

‎lib/matplotlib/backend_bases.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backend_bases.py
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1709,10 +1709,13 @@ def supports_blit(cls):
17091709
return (hasattr(cls, "copy_from_bbox")
17101710
and hasattr(cls, "restore_region"))
17111711

1712-
def __init__(self, figure):
1712+
def __init__(self, figure=None):
1713+
from matplotlib.figure import Figure
17131714
self._fix_ipython_backend2gui()
17141715
self._is_idle_drawing = True
17151716
self._is_saving = False
1717+
if figure is None:
1718+
figure = Figure()
17161719
figure.set_canvas(self)
17171720
self.figure = figure
17181721
self.manager = None

‎lib/matplotlib/backends/_backend_tk.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/_backend_tk.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class FigureCanvasTk(FigureCanvasBase):
162162
@_api.delete_parameter(
163163
"3.4", "resize_callback",
164164
alternative="get_tk_widget().bind('<Configure>', ..., True)")
165-
def __init__(self, figure, master=None, resize_callback=None):
165+
def __init__(self, figure=None, master=None, resize_callback=None):
166166
super().__init__(figure)
167167
self._idle = True
168168
self._idle_callback = None

‎lib/matplotlib/backends/backend_gtk3.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_gtk3.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class FigureCanvasGTK3(Gtk.DrawingArea, FigureCanvasBase):
102102
| Gdk.EventMask.POINTER_MOTION_HINT_MASK
103103
| Gdk.EventMask.SCROLL_MASK)
104104

105-
def __init__(self, figure):
105+
def __init__(self, figure=None):
106106
FigureCanvasBase.__init__(self, figure)
107107
GObject.GObject.__init__(self)
108108

‎lib/matplotlib/backends/backend_qt5.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_qt5.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,13 @@ class FigureCanvasQT(QtWidgets.QWidget, FigureCanvasBase):
206206
}
207207

208208
@_allow_super_init
209-
def __init__(self, figure):
209+
def __init__(self, figure=None):
210210
_create_qApp()
211211
super().__init__(figure=figure)
212212

213213
# We don't want to scale up the figure DPI more than once.
214214
# Note, we don't handle a signal for changing DPI yet.
215-
figure._original_dpi = figure.dpi
215+
self.figure._original_dpi = self.figure.dpi
216216
self._update_figure_dpi()
217217
# In cases with mixed resolution displays, we need to be careful if the
218218
# dpi_ratio changes - in this case we need to resize the canvas

‎lib/matplotlib/backends/backend_qt5agg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_qt5agg.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class FigureCanvasQTAgg(FigureCanvasAgg, FigureCanvasQT):
1818

19-
def __init__(self, figure):
19+
def __init__(self, figure=None):
2020
# Must pass 'figure' as kwarg to Qt base class.
2121
super().__init__(figure=figure)
2222

‎lib/matplotlib/backends/backend_qt5cairo.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_qt5cairo.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
class FigureCanvasQTCairo(FigureCanvasQT, FigureCanvasCairo):
9-
def __init__(self, figure):
9+
def __init__(self, figure=None):
1010
super().__init__(figure=figure)
1111
self._renderer = RendererCairo(self.figure.dpi)
1212
self._renderer.set_width_height(-1, -1) # Invalid values.

‎lib/matplotlib/backends/backend_wx.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_wx.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ class _FigureCanvasWxBase(FigureCanvasBase, wx.Panel):
494494
wx.WXK_NUMPAD_DELETE: 'delete',
495495
}
496496

497-
def __init__(self, parent, id, figure):
497+
def __init__(self, parent, id, figure=None):
498498
"""
499499
Initialize a FigureWx instance.
500500
@@ -504,7 +504,7 @@ def __init__(self, parent, id, figure):
504504
"""
505505

506506
FigureCanvasBase.__init__(self, figure)
507-
w, h = map(math.ceil, figure.bbox.size)
507+
w, h = map(math.ceil, self.figure.bbox.size)
508508
# Set preferred window size hint - helps the sizer, if one is connected
509509
wx.Panel.__init__(self, parent, id, size=wx.Size(w, h))
510510
# Create the drawing bitmap

‎lib/matplotlib/tests/test_backend_bases.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_bases.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
NavigationToolbar2, RendererBase)
66
from matplotlib.backend_tools import (ToolZoom, ToolPan, RubberbandBase,
77
ToolViewsPositions, _views_positions)
8+
from matplotlib.figure import Figure
89
import matplotlib.pyplot as plt
910
import matplotlib.transforms as transforms
1011
import matplotlib.path as path
12+
1113
import numpy as np
1214
import pytest
1315

@@ -53,6 +55,10 @@ def check(master_transform, paths, all_transforms,
5355
check(id, paths, tforms_matrices, offsets, facecolors[0:1], edgecolors)
5456

5557

58+
def test_canvas_ctor():
59+
assert isinstance(FigureCanvasBase().figure, Figure)
60+
61+
5662
def test_get_default_filename(tmpdir):
5763
plt.rcParams['savefig.directory'] = str(tmpdir)
5864
fig = plt.figure()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.