Skip to content

Commit d8531dc

Browse files
committed
formatting
1 parent 120f503 commit d8531dc

13 files changed

Lines changed: 106 additions & 144 deletions

examples/plotly_backend_parity.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ def main() -> None:
1919
marker="o",
2020
label="samples ± err",
2121
)
22-
canvas.fill_between(
23-
x, y - 0.1, y + 0.1, color="steelblue", alpha=0.2, label="band"
24-
)
22+
canvas.fill_between(x, y - 0.1, y + 0.1, color="steelblue", alpha=0.2, label="band")
2523
canvas.vlines([2, 5, 8], ymin=0, ymax=3.5, color="gray", linestyle="dashed")
2624
canvas.text(7.2, 2.8, "note", color="purple")
2725
canvas.annotate(

src/maxplotlib/subfigure/line_plot.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -691,11 +691,15 @@ def plotly_color(value):
691691
kwargs = line["kwargs"]
692692
x = tx(line["x"])
693693
if np.isscalar(line["y1"]):
694-
y1 = np.full_like(np.asarray(x, dtype=float), float(tys(line["y1"])))
694+
y1 = np.full_like(
695+
np.asarray(x, dtype=float), float(tys(line["y1"]))
696+
)
695697
else:
696698
y1 = ty(line["y1"])
697699
if np.isscalar(line["y2"]):
698-
y2 = np.full_like(np.asarray(x, dtype=float), float(tys(line["y2"])))
700+
y2 = np.full_like(
701+
np.asarray(x, dtype=float), float(tys(line["y2"]))
702+
)
699703
else:
700704
y2 = ty(line["y2"])
701705

@@ -732,7 +736,9 @@ def plotly_color(value):
732736
showlegend=bool(kwargs.get("label")) and bool(self._legend),
733737
line=dict(
734738
color=plotly_color(kwargs.get("color", None)),
735-
dash=linestyle_map.get(kwargs.get("linestyle", "solid"), "solid"),
739+
dash=linestyle_map.get(
740+
kwargs.get("linestyle", "solid"), "solid"
741+
),
736742
width=kwargs.get("linewidth", None),
737743
),
738744
marker=(
@@ -867,7 +873,9 @@ def plotly_color(value):
867873
if last_heatmap_idx is not None:
868874
label = line.get("label", "") or line["kwargs"].get("label", "")
869875
if label:
870-
traces[last_heatmap_idx].update(colorbar=dict(title=dict(text=label)))
876+
traces[last_heatmap_idx].update(
877+
colorbar=dict(title=dict(text=label))
878+
)
871879
elif plot_type == "patch":
872880
kwargs = line["kwargs"]
873881
patch = line["patch"]
@@ -879,22 +887,28 @@ def plotly_color(value):
879887
def _patch_line_color():
880888
return plotly_color(
881889
kwargs.get(
882-
"edgecolor",
883-
kwargs.get(
884-
"color",
885-
patch.get_edgecolor()
886-
if hasattr(patch, "get_edgecolor")
887-
else "black",
888-
),
889-
)
890+
"edgecolor",
891+
kwargs.get(
892+
"color",
893+
(
894+
patch.get_edgecolor()
895+
if hasattr(patch, "get_edgecolor")
896+
else "black"
897+
),
898+
),
899+
)
890900
)
891901

892902
def _patch_fill_color():
893903
return plotly_color(
894904
kwargs.get(
895-
"facecolor",
896-
patch.get_facecolor() if hasattr(patch, "get_facecolor") else None,
897-
)
905+
"facecolor",
906+
(
907+
patch.get_facecolor()
908+
if hasattr(patch, "get_facecolor")
909+
else None
910+
),
911+
)
898912
)
899913

900914
patch_label = kwargs.get("label")

src/maxplotlib/tests/test_plotly_backend.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ def test_plotly_backend_supports_common_primitives():
2323
assert fig is not None
2424
assert len(fig.data) >= 4 # line, scatter, errorbar, fill_between
2525
assert len(getattr(fig.layout, "shapes", []) or []) >= 2 # axhline + axvline
26-
assert len(getattr(fig.layout, "annotations", []) or []) >= 2 # subplot title + text/annotate
26+
assert (
27+
len(getattr(fig.layout, "annotations", []) or []) >= 2
28+
) # subplot title + text/annotate
2729

2830

2931
def test_plotly_backend_respects_layers():
@@ -48,9 +50,13 @@ def test_plotly_backend_supports_common_patches_and_symlog():
4850

