File tree Expand file tree Collapse file tree 7 files changed +67
-3
lines changed
Expand file tree Collapse file tree 7 files changed +67
-3
lines changed File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ MyST supports embedding plots from other pages and site! Here are some such plot
1111
1212![ ] ( #fig-bokeh )
1313
14+ ## A Matplotlib Figure
15+
16+ ![ ] ( #fig-matplotlib )
17+
1418## An External Figure!
1519
1620![ ] ( xref:guide#img:altair-horsepower )
Original file line number Diff line number Diff line change 1+ ---
2+ kernelspec :
3+ name : python3
4+ display_name : Python 3
5+ ---
6+
7+ # Matplotlib
8+
9+ ``` {code-cell} python3
10+ import matplotlib.pyplot as plt
11+ import numpy as np
12+
13+
14+ def koch_snowflake(order, scale=10):
15+ """
16+ Return two lists x, y of point coordinates of the Koch snowflake.
17+
18+ Parameters
19+ ----------
20+ order : int
21+ The recursion depth.
22+ scale : float
23+ The extent of the snowflake (edge length of the base triangle).
24+ """
25+ def _koch_snowflake_complex(order):
26+ if order == 0:
27+ # initial triangle
28+ angles = np.array([0, 120, 240]) + 90
29+ return scale / np.sqrt(3) * np.exp(np.deg2rad(angles) * 1j)
30+ else:
31+ ZR = 0.5 - 0.5j * np.sqrt(3) / 3
32+
33+ p1 = _koch_snowflake_complex(order - 1) # start points
34+ p2 = np.roll(p1, shift=-1) # end points
35+ dp = p2 - p1 # connection vectors
36+
37+ new_points = np.empty(len(p1) * 4, dtype=np.complex128)
38+ new_points[::4] = p1
39+ new_points[1::4] = p1 + dp / 3
40+ new_points[2::4] = p1 + dp * ZR
41+ new_points[3::4] = p1 + dp / 3 * 2
42+ return new_points
43+
44+ points = _koch_snowflake_complex(order)
45+ x, y = points.real, points.imag
46+ return x, y
47+ ```
48+
49+ ``` {code-cell} python3
50+ :name: fig-matplotlib
51+ x, y = koch_snowflake(order=5)
52+
53+ plt.figure(figsize=(8, 8))
54+ plt.axis('equal')
55+ plt.fill(x, y)
56+ plt.show()
57+ ```
File renamed without changes.
Original file line number Diff line number Diff line change @@ -6,9 +6,10 @@ project:
66 references :
77 guide : https://mystmd.org/guide
88 toc :
9- - file : index.md
10- - file : bokeh.md
11- - file : plotly.md
9+ - file : content/index.md
10+ - file : content/bokeh.md
11+ - file : content/plotly.md
12+ - file : content/matplotlib.md
1213site :
1314 template : book-theme
1415 options :
Original file line number Diff line number Diff line change 22numpy
33plotly
44bokeh
5+ matplotlib
6+
57jupyter-server
68ipykernel
You can’t perform that action at this time.
0 commit comments