Skip to content

Commit e57dd7b

Browse files
committed
Improve scatter() 's' scaling, add 'area_size' opt
1 parent 2bc9a03 commit e57dd7b

1 file changed

Lines changed: 23 additions & 27 deletions

File tree

proplot/axes/plot.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,16 @@
646646
The minimum and maximum marker size area in units ``points ** 2``. Ignored
647647
if `absolute_size` is ``True``. Default value for `smin` is ``1`` and for
648648
`smax` is the square of :rc:`lines.markersize`.
649+
area_size : bool, default: True
650+
Whether the marker sizes `s` are scaled by area or by radius. The default
651+
``True`` is consistent with matplotlib. When `absolute_size` is ``True``,
652+
the `s` units are ``points ** 2`` if `area_size` is ``True`` and ``points``
653+
if `area_size` is ``False``.
649654
absolute_size : bool, default: True or False
650-
Whether `s` should be taken to represent "absolute" marker size areas in units
651-
``points ** 2`` or "relative" marker size areas scaled by `smin` and `smax`.
652-
Default is ``True`` if `s` is scalar and ``False`` if `s` is array-like.
655+
Whether `s` should be taken to represent "absolute" marker sizes in units
656+
``points`` or ``points ** 2`` or "relative" marker sizes scaled by `smin`
657+
and `smax`. Default is ``True`` if `s` is scalar and ``False`` if `s` is
658+
array-like or `smin` or `smax` were passed.
653659
%(plot.vmin_vmax)s
654660
%(plot.args_1d_shared)s
655661
@@ -1658,10 +1664,10 @@ def _fix_patch_edges(obj, edgefix=None, **kwargs):
16581664
with colormaps that are transparent. If keyword args passed by user
16591665
include explicit edge properties then we skip this step.
16601666
"""
1667+
# NOTE: Use default edge width used for pcolor grid box edges. This is thick
1668+
# enough to hide lines but thin enough to not add 'nubs' to corners of boxes.
16611669
# See: https://github.com/jklymak/contourfIssues
16621670
# See: https://stackoverflow.com/q/15003353/4970632
1663-
# NOTE: Use default edge width used for pcolor grid box edges. This is thick
1664-
# enough to hide lines but thin enough to not add 'dots' to corners of boxes.
16651671
edgefix = _not_none(edgefix, rc.edgefix, True)
16661672
linewidth = EDGEWIDTH if edgefix is True else 0 if edgefix is False else edgefix
16671673
if not linewidth:
@@ -3152,32 +3158,22 @@ def hlines(self, *args, **kwargs):
31523158
return self._apply_lines(*args, **kwargs)
31533159

31543160
def _parse_markersize(
3155-
self, s, *, smin=None, smax=None, absolute_size=None, **kwargs
3161+
self, s, *, smin=None, smax=None, area_size=True, absolute_size=None, **kwargs
31563162
):
31573163
"""
31583164
Scale the marker sizes with optional keyword args.
31593165
"""
3160-
default_size = True
3161-
if np.iterable(s):
3162-
s = np.asarray(s)
3163-
if not inputs._is_categorical(s):
3164-
default_size = False
3165-
else:
3166-
s = s.copy()
3167-
s.flat[:] = utils.units(s.flat, 'pt')
3168-
s = s.astype(np.float64) ** 2
3169-
if absolute_size is None:
3170-
if _inside_seaborn_call():
3171-
absolute_size = True
3172-
else:
3173-
absolute_size = default_size
3174-
if not absolute_size or smin is not None or smax is not None:
3175-
smin = _not_none(smin, 1)
3176-
smax = _not_none(smax, rc['lines.markersize'] ** 2)
3177-
smin_true, smax_true = inputs._safe_range(s)
3178-
smin_true = _not_none(smin_true, smin) # fallback behavior
3179-
smax_true = _not_none(smax_true, smax)
3180-
s = smin + (smax - smin) * (s - smin_true) / (smax_true - smin_true)
3166+
if s is not None:
3167+
s = inputs._to_numpy_array(s)
3168+
if absolute_size is None:
3169+
absolute_size = s.size == 1 or _inside_seaborn_call()
3170+
if not absolute_size or smin is not None or smax is not None:
3171+
smin = _not_none(smin, 1)
3172+
smax = _not_none(smax, rc['lines.markersize'] ** (1, 2)[area_size])
3173+
dmin, dmax = inputs._safe_range(s) # data value range
3174+
if dmin is not None and dmax is not None and dmin != dmax:
3175+
s = smin + (smax - smin) * (s - dmin) / (dmax - dmin)
3176+
s = s ** (2, 1)[area_size]
31813177
return s, kwargs
31823178

31833179
def _apply_scatter(self, xs, ys, ss, cc, *, vert=True, **kwargs):

0 commit comments

Comments
 (0)