Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 326ccd6

Browse files
committed
Merge pull request #4503 from tacaswell/fix_draw_on_show
Fix draw on show
2 parents 4a0af53 + fdadd63 commit 326ccd6

10 files changed

+28
-25
lines changed

lib/matplotlib/_pylab_helpers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def get_num_fig_managers(cls):
114114
"""
115115
Return the number of figures being managed.
116116
"""
117-
return len(cls.figs.values())
117+
return len(cls.figs)
118118

119119
@classmethod
120120
def get_active(cls):
@@ -146,7 +146,6 @@ def draw_all(cls, force=False):
146146
state machine.
147147
"""
148148
for f_mgr in cls.get_all_fig_managers():
149-
# TODO add logic to check if figure is stale
150149
if force or f_mgr.canvas.figure.stale:
151150
f_mgr.canvas.draw_idle()
152151

lib/matplotlib/backends/backend_gtk.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ def destroy(*args):
586586
self.window.connect("delete_event", destroy)
587587
if matplotlib.is_interactive():
588588
self.window.show()
589+
self.canvas.draw_idle()
589590

590591
def notify_axes_change(fig):
591592
'this will be called whenever the current axes is changed'

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ def destroy(*args):
451451
self.window.connect("delete_event", destroy)
452452
if matplotlib.is_interactive():
453453
self.window.show()
454+
self.canvas.draw_idle()
454455

455456
def notify_axes_change(fig):
456457
'this will be called whenever the current axes is changed'

lib/matplotlib/backends/backend_macosx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ def notify_axes_change(fig):
386386

387387
if matplotlib.is_interactive():
388388
self.show()
389+
self.canvas.draw_idle()
389390

390391
def close(self):
391392
Gcf.destroy(self.num)

lib/matplotlib/backends/backend_nbagg.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# that changes made maintain expected behaviour.
55

66
from base64 import b64encode
7-
from contextlib import contextmanager
87
import json
98
import io
109
import os
@@ -18,7 +17,7 @@
1817

1918
from matplotlib import rcParams
2019
from matplotlib.figure import Figure
21-
from matplotlib.backends import backend_agg
20+
from matplotlib import is_interactive
2221
from matplotlib.backends.backend_webagg_core import (FigureManagerWebAgg,
2322
FigureCanvasWebAggCore,
2423
NavigationToolbar2WebAgg)
@@ -29,7 +28,6 @@
2928
class Show(ShowBase):
3029
def __call__(self, block=None):
3130
from matplotlib._pylab_helpers import Gcf
32-
from matplotlib import is_interactive
3331

3432
managers = Gcf.get_all_fig_managers()
3533
if not managers:
@@ -54,7 +52,6 @@ def __call__(self, block=None):
5452

5553

5654
def draw_if_interactive():
57-
from matplotlib import is_interactive
5855
import matplotlib._pylab_helpers as pylab_helpers
5956

6057
if is_interactive():
@@ -227,6 +224,9 @@ def new_figure_manager_given_figure(num, figure):
227224
if rcParams['nbagg.transparent']:
228225
figure.patch.set_alpha(0)
229226
manager = FigureManagerNbAgg(canvas, num)
227+
if is_interactive():
228+
manager.show()
229+
figure.canvas.draw_idle()
230230
return manager
231231

232232

lib/matplotlib/backends/backend_qt5.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ def __init__(self, canvas, num):
500500

501501
if matplotlib.is_interactive():
502502
self.window.show()
503+
self.canvas.draw_idle()
503504

504505
def notify_axes_change(fig):
505506
# This will be called whenever the current axes is changed

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def new_figure_manager_given_figure(num, figure):
112112
figManager = FigureManagerTkAgg(canvas, num, window)
113113
if matplotlib.is_interactive():
114114
figManager.show()
115+
canvas.draw_idle()
115116
return figManager
116117

117118

lib/matplotlib/backends/backend_wx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,7 @@ def new_figure_manager_given_figure(num, figure):
12361236
figmgr = frame.get_figure_manager()
12371237
if matplotlib.is_interactive():
12381238
figmgr.frame.Show()
1239+
figure.canvas.draw_idle()
12391240

12401241
return figmgr
12411242

lib/matplotlib/backends/backend_wxagg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def new_figure_manager_given_figure(num, figure):
124124
figmgr = frame.get_figure_manager()
125125
if matplotlib.is_interactive():
126126
figmgr.frame.Show()
127+
figure.canvas.draw_idle()
127128
return figmgr
128129

129130

lib/matplotlib/pyplot.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ def gcf():
555555
else:
556556
return figure()
557557

558+
558559
def fignum_exists(num):
559560
return _pylab_helpers.Gcf.has_fignum(num) or num in get_figlabels()
560561

@@ -1138,20 +1139,20 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
11381139
sharey = "none"
11391140
share_values = ["all", "row", "col", "none"]
11401141
if sharex not in share_values:
1141-
# This check was added because it is very easy to type subplots(1, 2, 1)
1142-
# when subplot(1, 2, 1) was intended. In most cases, no error will
1143-
# ever occur, but mysterious behavior will result because what was
1144-
# intended to be the subplot index is instead treated as a bool for
1145-
# sharex.
1142+
# This check was added because it is very easy to type
1143+
# `subplots(1, 2, 1)` when `subplot(1, 2, 1)` was intended.
1144+
# In most cases, no error will ever occur, but mysterious behavior will
1145+
# result because what was intended to be the subplot index is instead
1146+
# treated as a bool for sharex.
11461147
if isinstance(sharex, int):
11471148
warnings.warn("sharex argument to subplots() was an integer."
11481149
" Did you intend to use subplot() (without 's')?")
11491150

1150-
raise ValueError("sharex [%s] must be one of %s" % \
1151-
(sharex, share_values))
1151+
raise ValueError("sharex [%s] must be one of %s" %
1152+
(sharex, share_values))
11521153
if sharey not in share_values:
1153-
raise ValueError("sharey [%s] must be one of %s" % \
1154-
(sharey, share_values))
1154+
raise ValueError("sharey [%s] must be one of %s" %
1155+
(sharey, share_values))
11551156
if subplot_kw is None:
11561157
subplot_kw = {}
11571158
if gridspec_kw is None:
@@ -1167,10 +1168,6 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
11671168

11681169
# Create first subplot separately, so we can share it if requested
11691170
ax0 = fig.add_subplot(gs[0, 0], **subplot_kw)
1170-
#if sharex:
1171-
# subplot_kw['sharex'] = ax0
1172-
#if sharey:
1173-
# subplot_kw['sharey'] = ax0
11741171
axarr[0] = ax0
11751172

11761173
r, c = np.mgrid[:nrows, :ncols]
@@ -1203,15 +1200,13 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
12031200

12041201
# turn off redundant tick labeling
12051202
if sharex in ["col", "all"] and nrows > 1:
1206-
#if sharex and nrows>1:
12071203
# turn off all but the bottom row
12081204
for ax in axarr[:-1, :].flat:
12091205
for label in ax.get_xticklabels():
12101206
label.set_visible(False)
12111207
ax.xaxis.offsetText.set_visible(False)
12121208

12131209
if sharey in ["row", "all"] and ncols > 1:
1214-
#if sharey and ncols>1:
12151210
# turn off all but the first column
12161211
for ax in axarr[:, 1:].flat:
12171212
for label in ax.get_yticklabels():
@@ -1222,8 +1217,8 @@ def subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True,
12221217
# Reshape the array to have the final desired dimension (nrow,ncol),
12231218
# though discarding unneeded dimensions that equal 1. If we only have
12241219
# one subplot, just return it instead of a 1-element array.
1225-
if nplots==1:
1226-
ret = fig, axarr[0,0]
1220+
if nplots == 1:
1221+
ret = fig, axarr[0, 0]
12271222
else:
12281223
ret = fig, axarr.squeeze()
12291224
else:
@@ -1257,10 +1252,12 @@ def subplot2grid(shape, loc, rowspan=1, colspan=1, **kwargs):
12571252
bbox = a.bbox
12581253
byebye = []
12591254
for other in fig.axes:
1260-
if other==a: continue
1255+
if other == a:
1256+
continue
12611257
if bbox.fully_overlaps(other.bbox):
12621258
byebye.append(other)
1263-
for ax in byebye: delaxes(ax)
1259+
for ax in byebye:
1260+
delaxes(ax)
12641261

12651262
return a
12661263

0 commit comments

Comments
 (0)