51
51
ROBUST_PERCENTILE = 2.0
52
52
53
53
# copied from seaborn
54
- _MARKERSIZE_RANGE = (18.0 , 72.0 )
55
- _LINEWIDTH_RANGE = (1.5 , 6.0 )
54
+ _MARKERSIZE_RANGE = (18.0 , 36.0 , 72.0 )
55
+ _LINEWIDTH_RANGE = (1.5 , 1.5 , 6.0 )
56
56
57
57
58
58
def import_matplotlib_pyplot ():
@@ -1341,7 +1341,7 @@ def _parse_size(
1341
1341
else :
1342
1342
levels = numbers = np .sort (np .unique (flatdata ))
1343
1343
1344
- min_width , max_width = _MARKERSIZE_RANGE
1344
+ min_width , default_width , max_width = _MARKERSIZE_RANGE
1345
1345
# width_range = min_width, max_width
1346
1346
1347
1347
if norm is None :
@@ -1378,8 +1378,8 @@ class _Normalize(Sequence):
1378
1378
----------
1379
1379
data : DataArray
1380
1380
DataArray to normalize.
1381
- width : Sequence of two numbers, optional
1382
- Normalize the data to theses min and max values.
1381
+ width : Sequence of three numbers, optional
1382
+ Normalize the data to these ( min, default, max) values.
1383
1383
The default is None.
1384
1384
"""
1385
1385
@@ -1388,7 +1388,7 @@ class _Normalize(Sequence):
1388
1388
_data_unique_index : np .ndarray
1389
1389
_data_unique_inverse : np .ndarray
1390
1390
_data_is_numeric : bool
1391
- _width : tuple [float , float ] | None
1391
+ _width : tuple [float , float , float ] | None
1392
1392
1393
1393
__slots__ = (
1394
1394
"_data" ,
@@ -1402,7 +1402,7 @@ class _Normalize(Sequence):
1402
1402
def __init__ (
1403
1403
self ,
1404
1404
data : DataArray | None ,
1405
- width : tuple [float , float ] | None = None ,
1405
+ width : tuple [float , float , float ] | None = None ,
1406
1406
_is_facetgrid : bool = False ,
1407
1407
) -> None :
1408
1408
self ._data = data
@@ -1469,14 +1469,16 @@ def _calc_widths(self, y: np.ndarray | DataArray) -> np.ndarray | DataArray:
1469
1469
if self ._width is None :
1470
1470
return y
1471
1471
1472
- x0 , x1 = self ._width
1472
+ xmin , xdefault , xmax = self ._width
1473
1473
1474
- # If y is constant, then add a small number to avoid division with zero:
1475
1474
diff_maxy_miny = np .max (y ) - np .min (y )
1476
- eps = np .finfo (np .float64 ).eps if diff_maxy_miny == 0 else 0
1477
- k = (y - np .min (y )) / (diff_maxy_miny + eps )
1478
- widths = x0 + k * (x1 - x0 )
1479
-
1475
+ if diff_maxy_miny == 0 :
1476
+ # Use default with if y is constant:
1477
+ widths = xdefault + 0 * y
1478
+ else :
1479
+ # Normalize inbetween xmin and xmax:
1480
+ k = (y - np .min (y )) / diff_maxy_miny
1481
+ widths = xmin + k * (xmax - xmin )
1480
1482
return widths
1481
1483
1482
1484
@overload
@@ -1507,7 +1509,7 @@ def values(self) -> DataArray | None:
1507
1509
array([3, 1, 1, 3, 5])
1508
1510
Dimensions without coordinates: dim_0
1509
1511
1510
- >>> _Normalize(a, width=[ 18, 72] ).values
1512
+ >>> _Normalize(a, width=( 18, 36, 72) ).values
1511
1513
<xarray.DataArray (dim_0: 5)>
1512
1514
array([45., 18., 18., 45., 72.])
1513
1515
Dimensions without coordinates: dim_0
@@ -1518,14 +1520,14 @@ def values(self) -> DataArray | None:
1518
1520
array([0.5, 0. , 0. , 0.5, 2. , 3. ])
1519
1521
Dimensions without coordinates: dim_0
1520
1522
1521
- >>> _Normalize(a, width=[ 18, 72] ).values
1523
+ >>> _Normalize(a, width=( 18, 36, 72) ).values
1522
1524
<xarray.DataArray (dim_0: 6)>
1523
1525
array([27., 18., 18., 27., 54., 72.])
1524
1526
Dimensions without coordinates: dim_0
1525
1527
1526
- >>> _Normalize(a * 0, width=[ 18, 72] ).values
1528
+ >>> _Normalize(a * 0, width=( 18, 36, 72) ).values
1527
1529
<xarray.DataArray (dim_0: 6)>
1528
- array([18 ., 18 ., 18 ., 18 ., 18 ., 18 .])
1530
+ array([36 ., 36 ., 36 ., 36 ., 36 ., 36 .])
1529
1531
Dimensions without coordinates: dim_0
1530
1532
1531
1533
"""
@@ -1552,14 +1554,14 @@ def _values_unique(self) -> np.ndarray | None:
1552
1554
>>> _Normalize(a)._values_unique
1553
1555
array([1, 3, 5])
1554
1556
1555
- >>> _Normalize(a, width=[ 18, 72] )._values_unique
1557
+ >>> _Normalize(a, width=( 18, 36, 72) )._values_unique
1556
1558
array([18., 45., 72.])
1557
1559
1558
1560
>>> a = xr.DataArray([0.5, 0, 0, 0.5, 2, 3])
1559
1561
>>> _Normalize(a)._values_unique
1560
1562
array([0. , 0.5, 2. , 3. ])
1561
1563
1562
- >>> _Normalize(a, width=[ 18, 72] )._values_unique
1564
+ >>> _Normalize(a, width=( 18, 36, 72) )._values_unique
1563
1565
array([18., 27., 54., 72.])
1564
1566
"""
1565
1567
if self .data is None :
@@ -1631,7 +1633,7 @@ def format(self) -> FuncFormatter:
1631
1633
Examples
1632
1634
--------
1633
1635
>>> a = xr.DataArray([0.5, 0, 0, 0.5, 2, 3])
1634
- >>> aa = _Normalize(a, width=[ 0, 1] )
1636
+ >>> aa = _Normalize(a, width=( 0, 0.5, 1) )
1635
1637
>>> aa._lookup
1636
1638
0.000000 0.0
1637
1639
0.166667 0.5
@@ -1657,7 +1659,7 @@ def func(self) -> Callable[[Any, None | Any], Any]:
1657
1659
Examples
1658
1660
--------
1659
1661
>>> a = xr.DataArray([0.5, 0, 0, 0.5, 2, 3])
1660
- >>> aa = _Normalize(a, width=[ 0, 1] )
1662
+ >>> aa = _Normalize(a, width=( 0, 0.5, 1) )
1661
1663
>>> aa._lookup
1662
1664
0.000000 0.0
1663
1665
0.166667 0.5
0 commit comments