8000 Deprecate FigureCanvas.{get,set}_window_title. · matplotlib/matplotlib@21597eb · GitHub
[go: up one dir, main page]

Skip to content

Commit 21597eb

Browse files
committed
Deprecate FigureCanvas.{get,set}_window_title.
This really belongs on the manager, and is a mild footgun on the canvas.
1 parent 8d2c16b commit 21597eb

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

doc/api/api_changes_3.4/deprecations.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ The following globals in :mod:`matplotlib.colorbar` are deprecated:
1616
In order to use a custom boxstyle, directly pass it as the *boxstyle* argument
1717
to `.FancyBboxPatch`. This was previously already possible, and is consistent
1818
with custom arrow styles and connection styles.
19+
20+
``FigureCanvasBase.get_window_title`` and ``FigureCanvasBase.set_window_title``
21+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22+
... are deprecated. Use the corresponding methods on the FigureManager if
23+
using pyplot, or GUI-specific methods if embedding.

examples/specialty_plots/leftventricle_bulleye.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ def bullseye_plot(ax, data, seg_bold=None, cmap=None, norm=None):
2828
norm : Normalize or None, optional
2929
Optional argument to normalize data into the [0.0, 1.0] range
3030
31-
3231
Notes
3332
-----
34-
This function create the 17 segment model for the left ventricle according
33+
This function creates the 17 segment model for the left ventricle according
3534
to the American Heart Association (AHA) [1]_
3635
3736
References
@@ -135,7 +134,7 @@ def bullseye_plot(ax, data, seg_bold=None, cmap=None, norm=None):
135134
# Make a figure and axes with dimensions as desired.
136135
fig, ax = plt.subplots(figsize=(12, 8), nrows=1, ncols=3,
137136
subplot_kw=dict(projection='polar'))
138-
fig.canvas.set_window_title('Left Ventricle Bulls Eyes (AHA)')
137+
fig.canvas.manager.set_window_title('Left Ventricle Bulls Eyes (AHA)')
139138

140139
# Create the axis for the colorbars
141140
axl = fig.add_axes([0.14, 0.15, 0.2, 0.05])

examples/statistics/barchart_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def format_ycursor(y):
6767
def plot_student_results(student, scores, cohort_size):
6868
fig, ax1 = plt.subplots(figsize=(9, 7)) # Create the figure
6969
fig.subplots_adjust(left=0.115, right=0.88)
70-
fig.canvas.set_window_title('Eldorado K-8 Fitness Chart')
70+
fig.canvas.manager.set_window_title('Eldorado K-8 Fitness Chart')
7171

7272
pos = np.arange(len(test_names))
7373

examples/statistics/boxplot_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
]
103103

104104
fig, ax1 = plt.subplots(figsize=(10, 6))
105-
fig.canvas.set_window_title('A Boxplot Example')
105+
fig.canvas.manager.set_window_title('A Boxplot Example')
106106
fig.subplots_adjust(left=0.075, right=0.95, top=0.9, bottom=0.25)
107107

108108
bp = ax1.boxplot(data, notch=0, sym='+', vert=1, whis=1.5)

lib/matplotlib/backend_bases.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,6 +2235,8 @@ def get_default_filetype(cls):
22352235
"""
22362236
return rcParams['savefig.format']
22372237

2238+
@cbook.deprecated(
2239+
"3.4", alternative="manager.get_window_title or GUI-specific methods")
22382240
def get_window_title(self):
22392241
"""
22402242
Return the title text of the window containing the figure, or None
@@ -2243,6 +2245,8 @@ def get_window_title(self):
22432245
if self.manager is not None:
22442246
return self.manager.get_window_title()
22452247

2248+
@cbook.deprecated(
2249+
"3.4", alternative="manager.set_window_title or GUI-specific methods")
22462250
def set_window_title(self, title):
22472251
"""
22482252
Set the title text of the window containing the figure. Note that
@@ -2256,11 +2260,12 @@ def get_default_filename(self):
22562260
Return a string, which includes extension, suitable for use as
22572261
a default filename.
22582262
"""
2259-
default_basename = self.get_window_title() or 'image'
2260-
default_basename = default_basename.replace(' ', '_')
2261-
default_filetype = self.get_default_filetype()
2262-
default_filename = default_basename + '.' + default_filetype
2263-
return default_filename
2263+
basename = (self.manager.get_window_title() if self.manager is not None
2264+
else '')
2265+
basename = (basename or 'image').replace(' ', '_')
2266+
filetype = self.get_default_filetype()
2267+
filename = basename + '.' + filetype
2268+
return filename
22642269

22652270
def switch_backends(self, FigureCanvasClass):
22662271
"""

0 commit comments

Comments
 (0)
0