Skip to content

Commit b72df2b

Browse files
committed
allow multiple single numbers as size for scatter
1 parent e2272e9 commit b72df2b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

examples/interactive_scatter.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
" return np.sin(x*tau)**2 + np.random.randn(N)*.01\n",
5757
"def f_y2(x, tau):\n",
5858
" return np.cos(x*tau)**2 + np.random.randn(N)*.1\n",
59-
"fig, ax, controls = interactive_scatter(x,[f_y1, f_y2], tau = (1, 2*np.pi, 100), c = ['blue', 'red']) "
59+
"fig, ax, controls = interactive_scatter(x,[f_y1, f_y2], tau = (1, 2*np.pi, 100), c = ['blue', 'red'], s = [5, 20]) "
6060
]
6161
},
6262
{
@@ -272,7 +272,7 @@
272272
"name": "python",
273273
"nbconvert_exporter": "python",
274274
"pygments_lexer": "ipython3",
275-
"version": "3.7.8"
275+
"version": "3.8.5"
276276
}
277277
},
278278
"nbformat": 4,

mpl_interactions/pyplot.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections import defaultdict
22
from collections.abc import Callable, Iterable
33
from functools import partial
4+
from numbers import Number
45

56
import ipywidgets as widgets
67
import matplotlib.widgets as mwidgets
@@ -759,11 +760,16 @@ def _prep_color(col):
759760
else:
760761
return col
761762

763+
def _prep_size(s):
764+
if (isinstance(s, tuple) or isinstance(s, list)) and all([isinstance(es, Number) for es in s]):
765+
return np.asarray(s, dtype=np.object)
766+
return s
767+
762768
X, Y, cols, sizes, edgecolors, alphas, labels = broadcast_many(
763769
(x, "x"),
764770
(y, "y"),
765771
(_prep_color(c), "c"),
766-
(s, "s"),
772+
(_prep_size(s), "s"),
767773
(_prep_color(edgecolors), "edgecolors"),
768774
(alpha, "alpha"),
769775
(label, "labels"),
@@ -818,7 +824,7 @@ def update(change, key, label):
818824
scat.set_facecolor(c)
819825
if ec is not None:
820826
scat.set_edgecolor(ec)
821-
if s is not None:
827+
if s is not None and not isinstance(s, Number):
822828
scat.set_sizes(s)
823829
if a is not None:
824830
scat.set_alpha(a)

0 commit comments

Comments
 (0)