Skip to content

Commit

Permalink
initial cleanup of kwarg passthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhi committed Nov 17, 2020
1 parent a837538 commit 72ac5cc
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 29 deletions.
58 changes: 58 additions & 0 deletions mpl_interactions/mpl_kwargs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# this is a list of options to Line2D partially taken from
# https://github.com/matplotlib/matplotlib/blob/f9d29189507cfe4121a231f6ab63539d216c37bd/lib/matplotlib/lines.py#L271
# many of these can also be made into functions
plot_kwargs_list = [
"alpha",
"linewidth",
"linestyle",
"color",
"marker",
"markersize",
"markeredgewidth",
"markeredgecolor",
"markerfacecolor",
"markerfacecoloralt",
"fillstyle",
"antialiased",
"dash_capstyle",
"solid_capstyle",
"dash_joinstyle",
"solid_joinstyle",
"pickradius",
"drawstyle",
"markevery",
"label",
]

imshow_kwargs_list = [
"cmap",
"norm",
"aspect",
"interpolation",
"alpha",
"vmin",
"vmax",
"origin",
"extent",
"filternorm",
"filterrad",
"resample",
"url",
]


def kwarg_popper(kwargs, mpl_kwargs):
"""
This will not modify kwargs for you.
Usage
-----
kwargs, plot_kwargs = kwarg_popper(kwargs, plot_kwargs_list)
"""
kwargs = dict(kwargs)
passthrough = {}
for k in mpl_kwargs:
if k in kwargs:
passthrough[k] = kwargs.pop(k)
return kwargs, passthrough
31 changes: 2 additions & 29 deletions mpl_interactions/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
notebook_backend,
update_datalim_from_bbox,
)
from .mpl_kwargs import plot_kwargs_list, imshow_kwargs_list, kwarg_popper

# functions that are methods
__all__ = [
Expand Down Expand Up @@ -128,35 +129,7 @@ def f(x, tau):
interactive_plot(x, f, tau=(0, np.pi, 1000))
"""
# this is a list of options to Line2D partially taken from
# https://github.com/matplotlib/matplotlib/blob/f9d29189507cfe4121a231f6ab63539d216c37bd/lib/matplotlib/lines.py#L271
# many of these can also be made into functions
plot_kwargs_list = [
"alpha",
"linewidth",
"linestyle",
"color",
"marker",
"markersize",
"markeredgewidth",
"markeredgecolor",
"markerfacecolor",
"markerfacecoloralt",
"fillstyle",
"antialiased",
"dash_capstyle",
"solid_capstyle",
"dash_joinstyle",
"solid_joinstyle",
"pickradius",
"drawstyle",
"markevery",
"label",
]
plot_kwargs = {}
for k in plot_kwargs_list:
if k in kwargs:
plot_kwargs[k] = kwargs.pop(k)
kwargs, plot_kwargs = kwarg_popper(kwargs, plot_kwargs_list)
x_and_y = False
x = None
fmt = None
Expand Down

0 comments on commit 72ac5cc

Please sign in to comment.