-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.py
64 lines (49 loc) · 1.41 KB
/
plot.py
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
57
58
59
60
61
62
63
64
# -*- coding: utf-8 -*-
'''
@program: Plot.py
@description: 基础绘图
@author: doubleZ
@create: 2020/02/09
'''
from matplotlib.pyplot import *
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
mpl.rcParams['axes.unicode_minus'] = False # 解决汉字乱码
mpl.rcParams['font.family'] = 'sans-serif' # 负号正常显示
mpl.rcParams['font.sans-serif'] = [u'SimHei']
def drawCurve():
x = np.arange(-np.pi, np.pi, .1)
y = np.sin(x)
y1 = np.cos(x)
plt.plot(x, y, color='r', linewidth=2.0, linestyle='--', label='sin')
plt.plot(x, y1, color='b', label='cos')
plt.grid(True)
plt.xlim(-5, 5)
plt.ylim(-2, 2)
plt.xlabel('x')
plt.ylabel('y=sin(x)')
plt.title('figure of sin')
xticks(np.linspace(-np.pi, np.pi, 5))
legend()
plt.show()
def drawPie():
data = np.random.randint(1,11,5)
plt.pie(data, explode=[0,0,0.2,0,0])
plt.show()
def drawScatter():
n = 100
x, y = np.random.normal(0,1,n), np.random.normal(0,1,n)
plt.scatter(x,y,marker='v')
plt.show()
def drawBar():
plt.bar(x=(0,1,2),height=(1,0.5,0.8),width=0.3,align='center')
plt.show()
def drawBar_with_Curve():
data = np.random.randint(1, 10, 5)
x = np.arange(len(data))
plt.plot(x, data, color='r')
plt.bar(x, data, alpha=.5, color='b', width=0.2, align='center')
plt.show()
if __name__ == '__main__':
drawBar_with_Curve()