4951
canvas, ax = Canvas.subplots()
5052
ax.add_patch(
51-
mpatches.Rectangle((0.2, 0.2), 1.3, 0.7, fill=False, edgecolor="yellow", label="r")
53+
mpatches.Rectangle(
54+
(0.2, 0.2), 1.3, 0.7, fill=False, edgecolor="yellow", label="r"
55+
)
56+
)
57+
ax.add_patch(
58+
mpatches.Circle((2.2, 1.6), 0.45, fill=False, edgecolor="cyan", label="c")
5259
)
53-
ax.add_patch(mpatches.Circle((2.2, 1.6), 0.45, fill=False, edgecolor="cyan", label="c"))
5460
ax.add_patch(
5561
mpatches.Polygon(
5662
[[3.0, 0.5], [3.8, 1.2], [3.4, 2.0]],

tutorials/tutorial_01.ipynb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@
5555
"outputs": [],
5656
"source": [
5757
"# Change to \"plotly\" for interactive output\n",
58-
"BACKEND = \"matplotlib\"\n",
59-
"\n"
58+
"BACKEND = \"matplotlib\""
6059
]
6160
},
6261
{
@@ -82,8 +81,7 @@
8281
"\n",
8382
"canvas, ax = Canvas.subplots()\n",
8483
"ax.plot(x, y)\n",
85-
"canvas.show(backend=BACKEND)\n",
86-
"\n"
84+
"canvas.show(backend=BACKEND)"
8785
]
8886
},
8987
{
@@ -119,8 +117,7 @@
119117
"ax.set_title(\"Sine and Cosine\")\n",
120118
"ax.set_legend(True)\n",
121119
"\n",
122-
"canvas.show(backend=BACKEND)\n",
123-
"\n"
120+
"canvas.show(backend=BACKEND)"
124121
]
125122
},
126123
{
@@ -152,8 +149,7 @@
152149
"canvas.set_legend(True)\n",
153150
"canvas.set_grid(True)\n",
154151
"\n",
155-
"canvas.show(backend=BACKEND)\n",
156-
"\n"
152+
"canvas.show(backend=BACKEND)"
157153
]
158154
},
159155
{
@@ -186,8 +182,7 @@
186182
"ax.plot(x, np.sin(x), label=\"sin\", color=\"royalblue\")\n",
187183
"ax.plot(x, x / (2 * np.pi), label=\"x/2π\", color=\"coral\", linestyle=\"dashed\")\n",
188184
"\n",
189-
"canvas.show(backend=BACKEND)\n",
190-
"\n"
185+
"canvas.show(backend=BACKEND)"
191186
]
192187
},
193188
{

tutorials/tutorial_02.ipynb

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@
5959
"outputs": [],
6060
"source": [
6161
"# Change to \"plotly\" for interactive output\n",
62-
"BACKEND = \"matplotlib\"\n",
63-
"\n"
62+
"BACKEND = \"matplotlib\""
6463
]
6564
},
6665
{
@@ -167,8 +166,7 @@
167166
"axes[1][1].set_title(\"cos(2x)\")\n",
168167
"\n",
169168
"canvas.suptitle(\"2 × 2 Layout\")\n",
170-
"canvas.show(backend=BACKEND)\n",
171-
"\n"
169+
"canvas.show(backend=BACKEND)"
172170
]
173171
},
174172
{
@@ -199,8 +197,7 @@
199197
" axes[0][col].plot(x, d, color=\"steelblue\")\n",
200198
" axes[0][col].set_title(t)\n",
201199
"\n",
202-
"canvas.show(backend=BACKEND)\n",
203-
"\n"
200+
"canvas.show(backend=BACKEND)"
204201
]
205202
},
206203
{
@@ -237,8 +234,7 @@
237234
"ax11.plot(x, np.cos(x), label=\"cos\", color=\"tomato\")\n",
238235
"\n",
239236
"canvas.suptitle(\"Manual Layout\")\n",
240-
"canvas.show(backend=BACKEND)\n",
241-
"\n"
237+
"canvas.show(backend=BACKEND)"
242238
]
243239
},
244240
{
@@ -271,8 +267,7 @@
271267
"canvas[1, 0].set_title(\"Method C\")\n",
272268
"canvas[1, 1].set_title(\"Method D (index)\")\n",
273269
"\n",
274-
"canvas.show(backend=BACKEND)\n",
275-
"\n"
270+
"canvas.show(backend=BACKEND)"
276271
]
277272
},
278273
{
@@ -302,8 +297,7 @@
302297
" sp.set_grid(True)\n",
303298
" sp.set_xlabel(\"x\")\n",
304299
"\n",
305-
"canvas.show(backend=BACKEND)\n",
306-
"\n"
300+
"canvas.show(backend=BACKEND)"
307301
]
308302
},
309303
{
@@ -333,8 +327,7 @@
333327
"canvas.set_legend(True, row=0, col=0)\n",
334328
"canvas.set_legend(True, row=0, col=1)\n",
335329
"canvas.suptitle(\"Canvas-level routing\")\n",
336-
"canvas.show(backend=BACKEND)\n",
337-
"\n"
330+
"canvas.show(backend=BACKEND)"
338331
]
339332
},
340333
{

tutorials/tutorial_03.ipynb

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@
5656
"outputs": [],
5757
"source": [
5858
"# Change to \"plotly\" for interactive output\n",
59-
"BACKEND = \"matplotlib\"\n",
60-
"\n"
59+
"BACKEND = \"matplotlib\""
6160
]
6261
},
6362
{
@@ -85,8 +84,7 @@
8584
"ax.set_title(\"Line Plot\")\n",
8685
"ax.set_legend(True)\n",
8786
"ax.set_grid(True)\n",
88-
"canvas.show(backend=BACKEND)\n",
89-
"\n"
87+
"canvas.show(backend=BACKEND)"
9088
]
9189
},
9290
{
@@ -117,8 +115,7 @@
117115
"ax.set_ylabel(\"y\")\n",
118116
"ax.set_title(\"Scatter Plot — coloured by distance\")\n",
119117
"ax.set_aspect(\"equal\")\n",
120-
"canvas.show(backend=BACKEND)\n",
121-
"\n"
118+
"canvas.show(backend=BACKEND)"
122119
]
123120
},
124121
{
@@ -145,8 +142,7 @@
145142
"ax.set_ylabel(\"Sales (units)\")\n",
146143
"ax.set_title(\"Bar Chart\")\n",
147144
"ax.set_legend(True)\n",
148-
"# canvas.show(backend=BACKEND) # TODO: Fix this error\n",
149-
"\n"
145+
"# canvas.show(backend=BACKEND) # TODO: Fix this error"
150146
]
151147
},
152148
{
@@ -178,8 +174,7 @@
178174
"ax.set_ylabel(\"value\")\n",
179175
"ax.set_title(\"Fill Between — Confidence Band\")\n",
180176
"ax.set_legend(True)\n",
181-
"canvas.show(backend=BACKEND)\n",
182-
"\n"
177+
"canvas.show(backend=BACKEND)"
183178
]
184179
},
185180
{
@@ -209,8 +204,7 @@
209204
"ax.set_title(\"Error Bars\")\n",
210205
"ax.set_legend(True)\n",
211206
"ax.set_grid(True)\n",
212-
"canvas.show(backend=BACKEND)\n",
213-
"\n"
207+
"canvas.show(backend=BACKEND)"
214208
]
215209
},
216210
{
@@ -241,8 +235,7 @@
241235
"ax.set_xlabel(\"x\")\n",
242236
"ax.set_title(\"axhline / axvline\")\n",
243237
"ax.set_legend(True)\n",
244-
"canvas.show(backend=BACKEND)\n",
245-
"\n"
238+
"canvas.show(backend=BACKEND)"
246239
]
247240
},
248241
{
@@ -288,8 +281,7 @@
288281
"ax.set_xlabel(\"x\")\n",
289282
"ax.set_title(\"hlines / vlines\")\n",
290283
"ax.set_legend(True)\n",
291-
"canvas.show(backend=BACKEND)\n",
292-
"\n"
284+
"canvas.show(backend=BACKEND)"
293285
]
294286
},
295287
{
@@ -333,8 +325,7 @@
333325
"ax.set_title(\"Combined: line + fill_between + scatter\")\n",
334326
"ax.set_legend(True)\n",
335327
"ax.set_grid(True)\n",
336-
"canvas.show(backend=BACKEND)\n",
337-
"\n"
328+
"canvas.show(backend=BACKEND)"
338329
]
339330
},
340331
{
@@ -369,8 +360,7 @@
369360
"ax.set_xlabel(\"x\")\n",
370361
"ax.set_ylabel(\"sin(x)\")\n",
371362
"ax.set_title(\"Annotate and Text\")\n",
372-
"canvas.show(backend=BACKEND)\n",
373-
"\n"
363+
"canvas.show(backend=BACKEND)"
374364
]
375365
},
376366
{

0 commit comments

Comments
 (0)