2022年12月6日 星期二

Python Matplotlib(一)基本元件

Python Matplotlib(一)基本元件

2022/11/22

-----


Fig. 1.1. Basic components of Matplotlib.

-----

代碼 m1.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
36
37
38
39
40
41
42
43
44
45
# Program m1.1:Basic components of Matplotlib
import matplotlib as mpl
import matplotlib.pyplot as plt

mpl.rcParams['font.size'] = 80
fig = plt.figure(figsize=(16, 16))
ax = fig.add_subplot(111)

# figure
ax.plot([0, 0], [0, 100], 'b')       # left, [x1, x2], [y1, y2]
ax.plot([100, 100], [0, 100], 'b')   # right
ax.plot([0, 100], [0, 0], 'b')       # bottom

ax.plot([0, 30], [100, 100], 'b')    # top left
ax.plot([70, 100], [100, 100], 'b')  # top right
ax.text(35, 98, "Figure", color='b')

# axes 1
ax.plot([10, 10], [60, 90], 'r')     # left
ax.plot([90, 90], [60, 90], 'r')     # right
ax.plot([10, 90], [60, 60], 'r')     # bottom

ax.plot([10, 35], [90, 90], 'r')     # top left
ax.plot([65, 90], [90, 90], 'r')     # top right
ax.text(39, 85, "Axes", color='r')

# axes 2
ax.plot([10, 10], [10, 50], 'r')     # left
ax.plot([90, 90], [10, 50], 'r')     # right
ax.plot([10, 90], [10, 10], 'r')     # bottom

ax.plot([10, 35], [50, 50], 'r')     # top left
ax.plot([65, 90], [50, 50], 'r')     # top right
ax.text(39, 47, "Axes", color='r')

# axis
ax.plot([15, 85], [20, 20], 'g')     # x axis
ax.plot([20, 20], [15, 45], 'g')     # y axis
ax.text(70, 25, "x Axis", fontsize=30, color='g')
ax.text(25, 40, "y Axis", fontsize=30, color='g')

ax.set_axis_off()

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

解說:


-----

# figure axes axis

[1] Getting Started with Matplotlib

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


# rectangle

[2] How to Draw Rectangles in Matplotlib (With Examples)

https://www.statology.org/matplotlib-rectangle/

-----

Matplotlib(目錄)

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

-----

Python Machine Learning(目錄)

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

-----

沒有留言:

張貼留言

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