89
89
use *color* instead. The size of *C* must match the number of arrow
90
90
locations.
91
91
92
- units : {'width', 'height', 'dots', 'inches', 'x', 'y', 'xy'}, default: 'width'
92
+ arrow_units : {'width', 'height', 'dots', 'inches', 'x', 'y', 'xy'}, default:
93
+ 'width'
93
94
The arrow dimensions (except for *length*) are measured in multiples of
94
95
this unit.
95
96
99
100
- 'dots', 'inches': Pixels or inches based on the figure dpi.
100
101
- 'x', 'y', 'xy': *X*, *Y* or :math:`\\ sqrt{X^2 + Y^2}` in data units.
101
102
102
- The arrows scale differently depending on the units. For
103
+ The arrows scale differently depending on the arrow units. For
103
104
'x' or 'y', the arrows get larger as one zooms in; for other
104
- units, the arrow size is independent of the zoom state. For
105
+ arrow units, the arrow size is independent of the zoom state. For
105
106
'width or 'height', the arrow size increases with the width and
106
107
height of the axes, respectively, when the window is resized;
107
108
for 'dots' or 'inches', resizing does not change the arrows.
151
152
``angles='xy', scale_units='xy', scale=1``.
152
153
153
154
width : float, optional
154
- Shaft width in arrow units; default depends on choice of units,
155
+ Shaft width in arrow units; default depends on choice of arrow units,
155
156
above, and number of vectors; a typical starting value is about
156
157
0.005 times the width of the plot.
157
158
@@ -466,11 +467,13 @@ class Quiver(mcollections.PolyCollection):
466
467
467
468
_PIVOT_VALS = ('tail' , 'middle' , 'tip' )
468
469
470
+ @_api .rename_parameter ('3.6' , 'units' , 'arrow_units' )
469
471
@docstring .Substitution (_quiver_doc )
470
472
def __init__ (self , ax , * args ,
471
473
scale = None , headwidth = 3 , headlength = 5 , headaxislength = 4.5 ,
472
- minshaft = 1 , minlength = 1 , units = 'width' , scale_units = None ,
473
- angles = 'uv' , width = None , color = 'k' , pivot = 'tail' , ** kw ):
474
+ minshaft = 1 , minlength = 1 , arrow_units = 'width' ,
475
+ scale_units = None , angles = 'uv' , width = None , color = 'k' ,
476
+ pivot = 'tail' , ** kw ):
474
477
"""
475
478
The constructor takes one required argument, an Axes
476
479
instance, followed by the args and kwargs described
@@ -504,7 +507,7 @@ def __init__(self, ax, *args,
504
507
super ().__init__ ([], offsets = self .XY , transOffset = self .transform ,
505
508
closed = False , ** kw )
506
509
507
- self .units = units
510
+ self .arrow_units = arrow_units
508
511
self .polykw = kw
509
512
self .set_UVC (U , V , C )
510
513
self ._initialized = False
@@ -522,11 +525,36 @@ def on_dpi_change(fig):
522
525
523
526
self ._cid = ax .figure .callbacks .connect ('dpi_changed' , on_dpi_change )
524
527
528
+ @property
529
+ def units (self ):
530
+ _api .warn_deprecated (
531
+ '3.6' ,
532
+ message = '%(name)s is deprecated since %(since)s. Use '
533
+ '%(alternative)s instead.' ,
534
+ name = 'Quiver.units' ,
535
+ alternative = 'Quiver.arrow_units' )
536
+ return self .arrow_units
537
+
538
+ @units .setter
539
+ def units (self , val ):
540
+ # Avoid emitting a warning when `ScalarMappable.__init__` sets this
541
+ # to None
542
+ if val is not None :
543
+ _api .warn_deprecated (
544
+ '3.6' ,
545
+ message = '%(name)s is deprecated since %(since)s. Use '
546
+ '%(alternative)s instead.' ,
547
+ name = 'Quiver.units' ,
548
+ alternative = 'Quiver.arrow_units' )
549
+ self .arrow_units = val
550
+
525
551
def _convert_mappable_units (self , A ):
526
552
"""
527
553
Since Quiver already has a .units attribute for another purpose, it's
528
554
not yet possible to support units on the ScalarMappable part, so
529
555
override convert units to be a no-op.
556
+
557
+ This method can be removed when the .units deprecation expires.
530
558
"""
531
559
return A
532
560
@@ -602,15 +630,15 @@ def set_UVC(self, U, V, C=None):
602
630
self ._new_UV = True
603
631
self .stale = True
604
632
605
- def _dots_per_unit (self , units ):
633
+ def _dots_per_unit (self , arrow_units ):
606
634
"""
607
635
Return a scale factor for converting from units to pixels
608
636
"""
609
- if units in ('x' , 'y' , 'xy' ):
610
- if units == 'x' :
637
+ if arrow_units in ('x' , 'y' , 'xy' ):
638
+ if arrow_units == 'x' :
611
639
dx0 = self .axes .viewLim .width
612
640
dx1 = self .axes .bbox .width
613
- elif units == 'y' :
641
+ elif arrow_units == 'y' :
614
642
dx0 = self .axes .viewLim .height
615
643
dx1 = self .axes .bbox .height
616
644
else : # 'xy' is assumed
@@ -622,24 +650,24 @@ def _dots_per_unit(self, units):
622
650
dx0 = np .hypot (dxx0 , dyy0 )
623
651
dx = dx1 / dx0
624
652
else :
625
- if units == 'width' :
653
+ if arrow_units == 'width' :
626
654
dx = self .axes .bbox .width
627
- elif units == 'height' :
655
+ elif arrow_units == 'height' :
628
656
dx = self .axes .bbox .height
629
- elif units == 'dots' :
657
+ elif arrow_units == 'dots' :
630
658
dx = 1.0
631
- elif units == 'inches' :
659
+ elif arrow_units == 'inches' :
632
660
dx = self .axes .figure .dpi
633
661
else :
634
- raise ValueError (f'Unrecognized units: { units } ' )
662
+ raise ValueError (f'Unrecognized arrow units: { arrow_units } ' )
635
663
return dx
636
664
637
665
def _set_transform (self ):
638
666
"""
639
667
Set the PolyCollection transform to go
640
668
from arrow width units to pixels.
641
669
"""
642
- dx = self ._dots_per_unit (self .units )
670
+ dx = self ._dots_per_unit (self .arrow_units )
643
671
self ._trans_scale = dx # pixels per arrow width unit
644
672
trans = transforms .Affine2D ().scale (dx )
645
673
self .set_transform (trans )
0 commit comments