diff --git a/lib/matplotlib/_pylab_helpers.py b/lib/matplotlib/_pylab_helpers.py index b851f06981d7..c5ea8cc6bb60 100644 --- a/lib/matplotlib/_pylab_helpers.py +++ b/lib/matplotlib/_pylab_helpers.py @@ -114,7 +114,7 @@ def get_num_fig_managers(cls): """ Return the number of figures being managed. """ - return len(cls.figs.values()) + return len(cls.figs) @classmethod def get_active(cls): @@ -146,7 +146,6 @@ def draw_all(cls, force=False): state machine. """ for f_mgr in cls.get_all_fig_managers(): - # TODO add logic to check if figure is stale if force or f_mgr.canvas.figure.stale: f_mgr.canvas.draw_idle() diff --git a/lib/matplotlib/backends/backend_gtk.py b/lib/matplotlib/backends/backend_gtk.py index 1a6ee313f546..d2007ff7900e 100644 --- a/lib/matplotlib/backends/backend_gtk.py +++ b/lib/matplotlib/backends/backend_gtk.py @@ -586,6 +586,7 @@ def destroy(*args): self.window.connect("delete_event", destroy) if matplotlib.is_interactive(): self.window.show() + self.canvas.draw_idle() def notify_axes_change(fig): 'this will be called whenever the current axes is changed' diff --git a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py index 32d15fb4fbcc..113c34f72e88 100644 --- a/lib/matplotlib/backends/backend_gtk3.py +++ b/lib/matplotlib/backends/backend_gtk3.py @@ -451,6 +451,7 @@ def destroy(*args): self.window.connect("delete_event", destroy) if matplotlib.is_interactive(): self.window.show() + self.canvas.draw_idle() def notify_axes_change(fig): 'this will be called whenever the current axes is changed' diff --git a/lib/matplotlib/backends/backend_macosx.py b/lib/matplotlib/backends/backend_macosx.py index ef4572f0958e..57fc57440f83 100755 --- a/lib/matplotlib/backends/backend_macosx.py +++ b/lib/matplotlib/backends/backend_macosx.py @@ -386,6 +386,7 @@ def notify_axes_change(fig): if matplotlib.is_interactive(): self.show() + self.canvas.draw_idle() def close(self): Gcf.destroy(self.num) diff --git a/lib/matplotlib/backends/backend_nbagg.py b/lib/matplotlib/backends/backend_nbagg.py index eada1c1de553..521efa20a989 100644 --- a/lib/matplotlib/backends/backend_nbagg.py +++ b/lib/matplotlib/backends/backend_nbagg.py @@ -4,7 +4,6 @@ # that changes made maintain expected behaviour. from base64 import b64encode -from contextlib import contextmanager import json import io import os @@ -18,7 +17,7 @@ from matplotlib import rcParams from matplotlib.figure import Figure -from matplotlib.backends import backend_agg +from matplotlib import is_interactive from matplotlib.backends.backend_webagg_core import (FigureManagerWebAgg, FigureCanvasWebAggCore, NavigationToolbar2WebAgg) @@ -29,7 +28,6 @@ class Show(ShowBase): def __call__(self, block=None): from matplotlib._pylab_helpers import Gcf - from matplotlib import is_interactive managers = Gcf.get_all_fig_managers() if not managers: @@ -54,7 +52,6 @@ def __call__(self, block=None): def draw_if_interactive(): - from matplotlib import is_interactive import matplotlib._pylab_helpers as pylab_helpers if is_interactive(): @@ -227,6 +224,9 @@ def new_figure_manager_given_figure(num, figure): if rcParams['nbagg.transparent']: figure.patch.set_alpha(0) manager = FigureManagerNbAgg(canvas, num) + if is_interactive(): + manager.show() + figure.canvas.draw_idle() return manager diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index e3e0624552fc..24dc630bea73 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -500,6 +500,7 @@ def __init__(self, canvas, num): if matplotlib.is_interactive(): self.window.show() + self.canvas.draw_idle() def notify_axes_change(fig): # This will be called whenever the current axes is changed diff --git a/lib/matplotlib/backends/backend_tkagg.py b/lib/matplotlib/backends/backend_tkagg.py index 8ffc8a85318e..66295e7ff16d 100644 --- a/lib/matplotlib/backends/backend_tkagg.py +++ b/lib/matplotlib/backends/backend_tkagg.py @@ -112,6 +112,7 @@ def new_figure_manager_given_figure(num, figure): figManager = FigureManagerTkAgg(canvas, num, window) if matplotlib.is_interactive(): figManager.show() + canvas.draw_idle() return figManager diff --git a/lib/matplotlib/backends/backend_wx.py b/lib/matplotlib/backends/backend_wx.py index 1c2a578edcd3..d4182e76b543 100644 --- a/lib/matplotlib/backends/backend_wx.py +++ b/lib/matplotlib/backends/backend_wx.py @@ -1236,6 +1236,7 @@ def new_figure_manager_given_figure(num, figure): figmgr = frame.get_figure_manager() if matplotlib.is_interactive(): figmgr.frame.Show() + figure.canvas.draw_idle() return figmgr diff --git a/lib/matplotlib/backends/backend_wxagg.py b/lib/matplotlib/backends/backend_wxagg.py index 8acd2b9e4cd5..36d10a8a41e6 100644 --- a/lib/matplotlib/backends/backend_wxagg.py +++ b/lib/matplotlib/backends/backend_wxagg.py @@ -124,6 +124,7 @@ def new_figure_manager_given_figure(num, figure): figmgr = frame.get_figure_manager() if matplotlib.is_interactive(): figmgr.frame.Show() + figure.canvas.draw_idle() return figmgr diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 2de9711df408..0107258febdb 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -555,6 +555,7 @@ def gcf(): else: return figure() + def fignum_exists(num): return _pylab_helpers.Gcf.has_fignum(num) or num in get_figlabels() @@ -1138,20 +1139,20 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, sharey = "none" share_values = ["all", "row", "col", "none"] if sharex not in share_values: - # This check was added because it is very easy to type subplots(1, 2, 1) - # when subplot(1, 2, 1) was intended. In most cases, no error will - # ever occur, but mysterious behavior will result because what was - # intended to be the subplot index is instead treated as a bool for - # sharex. + # This check was added because it is very easy to type + # `subplots(1, 2, 1)` when `subplot(1, 2, 1)` was intended. + # In most cases, no error will ever occur, but mysterious behavior will + # result because what was intended to be the subplot index is instead + # treated as a bool for sharex. if isinstance(sharex, int): warnings.warn("sharex argument to subplots() was an integer." " Did you intend to use subplot() (without 's')?") - raise ValueError("sharex [%s] must be one of %s" % \ - (sharex, share_values)) + raise ValueError("sharex [%s] must be one of %s" % + (sharex, share_values)) if sharey not in share_values: - raise ValueError("sharey [%s] must be one of %s" % \ - (sharey, share_values)) + raise ValueError("sharey [%s] must be one of %s" % + (sharey, share_values)) if subplot_kw is None: subplot_kw = {} if gridspec_kw is None: @@ -1167,10 +1168,6 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, # Create first subplot separately, so we can share it if requested ax0 = fig.add_subplot(gs[0, 0], **subplot_kw) - #if sharex: - # subplot_kw['sharex'] = ax0 - #if sharey: - # subplot_kw['sharey'] = ax0 axarr[0] = ax0 r, c = np.mgrid[:nrows, :ncols] @@ -1203,7 +1200,6 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, # turn off redundant tick labeling if sharex in ["col", "all"] and nrows > 1: - #if sharex and nrows>1: # turn off all but the bottom row for ax in axarr[:-1, :].flat: for label in ax.get_xticklabels(): @@ -1211,7 +1207,6 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, ax.xaxis.offsetText.set_visible(False) if sharey in ["row", "all"] and ncols > 1: - #if sharey and ncols>1: # turn off all but the first column for ax in axarr[:, 1:].flat: for label in ax.get_yticklabels(): @@ -1222,8 +1217,8 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, # Reshape the array to have the final desired dimension (nrow,ncol), # though discarding unneeded dimensions that equal 1. If we only have # one subplot, just return it instead of a 1-element array. - if nplots==1: - ret = fig, axarr[0,0] + if nplots == 1: + ret = fig, axarr[0, 0] else: ret = fig, axarr.squeeze() else: @@ -1257,10 +1252,12 @@ def subplot2grid(shape, loc, rowspan=1, colspan=1, **kwargs): bbox = a.bbox byebye = [] for other in fig.axes: - if other==a: continue + if other == a: + continue if bbox.fully_overlaps(other.bbox): byebye.append(other) - for ax in byebye: delaxes(ax) + for ax in byebye: + delaxes(ax) return a