forked from shenxiangzhuang/PythonDataAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMmatplotlib.py
More file actions
executable file
·56 lines (42 loc) · 1.01 KB
/
Copy pathMmatplotlib.py
File metadata and controls
executable file
·56 lines (42 loc) · 1.01 KB
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
46
47
48
49
50
51
52
53
54
55
56
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# 基本使用
'''
x = np.linspace(-2, 2, 100)
y1 = np.cos(np.pi * x)
y2 = np.sin(np.pi * x)
plt.plot(x, y1, 'go', label=r"$y1=\cos(\pi \times x)$", alpha=0.8, linewidth=0.7)
plt.plot(x, y2, 'r-', label=r"$y2=\sin(\pi \times x)$", alpha=0.8, linewidth=0.7)
plt.annotate("Important Point", (0, 1), xytext=(-1.5, 1.1),
arrowprops=dict(arrowstyle='->'))
plt.xlabel('x-axis')
plt.ylabel('y-axis')
# 设置座标范围[xmin, xmax, ymin, ymax]
plt.axis([-2.1, 2.1, -1.2, 1.2])
# 显示标签
plt.legend()
# 显示网格
plt.grid(alpha=0.4)
plt.title("Two plots", color=(0.1, 0.3, 0.5))
plt.show()
'''
# 进阶使用
'''
# 绘制子图[subplot]
plt.style.use('ggplot') # 设置绘图风格
x = np.linspace(-2, 2, 100)
y1 = np.sin(np.pi * x)
y2 = np.cos(np.pi * x)
y3 = np.tan(np.pi * x)
y4 = x
plt.subplot(221)
plt.plot(x, y1)
plt.subplot(222)
plt.plot(x, y2)
plt.subplot(223)
plt.plot(x, y3)
plt.subplot(224)
plt.plot(x, y4)
plt.show()
'''