Skip to content

Commit 72ac5cc

Browse files
committed
initial cleanup of kwarg passthrough
1 parent a837538 commit 72ac5cc

File tree

2 files changed

+60
-29
lines changed

2 files changed

+60
-29
lines changed

mpl_interactions/mpl_kwargs.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# this is a list of options to Line2D partially taken from
2+
# https://github.com/matplotlib/matplotlib/blob/f9d29189507cfe4121a231f6ab63539d216c37bd/lib/matplotlib/lines.py#L271
3+
# many of these can also be made into functions
4+
plot_kwargs_list = [
5+
"alpha",
6+
"linewidth",
7+
"linestyle",
8+
"color",
9+
"marker",
10+
"markersize",
11+
"markeredgewidth",
12+
"markeredgecolor",
13+
"markerfacecolor",
14+
"markerfacecoloralt",
15+
"fillstyle",
16+
"antialiased",
17+
"dash_capstyle",
18+
"solid_capstyle",
19+
"dash_joinstyle",
20+
"solid_joinstyle",
21+
"pickradius",
22+
"drawstyle",
23+
"markevery",
24+
"label",
25+
]
26+
27+
imshow_kwargs_list = [
28+
"cmap",
29+
"norm",
30+
"aspect",
31+
"interpolation",
32+
"alpha",
33+
"vmin",
34+
"vmax",
35+
"origin",
36+
"extent",
37+
"filternorm",
38+
"filterrad",
39+
"resample",
40+
"url",
41+
]
42+
43+
44+
def kwarg_popper(kwargs, mpl_kwargs):
45+
"""
46+
This will not modify kwargs for you.
47+
48+
Usage
49+
-----
50+
51+
kwargs, plot_kwargs = kwarg_popper(kwargs, plot_kwargs_list)
52+
"""
53+
kwargs = dict(kwargs)
54+
passthrough = {}
55+
for k in mpl_kwargs:
56+
if k in kwargs:
57+
passthrough[k] = kwargs.pop(k)
58+
return kwargs, passthrough

mpl_interactions/pyplot.py

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
notebook_backend,
2525
update_datalim_from_bbox,
2626
)
27+
from .mpl_kwargs import plot_kwargs_list, imshow_kwargs_list, kwarg_popper
2728

2829
# functions that are methods
2930
__all__ = [
@@ -128,35 +129,7 @@ def f(x, tau):
128129
interactive_plot(x, f, tau=(0, np.pi, 1000))
129130
130131
"""
131-
# this is a list of options to Line2D partially taken from
132-
# https://github.com/matplotlib/matplotlib/blob/f9d29189507cfe4121a231f6ab63539d216c37bd/lib/matplotlib/lines.py#L271
133-
# many of these can also be made into functions
134-
plot_kwargs_list = [
135-
"alpha",
136-
"linewidth",
137-
"linestyle",
138-
"color",
139-
"marker",
140-
"markersize",
141-
"markeredgewidth",
142-
"markeredgecolor",
143-
"markerfacecolor",
144-
"markerfacecoloralt",
145-
"fillstyle",
146-
"antialiased",
147-
"dash_capstyle",
148-
"solid_capstyle",
149-
"dash_joinstyle",
150-
"solid_joinstyle",
151-
"pickradius",
152-
"drawstyle",
153-
"markevery",
154-
"label",
155-
]
156-
plot_kwargs = {}
157-
for k in plot_kwargs_list:
158-
if k in kwargs:
159-
plot_kwargs[k] = kwargs.pop(k)
132+
kwargs, plot_kwargs = kwarg_popper(kwargs, plot_kwargs_list)
160133
x_and_y = False
161134
x = None
162135
fmt = None

0 commit comments

Comments
 (0)