Skip to content

Commit 0f323db

Browse files
committed
Formatted ipynb tutorials
1 parent 1a4cee4 commit 0f323db

File tree

2 files changed

+89
-55
lines changed

2 files changed

+89
-55
lines changed

tutorials/tutorial_02.ipynb

Lines changed: 68 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@
2323
"outputs": [],
2424
"source": [
2525
"class PDF(object):\n",
26-
" def __init__(self, pdf, size=(200,200)):\n",
27-
" self.pdf = pdf\n",
28-
" self.size = size\n",
26+
" def __init__(self, pdf, size=(200, 200)):\n",
27+
" self.pdf = pdf\n",
28+
" self.size = size\n",
2929
"\n",
30-
" def _repr_html_(self):\n",
31-
" return '<iframe src={0} width={1[0]} height={1[1]}></iframe>'.format(self.pdf, self.size)\n",
30+
" def _repr_html_(self):\n",
31+
" return \"<iframe src={0} width={1[0]} height={1[1]}></iframe>\".format(\n",
32+
" self.pdf, self.size\n",
33+
" )\n",
3234
"\n",
33-
" def _repr_latex_(self):\n",
34-
" return r'\\includegraphics[width=1.0\\textwidth]{{{0}}}'.format(self.pdf)"
35+
" def _repr_latex_(self):\n",
36+
" return r\"\\includegraphics[width=1.0\\textwidth]{{{0}}}\".format(self.pdf)"
3537
]
3638
},
3739
{
@@ -53,23 +55,30 @@
5355
"tikz = c.add_tikzfigure(grid=False)\n",
5456
"\n",
5557
"# Add nodes\n",
56-
"tikz.add_node(0, 0, 'A', shape='circle', draw='black', fill='blue', layer=0)\n",
57-
"tikz.add_node(1, 0, 'B', shape='circle', draw='black', fill='blue', layer=0)\n",
58-
"tikz.add_node(1, 1, 'C', shape='circle', draw='black', fill='blue', layer=0)\n",
59-
"tikz.add_node(0, 1, 'D', shape='circle', draw='black', fill='blue', layer=2)\n",
58+
"tikz.add_node(0, 0, \"A\", shape=\"circle\", draw=\"black\", fill=\"blue\", layer=0)\n",
59+
"tikz.add_node(1, 0, \"B\", shape=\"circle\", draw=\"black\", fill=\"blue\", layer=0)\n",
60+
"tikz.add_node(1, 1, \"C\", shape=\"circle\", draw=\"black\", fill=\"blue\", layer=0)\n",
61+
"tikz.add_node(0, 1, \"D\", shape=\"circle\", draw=\"black\", fill=\"blue\", layer=2)\n",
6062
"\n",
6163
"\n",
62-
"# Add a line between nodes \n",
63-
"tikz.add_path(['A', 'B', 'C', 'D'], path_actions=['draw', 'rounded corners'], fill='red', opacity=1.0,cycle=True, layer=1)\n",
64+
"# Add a line between nodes\n",
65+
"tikz.add_path(\n",
66+
" [\"A\", \"B\", \"C\", \"D\"],\n",
67+
" path_actions=[\"draw\", \"rounded corners\"],\n",
68+
" fill=\"red\",\n",
69+
" opacity=1.0,\n",
70+
" cycle=True,\n",
71+
" layer=1,\n",
72+
")\n",
6473
"\n",
65-
"tikz.add_node(0.5, 0.5, content='Cube', layer=10)\n",
74+
"tikz.add_node(0.5, 0.5, content=\"Cube\", layer=10)\n",
6675
"\n",
6776
"# Generate the TikZ script\n",
68-
"#script = tikz.generate_tikz()\n",
69-
"#print(script)\n",
70-
"#print(tikz.generate_standalone())\n",
71-
"tikz.compile_pdf('my_figure.pdf')\n",
72-
"# "
77+
"# script = tikz.generate_tikz()\n",
78+
"# print(script)\n",
79+
"# print(tikz.generate_standalone())\n",
80+
"tikz.compile_pdf(\"my_figure.pdf\")\n",
81+
"#"
7382
]
7483
},
7584
{
@@ -109,29 +118,48 @@
109118
}
110119
],
111120
"source": [
112-
"c = canvas.Canvas(ncols=2,width=2000, ratio=0.5)\n",
121+
"c = canvas.Canvas(ncols=2, width=2000, ratio=0.5)\n",
113122
"tikz = c.add_tikzfigure(grid=False)\n",
114123
"\n",
115124
"# Add nodes\n",
116-
"node_a = tikz.add_node(-5, 0, 'A', content='Origin node', shape='circle', draw='black', fill='blue!20')\n",
117-
"tikz.add_node(2, 2, 'B', content=\"$a^2 + b^2 = c^2$\", shape='rectangle', draw='red', fill='white', layer=1)\n",
118-
"tikz.add_node(2, 5, 'C', shape='rectangle', draw='red', fill='red')\n",
119-
"last_node = tikz.add_node(-1, 5, shape='rectangle', draw='red', fill='red', layer=-10)\n",
125+
"node_a = tikz.add_node(\n",
126+
" -5, 0, \"A\", content=\"Origin node\", shape=\"circle\", draw=\"black\", fill=\"blue!20\"\n",
127+
")\n",
128+
"tikz.add_node(\n",
129+
" 2,\n",
130+
" 2,\n",
131+
" \"B\",\n",
132+
" content=\"$a^2 + b^2 = c^2$\",\n",
133+
" shape=\"rectangle\",\n",
134+
" draw=\"red\",\n",
135+
" fill=\"white\",\n",
136+
" layer=1,\n",
137+
")\n",
138+
"tikz.add_node(2, 5, \"C\", shape=\"rectangle\", draw=\"red\", fill=\"red\")\n",
139+
"last_node = tikz.add_node(-1, 5, shape=\"rectangle\", draw=\"red\", fill=\"red\", layer=-10)\n",
120140
"\n",
121-
"# Add a line between nodes \n",
122-
"tikz.add_path([node_a.label, 'B', 'C', 'A', last_node], color='green', style='solid', line_width='2',layer=-5)\n",
141+
"# Add a line between nodes\n",
142+
"tikz.add_path(\n",
143+
" [node_a.label, \"B\", \"C\", \"A\", last_node],\n",
144+
" color=\"green\",\n",
145+
" style=\"solid\",\n",
146+
" line_width=\"2\",\n",
147+
" layer=-5,\n",
148+
")\n",
123149
"\n",
124-
"sp = c.add_subplot(grid=True, xlabel='(x - 10) * 0.1', ylabel='10y',yscale=10,xshift=-10,xscale=0.1)\n",
150+
"sp = c.add_subplot(\n",
151+
" grid=True, xlabel=\"(x - 10) * 0.1\", ylabel=\"10y\", yscale=10, xshift=-10, xscale=0.1\n",
152+
")\n",
125153
"sp.add_line([0, 1, 2, 3], [0, 1, 4, 9], label=\"Line 1\")\n",
126-
"sp.add_line([0, 1, 2, 3], [0, 2, 3, 4], linestyle='dashed', color='red', label=\"Line 2\")\n",
154+
"sp.add_line([0, 1, 2, 3], [0, 2, 3, 4], linestyle=\"dashed\", color=\"red\", label=\"Line 2\")\n",
127155
"\n",
128156
"# Generate the TikZ script\n",
129157
"# print(tikz.generate_standalone())\n",
130158
"\n",
131-
"tikz.compile_pdf('my_figure.pdf')\n",
159+
"tikz.compile_pdf(\"my_figure.pdf\")\n",
132160
"\n",
133161
"# Replace 'path_to_pdf' with the path to your PDF file\n",
134-
"c.plot(backend='matplotlib')"
162+
"c.plot(backend=\"matplotlib\")"
135163
]
136164
},
137165
{
@@ -181,21 +209,21 @@
181209
"tikz = c.add_tikzfigure(grid=False)\n",
182210
"\n",
183211
"# Add nodes\n",
184-
"tikz.add_node(0, 0, 'A')\n",
185-
"tikz.add_node(10, 0, 'B')\n",
212+
"tikz.add_node(0, 0, \"A\")\n",
213+
"tikz.add_node(10, 0, \"B\")\n",
186214
"\n",
187215
"\n",
188-
"# Add a line between nodes \n",
189-
"tikz.add_path(['A', 'B'], path_actions=['->'], out=30)\n",
216+
"# Add a line between nodes\n",
217+
"tikz.add_path([\"A\", \"B\"], path_actions=[\"->\"], out=30)\n",
190218
"\n",
191219
"# Generate the TikZ script\n",
192-
"#script = tikz.generate_tikz()\n",
193-
"#print(script)\n",
220+
"# script = tikz.generate_tikz()\n",
221+
"# print(script)\n",
194222
"print(tikz.generate_standalone())\n",
195-
"tikz.compile_pdf('my_figure.pdf')\n",
223+
"tikz.compile_pdf(\"my_figure.pdf\")\n",
196224
"\n",
197-
"img = WImage(filename='my_figure.pdf')\n",
198-
"img\n"
225+
"img = WImage(filename=\"my_figure.pdf\")\n",
226+
"img"
199227
]
200228
},
201229
{
@@ -205,7 +233,7 @@
205233
"metadata": {},
206234
"outputs": [],
207235
"source": [
208-
"#PDF('my_figure.pdf',size=(600,250))"
236+
"# PDF('my_figure.pdf',size=(600,250))"
209237
]
210238
},
211239
{

tutorials/tutorial_1.ipynb

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@
4242
}
4343
],
4444
"source": [
45-
"c = canvas.Canvas(width='17cm', ratio=0.5, fontsize=12)\n",
46-
"sp = c.add_subplot(grid=True, xlabel='(x - 10) * 0.1', ylabel='10y',yscale=10,xshift=-10,xscale=0.1)\n",
45+
"c = canvas.Canvas(width=\"17cm\", ratio=0.5, fontsize=12)\n",
46+
"sp = c.add_subplot(\n",
47+
" grid=True, xlabel=\"(x - 10) * 0.1\", ylabel=\"10y\", yscale=10, xshift=-10, xscale=0.1\n",
48+
")\n",
4749
"sp.add_line([0, 1, 2, 3], [0, 1, 4, 9], label=\"Line 1\")\n",
48-
"sp.add_line([0, 1, 2, 3], [0, 2, 3, 4], linestyle='dashed', color='red', label=\"Line 2\")\n",
50+
"sp.add_line([0, 1, 2, 3], [0, 2, 3, 4], linestyle=\"dashed\", color=\"red\", label=\"Line 2\")\n",
4951
"c.plot()\n",
50-
"#c.savefig(filename='plot_00.pdf')"
52+
"# c.savefig(filename='plot_00.pdf')"
5153
]
5254
},
5355
{
@@ -1114,15 +1116,17 @@
11141116
}
11151117
],
11161118
"source": [
1117-
"c = canvas.Canvas(ncols=2,nrows=2, width=3000, ratio=0.5)\n",
1119+
"c = canvas.Canvas(ncols=2, nrows=2, width=3000, ratio=0.5)\n",
11181120
"sp = c.add_subplot(grid=True)\n",
11191121
"c.add_subplot(row=1)\n",
1120-
"sp2 = c.add_subplot(row=1,legend=False)\n",
1122+
"sp2 = c.add_subplot(row=1, legend=False)\n",
11211123
"sp.add_line([0, 1, 2, 3], [0, 1, 4, 9], label=\"Line 1\")\n",
1122-
"sp2.add_line([0, 1, 2, 3], [0, 2, 3, 4], linestyle='dashed', color='red', label=\"Line 2\")\n",
1123-
"c.plot(backend='matplotlib')\n",
1124-
"c.plot(backend='plotly')\n",
1125-
"c.savefig(filename='plot_01.pdf')"
1124+
"sp2.add_line(\n",
1125+
" [0, 1, 2, 3], [0, 2, 3, 4], linestyle=\"dashed\", color=\"red\", label=\"Line 2\"\n",
1126+
")\n",
1127+
"c.plot(backend=\"matplotlib\")\n",
1128+
"c.plot(backend=\"plotly\")\n",
1129+
"c.savefig(filename=\"plot_01.pdf\")"
11261130
]
11271131
},
11281132
{
@@ -2094,11 +2098,13 @@
20942098
"source": [
20952099
"# Test with plotly backend\n",
20962100
"c = canvas.Canvas(width=3000, ratio=0.5)\n",
2097-
"sp = c.add_subplot(grid=True, xlabel='x (mm)', ylabel='10y',yscale=10,xshift=-10,xscale=0.1)\n",
2098-
"sp.add_line([0, 1, 2, 3], [0, 1, 4, 9], label=\"Line 1\", linestyle='-.')\n",
2099-
"sp.add_line([0, 1, 2, 3], [0, 2, 3, 4], linestyle='dashed', color='red', label=\"Line 2\")\n",
2100-
"c.plot(backend='matplotlib')\n",
2101-
"c.plot(backend='plotly')"
2101+
"sp = c.add_subplot(\n",
2102+
" grid=True, xlabel=\"x (mm)\", ylabel=\"10y\", yscale=10, xshift=-10, xscale=0.1\n",
2103+
")\n",
2104+
"sp.add_line([0, 1, 2, 3], [0, 1, 4, 9], label=\"Line 1\", linestyle=\"-.\")\n",
2105+
"sp.add_line([0, 1, 2, 3], [0, 2, 3, 4], linestyle=\"dashed\", color=\"red\", label=\"Line 2\")\n",
2106+
"c.plot(backend=\"matplotlib\")\n",
2107+
"c.plot(backend=\"plotly\")"
21022108
]
21032109
},
21042110
{

0 commit comments

Comments
 (0)