Skip to content

Commit 1efc9af

Browse files
committed
Converted tutorials to ipynb
1 parent b2adfdb commit 1efc9af

File tree

5 files changed

+320
-0
lines changed

5 files changed

+320
-0
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ dev = [
3030
"black",
3131
"isort",
3232
"jupyterlab",
33+
"nbstripout"
3334
]
3435
[project.urls]
3536
"Source" = "https://github.com/max-models/maxplotlib"

tutorials/tutorial_03.ipynb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "5a83b8ed",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import maxplotlib.canvas.canvas as canvas"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"id": "88c5ec37",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"c = canvas.Canvas(width=\"17cm\", ratio=0.5)\n",
21+
"sp = c.add_subplot(\n",
22+
" grid=False, xlabel=\"(x - 10) * 0.1\", ylabel=\"10y\", yscale=10, xshift=-10, xscale=0.1\n",
23+
")\n",
24+
"sp.add_line([0, 1, 2, 3], [0, 1, 4, 9], label=\"Line 1\", layer=0)\n",
25+
"sp.add_line(\n",
26+
" [0, 1, 2, 3], [0, 2, 3, 4], linestyle=\"dashed\", color=\"red\", label=\"Line 2\", layer=1\n",
27+
")\n",
28+
"# c.plot()\n",
29+
"c.savefig(layer_by_layer=True, filename=\"figures/tutorial_03_figure_01.pdf\")"
30+
]
31+
}
32+
],
33+
"metadata": {
34+
"jupytext": {
35+
"cell_metadata_filter": "-all",
36+
"main_language": "python",
37+
"notebook_metadata_filter": "-all"
38+
},
39+
"language_info": {
40+
"name": "python"
41+
}
42+
},
43+
"nbformat": 4,
44+
"nbformat_minor": 5
45+
}

tutorials/tutorial_04.ipynb

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "73e47d39",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"\"\"\"\n",
11+
"Tutorial 4.\n",
12+
"\n",
13+
"Add raw tikz code to the tikz subplot.\n",
14+
"\"\"\""
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": null,
20+
"id": "d3758983",
21+
"metadata": {},
22+
"outputs": [],
23+
"source": [
24+
"import maxplotlib.canvas.canvas as canvas"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": null,
30+
"id": "6018c33c",
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"c = canvas.Canvas(width=800, ratio=0.5)\n",
35+
"tikz = c.add_tikzfigure(grid=False)"
36+
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": null,
41+
"id": "274987f3",
42+
"metadata": {
43+
"lines_to_next_cell": 2
44+
},
45+
"outputs": [],
46+
"source": [
47+
"# Add nodes\n",
48+
"tikz.add_node(0, 0, \"A\", shape=\"circle\", draw=\"black\", fill=\"blue\", layer=0)\n",
49+
"tikz.add_node(10, 0, \"B\", shape=\"circle\", draw=\"black\", fill=\"blue\", layer=0)\n",
50+
"tikz.add_node(10, 10, \"C\", shape=\"circle\", draw=\"black\", fill=\"blue\", layer=0)\n",
51+
"tikz.add_node(0, 10, \"D\", shape=\"circle\", draw=\"black\", fill=\"blue\", layer=2)"
52+
]
53+
},
54+
{
55+
"cell_type": "code",
56+
"execution_count": null,
57+
"id": "6934ff1b",
58+
"metadata": {},
59+
"outputs": [],
60+
"source": [
61+
"# Add a line between nodes\n",
62+
"tikz.add_path(\n",
63+
" [\"A\", \"B\", \"C\", \"D\"],\n",
64+
" path_actions=[\"draw\", \"rounded corners\"],\n",
65+
" fill=\"red\",\n",
66+
" opacity=0.5,\n",
67+
" cycle=True,\n",
68+
" layer=1,\n",
69+
")"
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": null,
75+
"id": "64d9335c",
76+
"metadata": {},
77+
"outputs": [],
78+
"source": [
79+
"raw_tikz = r\"\"\"\n",
80+
"\\foreach \\i in {0, 45, 90, 135, 180, 225, 270, 315} {\n",
81+
" % Place a node at angle \\i\n",
82+
" \\node[circle, draw, fill=green] at (\\i:3) (N\\i) {};\n",
83+
"}\n",
84+
"\n",
85+
"% Draw lines connecting the nodes\n",
86+
"\\foreach \\i/\\j in {0/45, 45/90, 90/135, 135/180, 180/225, 225/270, 270/315, 315/0} {\n",
87+
" \\draw (N\\i) -- (N\\j);\n",
88+
"}\n",
89+
"\"\"\""
90+
]
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": null,
95+
"id": "f0a5b9c9",
96+
"metadata": {},
97+
"outputs": [],
98+
"source": [
99+
"tikz.add_raw(raw_tikz)"
100+
]
101+
},
102+
{
103+
"cell_type": "code",
104+
"execution_count": null,
105+
"id": "0a5a6d7f",
106+
"metadata": {},
107+
"outputs": [],
108+
"source": [
109+
"tikz.add_node(0.5, 0.5, content=\"Cube\", layer=10)"
110+
]
111+
},
112+
{
113+
"cell_type": "code",
114+
"execution_count": null,
115+
"id": "6cd2a009",
116+
"metadata": {},
117+
"outputs": [],
118+
"source": [
119+
"# Generate the TikZ script\n",
120+
"script = tikz.generate_tikz()\n",
121+
"print(script)\n",
122+
"# print(tikz.generate_standalone())\n",
123+
"tikz.compile_pdf(\"figures/tutorial_04_figure_01.pdf\")\n",
124+
"#"
125+
]
126+
}
127+
],
128+
"metadata": {
129+
"jupytext": {
130+
"cell_metadata_filter": "-all",
131+
"main_language": "python",
132+
"notebook_metadata_filter": "-all"
133+
}
134+
},
135+
"nbformat": 4,
136+
"nbformat_minor": 5
137+
}

