2022年12月6日 星期二

Python Matplotlib(二)細部元件

Python Matplotlib(二)細部元件

2022/11/22

-----


Fig. m2.1. Anatomy of a figure.

-----

代碼 m2.1


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Program m2.1:Anatomy of a figure
import numpy as np
import matplotlib.pyplot as plt

# plt.figure
fig = plt.figure(figsize=(16, 16))
ax = fig.add_subplot(111)

# ax.plot
x = np.linspace(0, 4, 100)
y1 = 3 + np.cos(x)
y2 = 1 - np.sin(x)
ax.plot(x, y1, lw='5')
ax.plot(x, y2, lw='5')

# ax.scatter
np.random.seed(12)
y_point = np.random.uniform(y1, y2, len(x))
ax.scatter(x, y_point, s=30, facecolor='white', edgecolor='black', linewidth=1)

# ax.set_title
ax.set_title('Anatomy of a figure', fontsize=40)

# ax.legend
ax.legend(['Blue cosine', 'Orange sine'], fontsize=30)
ax.text(3.54, 3.4, 'Legend', style='italic', fontsize=20, fontweight='bold')
ax.text(3.5, 3.25, 'ax.legend', fontsize=20)

ringstyle = dict(zorder=50, facecolor='None', clip_on=False)
ax.scatter(3.6, 3.6, s=700, edgecolor='white', linewidth=2, **ringstyle)
ax.scatter(3.6, 3.6, s=900, edgecolor='black', linewidth=1, **ringstyle)
ax.scatter(3.6, 3.6, s=1100, edgecolor='white', linewidth=2, **ringstyle)

# plt.savefig('/content/drive/My Drive/pml/m0002_01.png')
plt.show()

解說:


-----

References


[1] Quick start guide — Matplotlib 3.6.2 documentation

https://matplotlib.org/stable/tutorials/introductory/quick_start.html


[2] Getting Started with Matplotlib

https://www.skytowner.com/explore/getting_started_with_matplotlib


[3] Matplotlib Tutorial - Learn How to Visualize Time Series Data With Matplotlib and InfluxDB | InfluxData

https://www.influxdata.com/blog/matplotlib-tutorial-visualize-time-series-data-matplotlib-influxdb/


[4] Matplotlib.pyplot.subplots() in Python - GeeksforGeeks

https://www.geeksforgeeks.org/matplotlib-pyplot-subplots-in-python/


[5] matplotlib.axes.Axes.text — Matplotlib 3.6.2 documentation

https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.text.html


[6] Matplotlib.axes.Axes.text() in Python - GeeksforGeeks

https://www.geeksforgeeks.org/matplotlib-axes-axes-text-in-python/


[7] Matplotlib的Anatomy of a figure復刻- 知乎

https://zhuanlan.zhihu.com/p/501009249

-----

Matplotlib(目錄)

https://mandhistory.blogspot.com/2022/02/matplotlib.html

-----

Python Machine Learning(目錄)

https://mandhistory.blogspot.com/2022/05/python.html

-----

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。