From 21597eb1809110c5d8fd2d883d342a6bd552cee5 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 22 Jun 2020 21:34:28 +0200 Subject: [PATCH] Deprecate FigureCanvas.{get,set}_window_title. This really belongs on the manager, and is a mild footgun on the canvas. --- doc/api/api_changes_3.4/deprecations.rst | 5 +++++ examples/specialty_plots/leftventricle_bulleye.py | 5 ++--- examples/statistics/barchart_demo.py | 2 +- examples/statistics/boxplot_demo.py | 2 +- lib/matplotlib/backend_bases.py | 15 ++++++++++----- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/doc/api/api_changes_3.4/deprecations.rst b/doc/api/api_changes_3.4/deprecations.rst index cc961932e0f8..a5a40deeb7c4 100644 --- a/doc/api/api_changes_3.4/deprecations.rst +++ b/doc/api/api_changes_3.4/deprecations.rst @@ -16,3 +16,8 @@ The following globals in :mod:`matplotlib.colorbar` are deprecated: In order to use a custom boxstyle, directly pass it as the *boxstyle* argument to `.FancyBboxPatch`. This was previously already possible, and is consistent with custom arrow styles and connection styles. + +``FigureCanvasBase.get_window_title`` and ``FigureCanvasBase.set_window_title`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +... are deprecated. Use the corresponding methods on the FigureManager if +using pyplot, or GUI-specific methods if embedding. diff --git a/examples/specialty_plots/leftventricle_bulleye.py b/examples/specialty_plots/leftventricle_bulleye.py index 1d98f5e8bfa0..4dc9ac231236 100644 --- a/examples/specialty_plots/leftventricle_bulleye.py +++ b/examples/specialty_plots/leftventricle_bulleye.py @@ -28,10 +28,9 @@ def bullseye_plot(ax, data, seg_bold=None, cmap=None, norm=None): norm : Normalize or None, optional Optional argument to normalize data into the [0.0, 1.0] range - Notes ----- - This function create the 17 segment model for the left ventricle according + This function creates the 17 segment model for the left ventricle according to the American Heart Association (AHA) [1]_ References @@ -135,7 +134,7 @@ def bullseye_plot(ax, data, seg_bold=None, cmap=None, norm=None): # Make a figure and axes with dimensions as desired. fig, ax = plt.subplots(figsize=(12, 8), nrows=1, ncols=3, subplot_kw=dict(projection='polar')) -fig.canvas.set_window_title('Left Ventricle Bulls Eyes (AHA)') +fig.canvas.manager.set_window_title('Left Ventricle Bulls Eyes (AHA)') # Create the axis for the colorbars axl = fig.add_axes([0.14, 0.15, 0.2, 0.05]) diff --git a/examples/statistics/barchart_demo.py b/examples/statistics/barchart_demo.py index a8d78b96363c..e9c2b94c0b95 100644 --- a/examples/statistics/barchart_demo.py +++ b/examples/statistics/barchart_demo.py @@ -67,7 +67,7 @@ def format_ycursor(y): def plot_student_results(student, scores, cohort_size): fig, ax1 = plt.subplots(figsize=(9, 7)) # Create the figure fig.subplots_adjust(left=0.115, right=0.88) - fig.canvas.set_window_title('Eldorado K-8 Fitness Chart') + fig.canvas.manager.set_window_title('Eldorado K-8 Fitness Chart') pos = np.arange(len(test_names)) diff --git a/examples/statistics/boxplot_demo.py b/examples/statistics/boxplot_demo.py index dbf272c430dc..84daaef90cb4 100644 --- a/examples/statistics/boxplot_demo.py +++ b/examples/statistics/boxplot_demo.py @@ -102,7 +102,7 @@ ] fig, ax1 = plt.subplots(figsize=(10, 6)) -fig.canvas.set_window_title('A Boxplot Example') +fig.canvas.manager.set_window_title('A Boxplot Example') fig.subplots_adjust(left=0.075, right=0.95, top=0.9, bottom=0.25) bp = ax1.boxplot(data, notch=0, sym='+', vert=1, whis=1.5) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index dcf3e7f02e04..a4ce63879cbf 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2235,6 +2235,8 @@ def get_default_filetype(cls): """ return rcParams['savefig.format'] + @cbook.deprecated( + "3.4", alternative="manager.get_window_title or GUI-specific methods") def get_window_title(self): """ Return the title text of the window containing the figure, or None @@ -2243,6 +2245,8 @@ def get_window_title(self): if self.manager is not None: return self.manager.get_window_title() + @cbook.deprecated( + "3.4", alternative="manager.set_window_title or GUI-specific methods") def set_window_title(self, title): """ Set the title text of the window containing the figure. Note that @@ -2256,11 +2260,12 @@ def get_default_filename(self): Return a string, which includes extension, suitable for use as a default filename. """ - default_basename = self.get_window_title() or 'image' - default_basename = default_basename.replace(' ', '_') - default_filetype = self.get_default_filetype() - default_filename = default_basename + '.' + default_filetype - return default_filename + basename = (self.manager.get_window_title() if self.manager is not None + else '') + basename = (basename or 'image').replace(' ', '_') + filetype = self.get_default_filetype() + filename = basename + '.' + filetype + return filename def switch_backends(self, FigureCanvasClass): """