3-matplotlib笔记
程序员文章站
2022-03-01 21:41:45
...
1 1-4-1-折线图
2 import pandas as pd
3 import matplotlib.pyplot as plt
4 unrate=pd.read_csv("D:/MachineData/week1/train.csv")
5 print(unrate.head(12))
6 first_twelve=unrate[0:12]
7 plt.plot(first_twelve['MSSubClass'],first_twelve['LotFrontage'])
8 plt.xticks(rotation=45)#x轴坐标旋转45度
9 plt.xlabel("MSSubClass")#x轴含义
10 plt.ylabel("LotFrontage")#Y轴含义
11 plt.title("MSSubClass&&LotFrontage")#折线图标题
12 plt.show()
13
14
15 1-4-3条形图
16 import matplotlib.pyplot as plt
17 from numpy import arange
18 fig=plt.figure(figsize=(5,10))
19 ax=fig.add_subplot(2,1,1)#绘制子图
20 num_cols=['MSSubClass','LotFrontage','LotArea','SalePrice','MSSubClass']
21 bar_heights=norm_reviews.ix[0,num_cols].values#条形图平均高度
22 print(bar_heights)
23 bar_positions=arange(5)+0.75#条形图横轴间距设置
24 print(bar_positions)
25 fig.ax=plt.subplots()
26 ax.bar(bar_positions,bar_heights,0.3)
27 plt.show()
28
29
30 import matplotlib.pyplot as plt
31 from numpy import arange
32 fig=plt.figure(figsize=(5,10))
33 ax=fig.add_subplot(2,1,1)#创建2行1列的矩阵格式,取第一个
34 num_cols=['MSSubClass','LotFrontage','LotArea','SalePrice','MSSubClass']
35 bar_heights=norm_reviews.ix[0,num_cols].values#条形图平均高度
36 print(bar_heights)
37 bar_positions=arange(5)+0.75#条形图横轴间距设置
38 print(bar_positions)
39 fig.ax=plt.subplots()
40 ax.bar(bar_positions,bar_heights,0.3)
41 plt.show()
42
43 fig.ax=plt.subplots()#绘制子图
44 reviews=pd.read_csv("D:/MachineData/week1/train.csv")
45 print(reviews[0:10])
46 cols=['MSSubClass','LotFrontage','LotArea','Street','LotShape']
47 norm_reviews=reviews[cols]
48 ax.scatter(norm_reviews['MSSubClass'],norm_reviews['LotFrontage'])
49 ax.set_xlabel('MSSubClass')
50 ax.setylabel('LotFrontage')
51 plt.show()
52
53
54 ax.setylim(0,50)#设置y轴区间
55 fig.ax=plt.subplot()
56 ax.boxplot(norm_reviews['MSSubClass'])#绘制盒图
57 ax.setylim(0,5)
58 plit.show()
上一篇: Pytorch读取图片并显示
下一篇: GDAL的使用简介