Skip to content

Commit 52a7579

Browse files
committed
Formatting and add black[jupyter] to deps
1 parent 70923cf commit 52a7579

11 files changed

Lines changed: 627 additions & 421 deletions

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ docs = [
3636
dev = [
3737
"maxplotlibx[test,docs]",
3838
"ruff",
39-
"black",
39+
"black[jupyter]",
4040
"isort",
4141
"jupyterlab",
4242
"nbstripout",

src/maxplotlib/canvas/canvas.py

Lines changed: 93 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -384,19 +384,27 @@ def set_title(self, title: str, row: int | None = None, col: int | None = None):
384384
"""Set the title for a subplot (default top-left)."""
385385
self._get_or_create_subplot(row, col).set_title(title)
386386

387-
def set_xlim(self, left=None, right=None, row: int | None = None, col: int | None = None):
387+
def set_xlim(
388+
self, left=None, right=None, row: int | None = None, col: int | None = None
389+
):
388390
"""Set the x-axis limits for a subplot (default top-left)."""
389391
self._get_or_create_subplot(row, col).set_xlim(left, right)
390392

391-
def set_ylim(self, bottom=None, top=None, row: int | None = None, col: int | None = None):
393+
def set_ylim(
394+
self, bottom=None, top=None, row: int | None = None, col: int | None = None
395+
):
392396
"""Set the y-axis limits for a subplot (default top-left)."""
393397
self._get_or_create_subplot(row, col).set_ylim(bottom, top)
394398

395-
def set_grid(self, visible: bool = True, row: int | None = None, col: int | None = None):
399+
def set_grid(
400+
self, visible: bool = True, row: int | None = None, col: int | None = None
401+
):
396402
"""Show or hide the grid for a subplot (default top-left)."""
397403
self._get_or_create_subplot(row, col).set_grid(visible)
398404

399-
def set_legend(self, visible: bool = True, row: int | None = None, col: int | None = None):
405+
def set_legend(
406+
self, visible: bool = True, row: int | None = None, col: int | None = None
407+
):
400408
"""Show or hide the legend for a subplot (default top-left)."""
401409
self._get_or_create_subplot(row, col).set_legend(visible)
402410

@@ -408,43 +416,109 @@ def set_yscale(self, scale: str, row: int | None = None, col: int | None = None)
408416
"""Set y-axis scale ('linear', 'log', 'symlog') for a subplot."""
409417
self._get_or_create_subplot(row, col).set_yscale(scale)
410418

411-
def set_xticks(self, ticks, labels=None, row: int | None = None, col: int | None = None):
419+
def set_xticks(
420+
self, ticks, labels=None, row: int | None = None, col: int | None = None
421+
):
412422
"""Set x-axis tick positions (and optional labels) for a subplot."""
413423
self._get_or_create_subplot(row, col).set_xticks(ticks, labels)
414424

415-
def set_yticks(self, ticks, labels=None, row: int | None = None, col: int | None = None):
425+
def set_yticks(
426+
self, ticks, labels=None, row: int | None = None, col: int | None = None
427+
):
416428
"""Set y-axis tick positions (and optional labels) for a subplot."""
417429
self._get_or_create_subplot(row, col).set_yticks(ticks, labels)
418430

419-
def fill_between(self, x, y1, y2=0, layer=0, row: int | None = None, col: int | None = None, **kwargs):
431+
def fill_between(
432+
self,
433+
x,
434+
y1,
435+
y2=0,
436+
layer=0,
437+
row: int | None = None,
438+
col: int | None = None,
439+
**kwargs,
440+
):
420441
"""Fill the region between two curves on a subplot."""
421-
self._get_or_create_subplot(row, col).fill_between(x, y1, y2, layer=layer, **kwargs)
442+
self._get_or_create_subplot(row, col).fill_between(
443+
x, y1, y2, layer=layer, **kwargs
444+
)
422445

423-
def errorbar(self, x, y, yerr=None, xerr=None, layer=0, row: int | None = None, col: int | None = None, **kwargs):
446+
def errorbar(
447+
self,
448+
x,
449+
y,
450+
yerr=None,
451+
xerr=None,
452+
layer=0,
453+
row: int | None = None,
454+
col: int | None = None,
455+
**kwargs,
456+
):
424457
"""Add an error-bar line to a subplot."""
425-
self._get_or_create_subplot(row, col).errorbar(x, y, yerr=yerr, xerr=xerr, layer=layer, **kwargs)
458+
self._get_or_create_subplot(row, col).errorbar(
459+
x, y, yerr=yerr, xerr=xerr, layer=layer, **kwargs
460+
)
426461

427-
def axhline(self, y=0, layer=0, row: int | None = None, col: int | None = None, **kwargs):
462+
def axhline(
463+
self, y=0, layer=0, row: int | None = None, col: int | None = None, **kwargs
464+
):
428465
"""Add a full-width horizontal reference line to a subplot."""
429466
self._get_or_create_subplot(row, col).axhline(y=y, layer=layer, **kwargs)
430467

431-
def axvline(self, x=0, layer=0, row: int | None = None, col: int | None = None, **kwargs):
468+
def axvline(
469+
self, x=0, layer=0, row: int | None = None, col: int | None = None, **kwargs
470+
):
432471
"""Add a full-height vertical reference line to a subplot."""
433472
self._get_or_create_subplot(row, col).axvline(x=x, layer=layer, **kwargs)
434473

435-
def hlines(self, y, xmin, xmax, layer=0, row: int | None = None, col: int | None = None, **kwargs):
474+
def hlines(
475+
self,
476+
y,
477+
xmin,
478+
xmax,
479+
layer=0,
480+
row: int | None = None,
481+
col: int | None = None,
482+
**kwargs,
483+
):
436484
"""Add horizontal lines at specified y positions to a subplot."""
437-
self._get_or_create_subplot(row, col).hlines(y, xmin, xmax, layer=layer, **kwargs)
485+
self._get_or_create_subplot(row, col).hlines(
486+
y, xmin, xmax, layer=layer, **kwargs
487+
)
438488

439-
def vlines(self, x, ymin, ymax, layer=0, row: int | None = None, col: int | None = None, **kwargs):
489+
def vlines(
490+
self,
491+
x,
492+
ymin,
493+
ymax,
494+
layer=0,
495+
row: int | None = None,
496+
col: int | None = None,
497+
**kwargs,
498+
):
440499
"""Add vertical lines at specified x positions to a subplot."""
441-
self._get_or_create_subplot(row, col).vlines(x, ymin, ymax, layer=layer, **kwargs)
500+
self._get_or_create_subplot(row, col).vlines(
501+
x, ymin, ymax, layer=layer, **kwargs
502+
)
442503

443-
def annotate(self, text, xy, xytext=None, layer=0, row: int | None = None, col: int | None = None, **kwargs):
504+
def annotate(
505+
self,
506+
text,
507+
xy,
508+
xytext=None,
509+
layer=0,
510+
row: int | None = None,
511+
col: int | None = None,
512+
**kwargs,
513+
):
444514
"""Add an annotation (with optional arrow) to a subplot."""
445-
self._get_or_create_subplot(row, col).annotate(text, xy, xytext=xytext, layer=layer, **kwargs)
515+
self._get_or_create_subplot(row, col).annotate(
516+
text, xy, xytext=xytext, layer=layer, **kwargs
517+
)
446518

447-
def text(self, x, y, s, layer=0, row: int | None = None, col: int | None = None, **kwargs):
519+
def text(
520+
self, x, y, s, layer=0, row: int | None = None, col: int | None = None, **kwargs
521+
):
448522
"""Add a text label at (x, y) on a subplot."""
449523
self._get_or_create_subplot(row, col).text(x, y, s, layer=layer, **kwargs)
450524

src/maxplotlib/subfigure/line_plot.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,16 @@ def plot_matplotlib(
465465
elif line["plot_type"] == "fill_between":
466466
ax.fill_between(
467467
(line["x"] + self._xshift) * self._xscale,
468-
line["y1"] if np.isscalar(line["y1"]) else (line["y1"] + self._yshift) * self._yscale,
469-
line["y2"] if np.isscalar(line["y2"]) else (line["y2"] + self._yshift) * self._yscale,
468+
(
469+
line["y1"]
470+
if np.isscalar(line["y1"])
471+
else (line["y1"] + self._yshift) * self._yscale
472+
),
473+
(
474+
line["y2"]
475+
if np.isscalar(line["y2"])
476+
else (line["y2"] + self._yshift) * self._yscale
477+
),
470478
**line["kwargs"],
471479
)
472480
elif line["plot_type"] == "errorbar":
@@ -645,5 +653,7 @@ def legend(self, value):
645653
if __name__ == "__main__":
646654
plotter = LinePlot(xlabel="x", ylabel="y", title="Example", legend=True)
647655
plotter.plot([0, 1, 2, 3], [0, 1, 4, 9], label="Line 1")
648-
plotter.plot([0, 1, 2, 3], [0, 2, 3, 6], linestyle="dashed", color="red", label="Line 2")
656+
plotter.plot(
657+
[0, 1, 2, 3], [0, 2, 3, 6], linestyle="dashed", color="red", label="Line 2"
658+
)
649659
plotter.scatter([0, 1, 2, 3], [0, 0.5, 2, 5], label="Scatter")

tutorials/tutorial_01.ipynb

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,20 @@
7474
"source": [
7575
"canvas, ax = Canvas.subplots()\n",
7676
"\n",
77-
"ax.plot(x, np.sin(x), label='sin(x)', color='royalblue', linestyle='solid', linewidth=2)\n",
78-
"ax.plot(x, np.cos(x), label='cos(x)', color='tomato', linestyle='dashed', linewidth=2)\n",
79-
"ax.plot(x, np.sin(2*x), label='sin(2x)', color='forestgreen',linestyle='dotted', linewidth=1.5)\n",
77+
"ax.plot(x, np.sin(x), label=\"sin(x)\", color=\"royalblue\", linestyle=\"solid\", linewidth=2)\n",
78+
"ax.plot(x, np.cos(x), label=\"cos(x)\", color=\"tomato\", linestyle=\"dashed\", linewidth=2)\n",
79+
"ax.plot(\n",
80+
" x,\n",
81+
" np.sin(2 * x),\n",
82+
" label=\"sin(2x)\",\n",
83+
" color=\"forestgreen\",\n",
84+
" linestyle=\"dotted\",\n",
85+
" linewidth=1.5,\n",
86+
")\n",
8087
"\n",
81-
"ax.set_xlabel('x')\n",
82-
"ax.set_ylabel('y')\n",
83-
"ax.set_title('Sine and Cosine')\n",
88+
"ax.set_xlabel(\"x\")\n",
89+
"ax.set_ylabel(\"y\")\n",
90+
"ax.set_title(\"Sine and Cosine\")\n",
8491
"ax.set_legend(True)\n",
8592
"\n",
8693
"canvas.show()"
@@ -106,12 +113,12 @@
106113
"source": [
107114
"canvas = Canvas(ratio=0.5, fontsize=12)\n",
108115
"\n",
109-
"canvas.add_line(x, np.sin(x), label='sin(x)', color='steelblue')\n",
110-
"canvas.add_line(x, np.cos(x), label='cos(x)', color='darkorange', linestyle='dashed')\n",
116+
"canvas.add_line(x, np.sin(x), label=\"sin(x)\", color=\"steelblue\")\n",
117+
"canvas.add_line(x, np.cos(x), label=\"cos(x)\", color=\"darkorange\", linestyle=\"dashed\")\n",
111118
"\n",
112-
"canvas.set_xlabel('angle (rad)')\n",
113-
"canvas.set_ylabel('amplitude')\n",
114-
"canvas.set_title('Using canvas-level methods')\n",
119+
"canvas.set_xlabel(\"angle (rad)\")\n",
120+
"canvas.set_ylabel(\"amplitude\")\n",
121+
"canvas.set_title(\"Using canvas-level methods\")\n",
115122
"canvas.set_legend(True)\n",
116123
"canvas.set_grid(True)\n",
117124
"\n",
@@ -138,15 +145,15 @@
138145
"source": [
139146
"canvas = Canvas(ratio=0.5)\n",
140147
"ax = canvas.add_subplot(\n",
141-
" title='Configured at creation',\n",
142-
" xlabel='x',\n",
143-
" ylabel='f(x)',\n",
148+
" title=\"Configured at creation\",\n",
149+
" xlabel=\"x\",\n",
150+
" ylabel=\"f(x)\",\n",
144151
" grid=True,\n",
145152
" legend=True,\n",
146153
")\n",
147154
"\n",
148-
"ax.plot(x, np.sin(x), label='sin', color='royalblue')\n",
149-
"ax.plot(x, x / (2*np.pi), label='x/2π', color='coral', linestyle='dashed')\n",
155+
"ax.plot(x, np.sin(x), label=\"sin\", color=\"royalblue\")\n",
156+
"ax.plot(x, x / (2 * np.pi), label=\"x/2π\", color=\"coral\", linestyle=\"dashed\")\n",
150157
"\n",
151158
"canvas.show()"
152159
]
@@ -170,11 +177,11 @@
170177
"outputs": [],
171178
"source": [
172179
"canvas = Canvas(ratio=0.5)\n",
173-
"ax = canvas.add_subplot(xlabel='x', ylabel='sin(x)', grid=True)\n",
174-
"ax.plot(x, np.sin(x), color='steelblue')\n",
180+
"ax = canvas.add_subplot(xlabel=\"x\", ylabel=\"sin(x)\", grid=True)\n",
181+
"ax.plot(x, np.sin(x), color=\"steelblue\")\n",
175182
"\n",
176-
"canvas.savefig('tutorial_01_output.png')\n",
177-
"print('Figure saved to tutorial_01_output.png')"
183+
"canvas.savefig(\"tutorial_01_output.png\")\n",
184+
"print(\"Figure saved to tutorial_01_output.png\")"
178185
]
179186
},
180187
{

0 commit comments

Comments
 (0)