15
15
"""
16
16
17
17
import math
18
- import weakref
19
18
20
19
import numpy as np
21
20
from numpy import ma
@@ -273,21 +272,6 @@ def __init__(self, Q, X, Y, U, label,
273
272
self .color = color
274
273
self .label = label
275
274
self ._labelsep_inches = labelsep
276
- self .labelsep = (self ._labelsep_inches * Q .axes .figure .dpi )
277
-
278
- # try to prevent closure over the real self
279
- weak_self = weakref .ref (self )
280
-
281
- def on_dpi_change (fig ):
282
- self_weakref = weak_self ()
283
- if self_weakref is not None :
284
- self_weakref .labelsep = self_weakref ._labelsep_inches * fig .dpi
285
- # simple brute force update works because _init is called at
286
- # the start of draw.
287
- self_weakref ._initialized = False
288
-
289
- self ._cid = Q .axes .figure .callbacks .connect (
290
- 'dpi_changed' , on_dpi_change )
291
275
292
276
self .labelpos = labelpos
293
277
self .labelcolor = labelcolor
@@ -303,18 +287,16 @@ def on_dpi_change(fig):
303
287
304
288
if self .labelcolor is not None :
305
289
self .text .set_color (self .labelcolor )
306
- self ._initialized = False
290
+ self ._dpi_at_last_init = None
307
291
self .zorder = Q .zorder + 0.1
308
292
309
- def remove (self ):
310
- # docstring inherited
311
- self .Q .axes .figure .callbacks .disconnect (self ._cid )
312
- self ._cid = None
313
- super ().remove () # pass the remove call up the stack
293
+ @property
294
+ def labelsep (self ):
295
+ return self ._labelsep_inches * self .Q .axes .figure .dpi
314
296
315
297
def _init (self ):
316
- if True : # not self._initialized:
317
- if not self .Q ._initialized :
298
+ if True : # self._dpi_at_last_init != self.axes.figure.dpi
299
+ if self . Q . _dpi_at_last_init != self .Q .axes . figure . dpi :
318
300
self .Q ._init ()
319
301
self ._set_transform ()
320
302
with cbook ._setattr_cm (self .Q , pivot = self .pivot [self .labelpos ],
@@ -337,7 +319,7 @@ def _init(self):
337
319
self .vector .set_color (self .color )
338
320
self .vector .set_transform (self .Q .get_transform ())
339
321
self .vector .set_figure (self .get_figure ())
340
- self ._initialized = True
322
+ self ._dpi_at_last_init = self . Q . axes . figure . dpi
341
323
342
324
def _text_x (self , x ):
343
325
if self .labelpos == 'E' :
@@ -508,26 +490,7 @@ def __init__(self, ax, *args,
508
490
closed = False , ** kw )
509
491
self .polykw = kw
510
492
self .set_UVC (U , V , C )
511
- self ._initialized = False
512
-
513
- weak_self = weakref .ref (self ) # Prevent closure over the real self.
514
-
515
- def on_dpi_change (fig ):
516
- self_weakref = weak_self ()
517
- if self_weakref is not None :
518
- # vertices depend on width, span which in turn depend on dpi
519
- self_weakref ._new_UV = True
520
- # simple brute force update works because _init is called at
521
- # the start of draw.
522
- self_weakref ._initialized = False
523
-
524
- self ._cid = ax .figure .callbacks .connect ('dpi_changed' , on_dpi_change )
525
-
526
- def remove (self ):
527
- # docstring inherited
528
- self .axes .figure .callbacks .disconnect (self ._cid )
529
- self ._cid = None
530
- super ().remove () # pass the remove call up the stack
493
+ self ._dpi_at_last_init = None
531
494
532
495
def _init (self ):
533
496
"""
@@ -536,18 +499,19 @@ def _init(self):
536
499
"""
537
500
# It seems that there are not enough event notifications
538
501
# available to have this work on an as-needed basis at present.
539
- if True : # not self._initialized:
502
+ if True : # self._dpi_at_last_init != self.axes.figure.dpi
540
503
trans = self ._set_transform ()
541
504
self .span = trans .inverted ().transform_bbox (self .axes .bbox ).width
542
505
if self .width is None :
543
506
sn = np .clip (math .sqrt (self .N ), 8 , 25 )
544
507
self .width = 0.06 * self .span / sn
545
508
546
509
# _make_verts sets self.scale if not already specified
547
- if not self ._initialized and self .scale is None :
510
+ if (self ._dpi_at_last_init != self .axes .figure .dpi
511
+ and self .scale is None ):
548
512
self ._make_verts (self .U , self .V , self .angles )
549
513
550
- self ._initialized = True
514
+ self ._dpi_at_last_init = self . axes . figure . dpi
551
515
552
516
def get_datalim (self , transData ):
553
517
trans = self .get_transform ()
@@ -563,7 +527,6 @@ def draw(self, renderer):
563
527
self ._init ()
564
528
verts = self ._make_verts (self .U , self .V , self .angles )
565
529
self .set_verts (verts , closed = False )
566
- self ._new_UV = False
567
530
super ().draw (renderer )
568
531
self .stale = False
569
532
@@ -592,7 +555,6 @@ def set_UVC(self, U, V, C=None):
592
555
self .Umask = mask
593
556
if C is not None :
594
557
self .set_array (C )
595
- self ._new_UV = True
596
558
self .stale = True
597
559
598
560
def _dots_per_unit (self , units ):
0 commit comments