tutorials/tutorial_05.ipynb

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "e5f3b684",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import numpy as np"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"id": "909dbed8",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"import maxplotlib.canvas.canvas as canvas"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": null,
26+
"id": "44c6922f",
27+
"metadata": {},
28+
"outputs": [],
29+
"source": [
30+
"c = canvas.Canvas(width="17cm", ratio=0.5)\n",
31+
"sp = c.add_subplot(grid=True, xlabel=\"x\", ylabel=\"y\")"
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": null,
37+
"id": "168ba89a",
38+
"metadata": {},
39+
"outputs": [],
40+
"source": [
41+
"node_a = sp.add_node(\n",
42+
" 0, 0, \"A\", content=\"Node A\", shape=\"circle\", draw=\"black\", fill=\"blue!20\"\n",
43+
")\n",
44+
"node_b = sp.add_node(\n",
45+
" 1, 1, \"B\", content=\"Node B\", shape=\"circle\", draw=\"black\", fill=\"blue!20\"\n",
46+
")\n",
47+
"# sp.add_node(2, 2, 'B', content=\"$a^2 + b^2 = c^2$\", shape='rectangle', draw='red', fill='white', layer=1)\n",
48+
"# sp.add_node(2, 5, 'C', shape='rectangle', draw='red', fill='red')\n",
49+
"# last_node = sp.add_node(-1, 5, shape='rectangle', draw='red', fill='red', layer=-10)"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": null,
55+
"id": "4f86d41a",
56+
"metadata": {},
57+
"outputs": [],
58+
"source": [
59+
"# Add a line between nodes\n",
60+
"sp.add_path([\"A\", \"B\"], color=\"green\", style=\"solid\", line_width=\"2\", layer=-5)"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": null,
66+
"id": "eb7dee8e",
67+
"metadata": {},
68+
"outputs": [],
69+
"source": [
70+
"x = np.arange(0, 2 * np.pi, 0.01)\n",
71+
"y = np.sin(x)\n",
72+
"sp.add_line(x, y, label=r\"$\\sin(x)$\")\n",
73+
"# c.plot()\n",
74+
"c.savefig(filename=\"figures/tutorial_05_figure_01.pdf\")"
75+
]
76+
}
77+
],
78+
"metadata": {
79+
"jupytext": {
80+
"cell_metadata_filter": "-all",
81+
"main_language": "python",
82+
"notebook_metadata_filter": "-all"
83+
}
84+
},
85+
"nbformat": 4,
86+
"nbformat_minor": 5
87+
}

tutorials/tutorial_06.ipynb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "9d413776",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import matplotlib.pyplot as plt\n",
11+
"import numpy as np"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": null,
17+
"id": "41b40c4d",
18+
"metadata": {},
19+
"outputs": [],
20+
"source": [
21+
"import maxplotlib.canvas.canvas as canvas"
22+
]
23+
},
24+
{
25+
"cell_type": "code",
26+
"execution_count": null,
27+
"id": "02c73973",
28+
"metadata": {},
29+
"outputs": [],
30+
"source": [
31+
"c = canvas.Canvas(width="17cm", ratio=0.5)\n",
32+
"sp = c.add_subplot(grid=False, xlabel=\"x\", ylabel=\"y\")\n",
33+
"# sp.add_line([0, 1, 2, 3], [0, 1, 4, 9], label=\"Line 1\",layer=1)\n",
34+
"data = np.random.random((10, 10))\n",
35+
"sp.add_imshow(data, extent=[1, 10, 1, 20], layer=1)\n",
36+
"# c.plot()\n",
37+
"c.savefig(layer_by_layer=True, filename=\"figures/tutorial_06_figure_01.pdf\")"
38+
]
39+
}
40+
],
41+
"metadata": {
42+
"jupytext": {
43+
"cell_metadata_filter": "-all",
44+
"main_language": "python",
45+
"notebook_metadata_filter": "-all"
46+
}
47+
},
48+
"nbformat": 4,
49+
"nbformat_minor": 5
50+
}

0 commit comments

Comments
 (0)