Skip to content

Commit c99393e

Browse files
committed
improve tutorial
1 parent e5ff348 commit c99393e

2 files changed

Lines changed: 46 additions & 15 deletions

File tree

src/maxplotlib/canvas/canvas.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,8 @@ def show(
736736
elif backend == "tikzfigure":
737737
fig = self.plot_tikzfigure(savefig=False, verbose=verbose)
738738
# TikzFigure handles all rendering (single or multi-subplot)
739-
fig.show()
739+
fig.show(transparent=False)
740+
return fig
740741
else:
741742
raise ValueError("Invalid backend")
742743

@@ -864,14 +865,15 @@ def plot_tikzfigure(
864865
x = (line_data["x"] + line_plot._xshift) * line_plot._xscale
865866
y = (line_data["y"] + line_plot._yshift) * line_plot._yscale
866867
kwargs = line_data.get("kwargs", {})
867-
868+
if verbose:
869+
print(f"Line {kwargs = }")
868870
# Add plot to subfigure axis
869871
ax.add_plot(
870872
x=x,
871873
y=y,
872874
# label=kwargs.get("label", ""),
873-
color=kwargs.get("color"),
874-
line_width=kwargs.get("linewidth"),
875+
color=kwargs.get("color", "black"),
876+
line_width=kwargs.get("linewidth", 1.0),
875877
)
876878

877879
# Add legend if requested

tutorials/tutorial_tikzfigure_subplots.ipynb

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,29 @@
2323
"source": [
2424
"from maxplotlib import Canvas\n",
2525
"import numpy as np\n",
26-
"\n",
26+
"%load_ext autoreload\n",
27+
"%autoreload 2"
28+
]
29+
},
30+
{
31+
"cell_type": "code",
32+
"execution_count": null,
33+
"id": "2",
34+
"metadata": {},
35+
"outputs": [],
36+
"source": [
2737
"# Create a 1×2 canvas with custom width\n",
2838
"x = np.linspace(0, 2 * np.pi, 200)\n",
2939
"canvas, (ax1, ax2) = Canvas.subplots(ncols=2, width=\"10cm\", ratio=0.3)\n",
3040
"\n",
3141
"# Left subplot: sine wave\n",
32-
"ax1.plot(x, np.sin(x), color=\"royalblue\", label=\"sin(x)\")\n",
42+
"ax1.plot(x, np.sin(x), color=\"royalblue\", label=\"sin(x)\", linewidth=1.5)\n",
3343
"ax1.set_title(\"sin(x)\")\n",
3444
"ax1.set_xlabel(\"x\")\n",
3545
"ax1.set_ylabel(\"amplitude\")\n",
3646
"\n",
3747
"# Right subplot: cosine wave\n",
38-
"ax2.plot(x, np.cos(x), color=\"tomato\", label=\"cos(x)\")\n",
48+
"ax2.plot(x, np.cos(x), color=\"tomato\", label=\"cos(x)\", linewidth=1.5)\n",
3949
"ax2.set_title(\"cos(x)\")\n",
4050
"ax2.set_xlabel(\"x\")\n",
4151
"\n",
@@ -48,7 +58,7 @@
4858
},
4959
{
5060
"cell_type": "markdown",
51-
"id": "2",
61+
"id": "3",
5262
"metadata": {},
5363
"source": [
5464
"## 1×3 Layout: Multiple Functions\n",
@@ -59,7 +69,7 @@
5969
{
6070
"cell_type": "code",
6171
"execution_count": null,
62-
"id": "3",
72+
"id": "4",
6373
"metadata": {},
6474
"outputs": [],
6575
"source": [
@@ -69,26 +79,27 @@
6979
"# Three different functions\n",
7080
"x = np.linspace(0, 2 * np.pi, 100)\n",
7181
"\n",
72-
"axes[0].plot(x, np.sin(x), color=\"royalblue\")\n",
82+
"axes[0].plot(x, np.sin(x), color=\"blue\")\n",
7383
"axes[0].set_title(\"sin(x)\")\n",
7484
"axes[0].set_xlabel(\"x\")\n",
7585
"\n",
76-
"axes[1].plot(x, np.cos(x), color=\"tomato\")\n",
86+
"axes[1].plot(x, np.cos(x), color=\"red\")\n",
7787
"axes[1].set_title(\"cos(x)\")\n",
7888
"axes[1].set_xlabel(\"x\")\n",
7989
"\n",
80-
"axes[2].plot(x, np.tan(x), color=\"seagreen\")\n",
90+
"axes[2].plot(x, np.tan(x), color=\"darkgreen\")\n",
8191
"axes[2].set_title(\"tan(x)\")\n",
8292
"axes[2].set_xlabel(\"x\")\n",
8393
"axes[2].set_ylim(-5, 5) # Limit y-range for tan\n",
8494
"\n",
8595
"canvas.suptitle(\"1 × 3 Layout: Three Trigonometric Functions\")\n",
86-
"result = canvas.show(backend=\"tikzfigure\")"
96+
"result = canvas.show(backend=\"tikzfigure\")\n",
97+
"print(result)"
8798
]
8899
},
89100
{
90101
"cell_type": "markdown",
91-
"id": "4",
102+
"id": "5",
92103
"metadata": {},
93104
"source": [
94105
"## Important Notes\n",
@@ -100,7 +111,25 @@
100111
]
101112
}
102113
],
103-
"metadata": {},
114+
"metadata": {
115+
"kernelspec": {
116+
"display_name": ".venv",
117+
"language": "python",
118+
"name": "python3"
119+
},
120+
"language_info": {
121+
"codemirror_mode": {
122+
"name": "ipython",
123+
"version": 3
124+
},
125+
"file_extension": ".py",
126+
"mimetype": "text/x-python",
127+
"name": "python",
128+
"nbconvert_exporter": "python",
129+
"pygments_lexer": "ipython3",
130+
"version": "3.13.3"
131+
}
132+
},
104133
"nbformat": 4,
105134
"nbformat_minor": 5
106135
}

0 commit comments

Comments
 (0)