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
@@ -299,21 +298,6 @@ def __init__(self, Q, X, Y, U, label,
299
298
self .color = color
300
299
self .label = label
301
300
self ._labelsep_inches = labelsep
302
- self .labelsep = (self ._labelsep_inches * Q .axes .figure .dpi )
303
-
304
- # try to prevent closure over the real self
305
- weak_self = weakref .ref (self )
306
-
307
- def on_dpi_change (fig ):
308
- self_weakref = weak_self ()
309
- if self_weakref is not None :
310
- self_weakref .labelsep = self_weakref ._labelsep_inches * fig .dpi
311
- # simple brute force update works because _init is called at
312
- # the start of draw.
313
- self_weakref ._initialized = False
314
-
315
- self ._cid = Q .axes .figure .callbacks .connect (
316
- 'dpi_changed' , on_dpi_change )
317
301
318
302
self .labelpos = labelpos
319
303
self .labelcolor = labelcolor
@@ -329,18 +313,16 @@ def on_dpi_change(fig):
329
313
330
314
if self .labelcolor is not None :
331
315
self .text .set_color (self .labelcolor )
332
- self ._initialized = False
316
+ self ._dpi_at_last_init = None
333
317
self .zorder = Q .zorder + 0.1
334
318
335
- def remove (self ):
336
- # docstring inherited
337
- self .Q .axes .figure .callbacks .disconnect (self ._cid )
338
- self ._cid = None
339
- super ().remove () # pass the remove call up the stack
319
+ @property
320
+ def labelsep (self ):
321
+ return self ._labelsep_inches * self .Q .axes .figure .dpi
340
322
341
323
def _init (self ):
342
- if True : # not self._initialized:
343
- if not self .Q ._initialized :
324
+ if True : # self._dpi_at_last_init != self.axes.figure.dpi
325
+ if self . Q . _dpi_at_last_init != self .Q .axes . figure . dpi :
344
326
self .Q ._init ()
345
327
self ._set_transform ()
346
328
with cbook ._setattr_cm (self .Q , pivot = self .pivot [self .labelpos ],
@@ -363,7 +345,7 @@ def _init(self):
363
345
self .vector .set_color (self .color )
364
346
self .vector .set_transform (self .Q .get_transform ())
365
347
self .vector .set_figure (self .get_figure ())
366
- self ._initialized = True
348
+ self ._dpi_at_last_init = self . Q . axes . figure . dpi
367
349
368
350
def _text_x (self , x ):
369
351
if self .labelpos == 'E' :
@@ -534,26 +516,7 @@ def __init__(self, ax, *args,
534
516
closed = False , ** kwargs )
535
517
self .polykw = kwargs
536
518
self .set_UVC (U , V , C )
537
- self ._initialized = False
538
-
539
- weak_self = weakref .ref (self ) # Prevent closure over the real self.
540
-
541
- def on_dpi_change (fig ):
542
- self_weakref = weak_self ()
543
- if self_weakref is not None :
544
- # vertices depend on width, span which in turn depend on dpi
545
- self_weakref ._new_UV = True
546
- # simple brute force update works because _init is called at
547
- # the start of draw.
548
- self_weakref ._initialized = False
549
-
550
- self ._cid = ax .figure .callbacks .connect ('dpi_changed' , on_dpi_change )
551
-
552
- def remove (self ):
553
- # docstring inherited
554
- self .axes .figure .callbacks .disconnect (self ._cid )
555
- self ._cid = None
556
- super ().remove () # pass the remove call up the stack
519
+ self ._dpi_at_last_init = None
557
520
558
521
def _init (self ):
559
522
"""
@@ -562,18 +525,19 @@ def _init(self):
562
525
"""
563
526
# It seems that there are not enough event notifications
564
527
# available to have this work on an as-needed basis at present.
565
- if True : # not self._initialized:
528
+ if True : # self._dpi_at_last_init != self.axes.figure.dpi
566
529
trans = self ._set_transform ()
567
530
self .span = trans .inverted ().transform_bbox (self .axes .bbox ).width
568
531
if self .width is None :
569
532
sn = np .clip (math .sqrt (self .N ), 8 , 25 )
570
533
self .width = 0.06 * self .span / sn
571
534
572
535
# _make_verts sets self.scale if not already specified
573
- if not self ._initialized and self .scale is None :
536
+ if (self ._dpi_at_last_init != self .axes .figure .dpi
537
+ and self .scale is None ):
574
538
self ._make_verts (self .U , self .V , self .angles )
575
539
576
- self ._initialized = True
540
+ self ._dpi_at_last_init = self . axes . figure . dpi
577
541
578
542
def get_datalim (self , transData ):
579
543
trans = self .get_transform ()
@@ -589,7 +553,6 @@ def draw(self, renderer):
589
553
self ._init ()
590
554
verts = self ._make_verts (self .U , self .V , self .angles )
591
555
self .set_verts (verts , closed = False )
592
- self ._new_UV = False
593
556
super ().draw (renderer )
594
557
self .stale = False
595
558
@@ -618,7 +581,6 @@ def set_UVC(self, U, V, C=None):
618
581
self .Umask = mask
619
582
if C is not None :
620
583
self .set_array (C )
621
- self ._new_UV = True
622
584
self .stale = True
623
585
624
586
def _dots_per_unit (self , units ):
0 commit comments