Skip to content

Commit 8670f22

Browse files
committed
breaking: rename <xyz>_kwds -> <xyz>_kwargs for consistency
1 parent 73bf7f8 commit 8670f22

File tree

5 files changed

+33
-31
lines changed

5 files changed

+33
-31
lines changed

examples/make_assets/uncertainty.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# %% Uncertainty Plots
1616
ax = pmv.qq_gaussian(
17-
y_pred, y_true, y_std, identity_line={"line_kwds": {"color": "red"}}
17+
y_pred, y_true, y_std, identity_line={"line_kwargs": {"color": "red"}}
1818
)
1919
pmv.io.save_and_compress_svg(ax, "normal-prob-plot")
2020

pymatviz/bar.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,18 @@ def spacegroup_bar(
222222
for patch in ax.patches[0 if x0 == 1 else x0 : x1 + 1]:
223223
patch.set_facecolor(color)
224224

225-
text_kwds = dict(transform=transform, horizontalalignment="center") | (
225+
text_kwargs = dict(transform=transform, horizontalalignment="center") | (
226226
text_kwargs or {}
227227
)
228-
crys_sys_anno_kwds = dict(
228+
crys_sys_anno_kwargs = dict(
229229
rotation=90, va="top", ha="right", fontdict={"fontsize": 14}
230230
)
231-
ax.text(*[(x0 + x1) / 2, 0.95], crys_sys, **crys_sys_anno_kwds | text_kwds)
231+
ax.text(*[(x0 + x1) / 2, 0.95], crys_sys, **crys_sys_anno_kwargs | text_kwargs)
232232
if show_counts:
233233
ax.text(
234234
*[(x0 + x1) / 2, 1.02],
235235
f"{si_fmt_int(count)} ({count / len(data):.0%})",
236-
**dict(fontdict={"fontsize": 12}) | text_kwds,
236+
**dict(fontdict={"fontsize": 12}) | text_kwargs,
237237
)
238238

239239
ax.fill_between(

pymatviz/powerups/both.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def calculate_metrics(xs: ArrayLike, ys: ArrayLike) -> str:
135135
def add_identity_line(
136136
fig: go.Figure | plt.Figure | plt.Axes,
137137
*,
138-
line_kwds: dict[str, Any] | None = None,
138+
line_kwargs: dict[str, Any] | None = None,
139139
trace_idx: int = 0,
140140
retain_xy_limits: bool = False,
141141
**kwargs: Any,
@@ -146,8 +146,8 @@ def add_identity_line(
146146
Args:
147147
fig (go.Figure | plt.Figure | plt.Axes): plotly/matplotlib figure or axes to
148148
add the identity line to.
149-
line_kwds (dict[str, Any], optional): Keyword arguments for customizing the line
150-
shape will be passed to fig.add_shape(line=line_kwds). Defaults to
149+
line_kwargs (dict[str, Any], optional): Keyword arguments for customizing the
150+
line shape will be passed to fig.add_shape(line=line_kwargs). Defaults to
151151
dict(color="gray", width=1, dash="dash").
152152
trace_idx (int, optional): Index of the trace to use for measuring x/y limits.
153153
Defaults to 0. Unused if kaleido package is installed and the figure's
@@ -171,7 +171,7 @@ def add_identity_line(
171171
ax = fig if isinstance(fig, plt.Axes) else fig.gca()
172172

173173
line_defaults = dict(alpha=0.5, zorder=0, linestyle="dashed", color="black")
174-
ax.axline((x_min, x_min), (x_max, x_max), **line_defaults | (line_kwds or {}))
174+
ax.axline((x_min, x_min), (x_max, x_max), **line_defaults | (line_kwargs or {}))
175175
return fig
176176

177177
if isinstance(fig, go.Figure):
@@ -189,7 +189,7 @@ def add_identity_line(
189189
type="line",
190190
**dict(x0=xy_min_min, y0=xy_min_min, x1=xy_max_min, y1=xy_max_min),
191191
layer="below",
192-
line=line_defaults | (line_kwds or {}),
192+
line=line_defaults | (line_kwargs or {}),
193193
**kwargs,
194194
)
195195
if retain_xy_limits:
@@ -207,7 +207,7 @@ def add_best_fit_line(
207207
xs: ArrayLike = (),
208208
ys: ArrayLike = (),
209209
trace_idx: int | None = None,
210-
line_kwds: dict[str, Any] | None = None,
210+
line_kwargs: dict[str, Any] | None = None,
211211
annotate_params: bool | dict[str, Any] = True,
212212
warn: bool = True,
213213
**kwargs: Any,
@@ -223,8 +223,8 @@ def add_best_fit_line(
223223
means use the y-values of trace at trace_idx in fig.
224224
trace_idx (int, optional): Index of the trace to use for measuring x/y values
225225
for fitting if xs and ys are not provided. Defaults to 0.
226-
line_kwds (dict[str, Any], optional): Keyword arguments for customizing the line
227-
shape. For plotly, will be passed to fig.add_shape(line=line_kwds).
226+
line_kwargs (dict[str, Any], optional): Keyword arguments for customizing the
227+
line shape. For plotly, will be passed to fig.add_shape(line=line_kwargs).
228228
For matplotlib, will be passed to ax.plot(). Defaults to None.
229229
annotate_params (dict[str, Any], optional): Pass dict to customize
230230
the annotation of the best fit line. Set to False to disable annotation.
@@ -302,7 +302,7 @@ def add_best_fit_line(
302302
)
303303

304304
defaults = dict(alpha=0.7, linestyle="--", zorder=1)
305-
ax.axline((x0, y0), (x1, y1), **(defaults | (line_kwds or {})) | kwargs)
305+
ax.axline((x0, y0), (x1, y1), **(defaults | (line_kwargs or {})) | kwargs)
306306

307307
return fig
308308

@@ -324,8 +324,8 @@ def add_best_fit_line(
324324
x0, x1 = x_min, x_max
325325
y0, y1 = slope * x0 + intercept, slope * x1 + intercept
326326

327-
line_kwds = (
328-
(line_kwds or {})
327+
line_kwargs = (
328+
(line_kwargs or {})
329329
| dict(color=line_color, width=2, dash="dash")
330330
| kwargs.pop("line", {})
331331
)
@@ -339,7 +339,7 @@ def add_best_fit_line(
339339
y1=y1,
340340
xref=xref,
341341
yref=yref,
342-
line=line_kwds,
342+
line=line_kwargs,
343343
**{k: v for k, v in kwargs.items() if k not in invalid_kwargs},
344344
)
345345

pymatviz/structure_viz.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,13 +427,13 @@ class used to plot chemical bonds. Allowed are edgecolor, facecolor, color,
427427
(0.5 * radius) * direction if occupancy < 1 else (0, 0)
428428
)
429429

430-
txt_kwds = dict(
430+
text_kwargs = dict(
431431
ha="center",
432432
va="center",
433433
zorder=zorder,
434434
**(label_kwargs or {}),
435435
)
436-
ax.text(*(xy + text_offset), txt, **txt_kwds)
436+
ax.text(*(xy + text_offset), txt, **text_kwargs)
437437

438438
start += occupancy
439439

tests/powerups/test_both_powerups.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ def test_add_best_fit_line_invalid_fig() -> None:
8585

8686

8787
def test_add_best_fit_line_custom_line_kwargs(plotly_scatter: go.Figure) -> None:
88-
line_kwds = {"width": 3, "dash": "dot"}
89-
result = pmv.powerups.add_best_fit_line(plotly_scatter, line_kwds=line_kwds)
88+
line_kwargs = {"width": 3, "dash": "dot"}
89+
result = pmv.powerups.add_best_fit_line(plotly_scatter, line_kwargs=line_kwargs)
9090

9191
best_fit_line = result.layout.shapes[-1]
9292
assert best_fit_line.line.width == 2
@@ -146,7 +146,7 @@ def test_add_best_fit_line_custom_xs_ys(
146146

147147

148148
@pytest.mark.parametrize(
149-
("xaxis_type", "yaxis_type", "trace_idx", "line_kwds", "retain_xy_limits"),
149+
("xaxis_type", "yaxis_type", "trace_idx", "line_kwargs", "retain_xy_limits"),
150150
[
151151
("linear", "log", 0, None, True),
152152
("log", "linear", 1, {"color": "red"}, False),
@@ -159,7 +159,7 @@ def test_add_identity_line(
159159
xaxis_type: str,
160160
yaxis_type: str,
161161
trace_idx: int,
162-
line_kwds: dict[str, str] | None,
162+
line_kwargs: dict[str, str] | None,
163163
retain_xy_limits: bool,
164164
) -> None:
165165
# Set axis types
@@ -173,7 +173,7 @@ def test_add_identity_line(
173173

174174
fig = pmv.powerups.add_identity_line(
175175
plotly_scatter,
176-
line_kwds=line_kwds,
176+
line_kwargs=line_kwargs,
177177
trace_idx=trace_idx,
178178
retain_xy_limits=retain_xy_limits,
179179
)
@@ -184,7 +184,7 @@ def test_add_identity_line(
184184
assert line is not None
185185

186186
assert line.layer == "below"
187-
assert line.line.color == (line_kwds["color"] if line_kwds else "gray")
187+
assert line.line.color == (line_kwargs["color"] if line_kwargs else "gray")
188188
# check line coordinates
189189
assert line.x0 == line.y0
190190
assert line.x1 == line.y1
@@ -205,17 +205,19 @@ def test_add_identity_line(
205205
assert y_range_post != y_range_pre
206206

207207

208-
@pytest.mark.parametrize("line_kwds", [None, {"color": "blue"}])
208+
@pytest.mark.parametrize("line_kwargs", [None, {"color": "blue"}])
209209
def test_add_identity_matplotlib(
210-
matplotlib_scatter: plt.Figure, line_kwds: dict[str, str] | None
210+
matplotlib_scatter: plt.Figure, line_kwargs: dict[str, str] | None
211211
) -> None:
212-
expected_line_color = (line_kwds or {}).get("color", "black")
212+
expected_line_color = (line_kwargs or {}).get("color", "black")
213213
# test Figure
214-
fig = pmv.powerups.add_identity_line(matplotlib_scatter, line_kwds=line_kwds)
214+
fig = pmv.powerups.add_identity_line(matplotlib_scatter, line_kwargs=line_kwargs)
215215
assert isinstance(fig, plt.Figure)
216216

217217
# test Axes
218-
ax = pmv.powerups.add_identity_line(matplotlib_scatter.axes[0], line_kwds=line_kwds)
218+
ax = pmv.powerups.add_identity_line(
219+
matplotlib_scatter.axes[0], line_kwargs=line_kwargs
220+
)
219221
assert isinstance(ax, plt.Axes)
220222

221223
line = fig.axes[0].lines[-1] # retrieve identity line
@@ -225,7 +227,7 @@ def test_add_identity_matplotlib(
225227
_fig_log, ax_log = plt.subplots()
226228
ax_log.plot([1, 10, 100], [10, 100, 1000])
227229
ax_log.set(xscale="log", yscale="log")
228-
ax_log = pmv.powerups.add_identity_line(ax, line_kwds=line_kwds)
230+
ax_log = pmv.powerups.add_identity_line(ax, line_kwargs=line_kwargs)
229231

230232
line = fig.axes[0].lines[-1]
231233
assert line.get_color() == expected_line_color

0 commit comments

Comments
 (0)