-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatplotlib.py
More file actions
92 lines (84 loc) · 1.92 KB
/
Copy pathMatplotlib.py
File metadata and controls
92 lines (84 loc) · 1.92 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
print (mpl.matplotlib_fname())
from matplotlib.font_manager import _rebuild
_rebuild()
# from matplotlib import font_manager
# a = sorted([f.name for f in font_manager.fontManager.ttflist])
# for i in a:
# print(i)
#
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.titlecolor'] = 'r'
plt.rcParams['axes.unicode_minus'] = False
plt.rcParams['lines.linewidth'] = 5
plt.rcParams['lines.color'] = 'red'
plt.rcParams['lines.linestyle'] = '--'
x = [1,2]
y = [-3,4]
plt.title('中文标题')
plt.plot(x,y)
plt.show()
# 直方图
height = [165,158,182,170,161,155,173,176,181,190,172,163,170]
bins = range(150,200,5)
plt.hist(height, bins=bins)
plt.show()
# 条形图
classes = ['class1','class2','class3']
scores = [70,60,80]
plt.bar(classes, scores)
plt.show()
# 折线图
height = [165,158,182,170,161,155,173,176,181,190,172,163,170,178,183]
year = range(2005,2020)
plt.plot(year, height)
plt.show()
# 饼图
labels = ['房贷','饮食','出行','教育']
money = [8000,2000,2000,3000]
plt.pie(money, labels=labels, autopct='%1.1f%%')
plt.show()
# 散点图
f = open('/Users/mingyuexu/PycharmProjects/demo/learning/media_0731.csv', mode ='r')
R = []
R1 = []
X1 = []
TS = []
X = []
Y = []
n = 0
for line in f.readlines():
R = str.split(line, sep=',')
n = n + 1
if n != 1:
R1 = R[1:]
# print(R1)
X1.append(R1)
TS = np.array(X1)
TS = np.sort(TS,axis=0)
# print(TS)
X = TS[:,0]
Y = TS[:,-1]
# print(X)
f.close()
plt.scatter(X,Y,color='r')
plt.title('发文数与PDI的关系')
plt.xlabel('发文数')
plt.ylabel('PDI')
plt.show()
# 分图
fig = plt.figure()
fig.add_subplot(3,3,1)
n = 128
XX = np.random.normal(0,1,n)
YY = np.random.normal(0,1,n)
ARC = np.arctan2(YY,XX)
plt.scatter(XX,YY,s=75,c=ARC,alpha=0.5)
plt.xlim(-1.5,1.5), plt.xticks([])
plt.ylim(-1.5,1.5), plt.yticks([])
plt.axis()
plt.xlabel('x')
plt.ylabel('y')
plt.show()