Skip to content

Commit 15cf72f

Browse files
committed
ENH : add stale flag to Figure
1 parent 429031f commit 15cf72f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lib/matplotlib/figure.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ def set_tight_layout(self, tight):
426426
tight = rcParams['figure.autolayout']
427427
self._tight = bool(tight)
428428
self._tight_parameters = tight if isinstance(tight, dict) else {}
429+
self.stale = True
429430

430431
def autofmt_xdate(self, bottom=0.2, rotation=30, ha='right'):
431432
"""
@@ -465,6 +466,7 @@ def autofmt_xdate(self, bottom=0.2, rotation=30, ha='right'):
465466

466467
if allsubplots:
467468
self.subplots_adjust(bottom=bottom)
469+
self.stale = True
468470

469471
def get_children(self):
470472
'get a list of artists contained in the figure'
@@ -541,6 +543,7 @@ def suptitle(self, t, **kwargs):
541543
sup.remove()
542544
else:
543545
self._suptitle = sup
546+
self.stale = True
544547
return self._suptitle
545548

546549
def set_canvas(self, canvas):
@@ -550,6 +553,7 @@ def set_canvas(self, canvas):
550553
ACCEPTS: a FigureCanvas instance
551554
"""
552555
self.canvas = canvas
556+
self.stale = True
553557

554558
def hold(self, b=None):
555559
"""
@@ -652,6 +656,7 @@ def figimage(self, X,
652656
im.set_clim(vmin, vmax)
653657
self.images.append(im)
654658
im._remove_method = lambda h: self.images.remove(h)
659+
self.stale = True
655660
return im
656661

657662
def set_size_inches(self, *args, **kwargs):
@@ -693,6 +698,7 @@ def set_size_inches(self, *args, **kwargs):
693698
manager = getattr(self.canvas, 'manager', None)
694699
if manager is not None:
695700
manager.resize(int(canvasw), int(canvash))
701+
self.stale = True
696702

697703
def get_size_inches(self):
698704
"""
@@ -758,6 +764,7 @@ def set_dpi(self, val):
758764
ACCEPTS: float
759765
"""
760766
self.dpi = val
767+
self.stale = True
761768

762769
def set_figwidth(self, val):
763770
"""
@@ -766,6 +773,7 @@ def set_figwidth(self, val):
766773
ACCEPTS: float
767774
"""
768775
self.bbox_inches.x1 = val
776+
self.stale = True
769777

770778
def set_figheight(self, val):
771779
"""
@@ -774,6 +782,7 @@ def set_figheight(self, val):
774782
ACCEPTS: float
775783
"""
776784
self.bbox_inches.y1 = val
785+
self.stale = True
777786

778787
def set_frameon(self, b):
779788
"""
@@ -782,12 +791,14 @@ def set_frameon(self, b):
782791
ACCEPTS: boolean
783792
"""
784793
self.frameon = b
794+
self.stale = True
785795

786796
def delaxes(self, a):
787797
'remove a from the figure and update the current axes'
788798
self._axstack.remove(a)
789799
for func in self._axobservers:
790800
func(self)
801+
self.stale = True
791802

792803
def _make_key(self, *args, **kwargs):
793804
'make a hashable key out of args and kwargs'
@@ -900,6 +911,7 @@ def add_axes(self, *args, **kwargs):
900911

901912
self._axstack.add(key, a)
902913
self.sca(a)
914+
self.stale = True
903915
return a
904916

905917
@docstring.dedent_interpd
@@ -987,6 +999,7 @@ def add_subplot(self, *args, **kwargs):
987999

9881000
self._axstack.add(key, a)
9891001
self.sca(a)
1002+
self.stale = True
9901003
return a
9911004

9921005
def clf(self, keep_observers=False):
@@ -1016,6 +1029,7 @@ def clf(self, keep_observers=False):
10161029
if not keep_observers:
10171030
self._axobservers = []
10181031
self._suptitle = None
1032+
self.stale = True
10191033

10201034
def clear(self):
10211035
"""
@@ -1227,6 +1241,7 @@ def legend(self, handles, labels, *args, **kwargs):
12271241
l = Legend(self, handles, labels, *args, **kwargs)
12281242
self.legends.append(l)
12291243
l._remove_method = lambda h: self.legends.remove(h)
1244+
self.stale = True
12301245
return l
12311246

12321247
@docstring.dedent_interpd
@@ -1254,6 +1269,7 @@ def text(self, x, y, s, *args, **kwargs):
12541269
self._set_artist_props(t)
12551270
self.texts.append(t)
12561271
t._remove_method = lambda h: self.texts.remove(h)
1272+
self.stale = True
12571273
return t
12581274

12591275
def _set_artist_props(self, a):
@@ -1399,6 +1415,7 @@ def make_active(event):
13991415
self.number = num
14001416

14011417
plt.draw_if_interactive()
1418+
self.stale = True
14021419

14031420
def add_axobserver(self, func):
14041421
'whenever the axes state change, ``func(self)`` will be called'
@@ -1541,6 +1558,7 @@ def colorbar(self, mappable, cax=None, ax=None, use_gridspec=True, **kw):
15411558
cb = cbar.colorbar_factory(cax, mappable, **kw)
15421559

15431560
self.sca(current_ax)
1561+
self.stale = True
15441562
return cb
15451563

15461564
def subplots_adjust(self, *args, **kwargs):
@@ -1569,6 +1587,7 @@ def subplots_adjust(self, *args, **kwargs):
15691587
else:
15701588
ax.update_params()
15711589
ax.set_position(ax.figbox)
1590+
self.stale = True
15721591

15731592
def ginput(self, n=1, timeout=30, show_clicks=True, mouse_add=1,
15741593
mouse_pop=3, mouse_stop=2):

0 commit comments

Comments
 (0)