From 91d1f2bc3d85394a7eee23fdf592006219d7ed97 Mon Sep 17 00:00:00 2001 From: Ian Hunt-Isaak Date: Tue, 1 Jun 2021 23:44:49 -0400 Subject: [PATCH 1/4] handle all scatter kwargs --- mpl_interactions/mpl_kwargs.py | 2 ++ mpl_interactions/pyplot.py | 34 +++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/mpl_interactions/mpl_kwargs.py b/mpl_interactions/mpl_kwargs.py index 8e6b990..5bf3068 100644 --- a/mpl_interactions/mpl_kwargs.py +++ b/mpl_interactions/mpl_kwargs.py @@ -1,4 +1,5 @@ from matplotlib.artist import ArtistInspector +from matplotlib.collections import Collection from matplotlib.image import AxesImage # this is a list of options to Line2D partially taken from @@ -61,6 +62,7 @@ ] imshow_kwargs_list = ArtistInspector(AxesImage).get_setters() +collection_kwargs_list = ArtistInspector(Collection).get_setters() Text_kwargs_list = [ "agg_filter", diff --git a/mpl_interactions/pyplot.py b/mpl_interactions/pyplot.py index 58896fe..dc88865 100644 --- a/mpl_interactions/pyplot.py +++ b/mpl_interactions/pyplot.py @@ -23,7 +23,13 @@ notebook_backend, update_datalim_from_bbox, ) -from .mpl_kwargs import Line2D_kwargs_list, imshow_kwargs_list, Text_kwargs_list, kwarg_popper +from .mpl_kwargs import ( + Line2D_kwargs_list, + imshow_kwargs_list, + Text_kwargs_list, + collection_kwargs_list, + kwarg_popper, +) __all__ = [ "interactive_plot", @@ -404,6 +410,7 @@ def interactive_scatter( vmax=None, alpha=None, edgecolors=None, + facecolors=None, label=None, parametric=False, ax=None, @@ -424,18 +431,19 @@ def interactive_scatter( x, y : function or float or array-like shape (n, ) for array-like. Functions must return the correct shape as well. If y is None then parametric must be True and the function for x must return x, y - c : array-like or list of colors or color, broadcastable - Must be broadcastable to x,y and any other plotting kwargs. - valid input to plt.scatter + c : array-like or list of colors or color or Callable + Valid input to plt.scatter or a function s : float, array-like, function, or index controls object valid input to plt.scatter, or a function alpha : float, None, or function(s), broadcastable Affects all scatter points. This will compound with any alpha introduced by the ``c`` argument - edgecolors : colorlike, broadcastable + edgecolor[s] : callable or valid argument to scatter passed through to scatter. - label : string(s) broadcastable - labels for the functions being plotted. + facecolor[s] : callable or valid argument to scatter + Valid input to plt.scatter, or a function + label : string + Passed through to Matplotlib parametric : boolean If True then the function expects to have only received a value for y and that that function will return an array for both x and y, or will return an array with shape (N, 2) @@ -483,6 +491,12 @@ def interactive_scatter( else: stretch_y = False + # yanked from https://github.com/matplotlib/matplotlib/blob/bcc1ce8461f5b6e874baaaa02ef776d0243a4abe/lib/matplotlib/axes/_axes.py#L4271-L4273 + facecolors = kwargs.pop("facecolor", facecolors) + edgecolors = kwargs.pop("edgecolor", edgecolors) + + kwargs, collection_kwargs = kwarg_popper(kwargs, collection_kwargs_list) + ipympl = notebook_backend() fig, ax = gogogo_figure(ipympl, ax) use_ipywidgets = ipympl or force_ipywidgets @@ -509,6 +523,7 @@ def update(params, indices, cache): c_ = check_callable_xy(c, x_, y_, param_excluder(params), cache) s_ = check_callable_xy(s, x_, y_, param_excluder(params, "s"), cache) ec_ = check_callable_xy(edgecolors, x_, y_, param_excluder(params), cache) + fc_ = check_callable_xy(facecolors, x_, y_, param_excluder(params), cache) a_ = check_callable_alpha(alpha, param_excluder(params, "alpha"), cache) if c_ is not None: try: @@ -524,6 +539,8 @@ def update(params, indices, cache): scatter.set_facecolor(c_) if ec_ is not None: scatter.set_edgecolor(ec_) + if fc_ is not None: + scatter.set_facecolor(c_) if s_ is not None: if isinstance(s_, Number): s_ = np.broadcast_to(s_, (len(x_),)) @@ -565,6 +582,7 @@ def check_callable_alpha(alpha_, params, cache): c_ = check_callable_xy(c, x_, y_, p, {}) s_ = check_callable_xy(s, x_, y_, param_excluder(params, "s"), {}) ec_ = check_callable_xy(edgecolors, x_, y_, p, {}) + fc_ = check_callable_xy(facecolors, x_, y_, p, {}) a_ = check_callable_alpha(alpha, params, {}) scatter = ax.scatter( x_, @@ -576,7 +594,9 @@ def check_callable_alpha(alpha_, params, cache): cmap=cmap, alpha=a_, edgecolors=ec_, + facecolors=fc_, label=label, + **collection_kwargs, ) # this is necessary to make calls to plt.colorbar behave as expected sca(ax) From fe4c6fcc57943bb760d461e46e3c98acb9dd1e37 Mon Sep 17 00:00:00 2001 From: Ian Hunt-Isaak Date: Wed, 2 Jun 2021 00:39:48 -0400 Subject: [PATCH 2/4] make pass marker through and make it callable --- mpl_interactions/pyplot.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/mpl_interactions/pyplot.py b/mpl_interactions/pyplot.py index dc88865..df067bc 100644 --- a/mpl_interactions/pyplot.py +++ b/mpl_interactions/pyplot.py @@ -7,6 +7,7 @@ from matplotlib.colors import to_rgba_array from matplotlib.patches import Rectangle from matplotlib.pyplot import sca +import matplotlib.markers as mmarkers from .controller import Controls, gogogo_controls, prep_scalars @@ -409,6 +410,7 @@ def interactive_scatter( vmin=None, vmax=None, alpha=None, + marker=None, edgecolors=None, facecolors=None, label=None, @@ -438,6 +440,8 @@ def interactive_scatter( alpha : float, None, or function(s), broadcastable Affects all scatter points. This will compound with any alpha introduced by the ``c`` argument + marker : MarkerStyle, or Callable, optional + The marker style or a function returning marker styles. edgecolor[s] : callable or valid argument to scatter passed through to scatter. facecolor[s] : callable or valid argument to scatter @@ -503,9 +507,10 @@ def interactive_scatter( slider_formats = create_slider_format_dict(slider_formats) extra_ctrls = [] - funcs, extra_ctrls, param_excluder = prep_scalars(kwargs, s=s, alpha=alpha) + funcs, extra_ctrls, param_excluder = prep_scalars(kwargs, s=s, alpha=alpha, marker=marker) s = funcs["s"] alpha = funcs["alpha"] + marker = funcs["marker"] controls, params = gogogo_controls( kwargs, controls, display_controls, slider_formats, play_buttons, extra_ctrls @@ -525,6 +530,14 @@ def update(params, indices, cache): ec_ = check_callable_xy(edgecolors, x_, y_, param_excluder(params), cache) fc_ = check_callable_xy(facecolors, x_, y_, param_excluder(params), cache) a_ = check_callable_alpha(alpha, param_excluder(params, "alpha"), cache) + marker_ = callable_else_value_no_cast(marker, param_excluder(params), cache) + + if marker_ is not None: + if not isinstance(marker_, mmarkers.MarkerStyle): + marker_ = mmarkers.MarkerStyle(marker_) + path = marker_.get_path().transformed(marker_.get_transform()) + scatter.set_paths((path,)) + if c_ is not None: try: c_ = to_rgba_array(c_) @@ -584,6 +597,7 @@ def check_callable_alpha(alpha_, params, cache): ec_ = check_callable_xy(edgecolors, x_, y_, p, {}) fc_ = check_callable_xy(facecolors, x_, y_, p, {}) a_ = check_callable_alpha(alpha, params, {}) + marker_ = callable_else_value_no_cast(marker, p, {}) scatter = ax.scatter( x_, y_, @@ -592,6 +606,7 @@ def check_callable_alpha(alpha_, params, cache): vmin=vmin, vmax=vmax, cmap=cmap, + marker=marker_, alpha=a_, edgecolors=ec_, facecolors=fc_, From 6fc9482cf713c89e5d22f145209481258da0b894 Mon Sep 17 00:00:00 2001 From: Ian Hunt-Isaak Date: Wed, 2 Jun 2021 00:48:56 -0400 Subject: [PATCH 3/4] use new black ci options --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 30851c1..c4506bc 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,7 +10,7 @@ jobs: - uses: actions/setup-python@v2 - uses: psf/black@stable with: - black_args: ". --check --line-length=100" + options: ". --check --line-length=100" codespell: name: Check for spelling errors runs-on: ubuntu-latest From 28aa8e32ef73425702fb7e3b8dc2f7ccbc8fa3fa Mon Sep 17 00:00:00 2001 From: Ian Hunt-Isaak Date: Wed, 2 Jun 2021 00:56:55 -0400 Subject: [PATCH 4/4] vump! --- mpl_interactions/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpl_interactions/_version.py b/mpl_interactions/_version.py index a152703..399380b 100644 --- a/mpl_interactions/_version.py +++ b/mpl_interactions/_version.py @@ -1,2 +1,2 @@ -version_info = (0, 17, 11) +version_info = (0, 17, 12) __version__ = ".".join(map(str, version_info))