Pandas-25.可视化
用matplotlib库的plot()方法实现简单的可视化
df = pd.DataFrame(np.random.randn(10,4),index=pd.date_range('2018/12/18', periods=10), columns=list('ABCD'))
print(df.plot())
默认绘图
- 日期类的索引,可以用
gct.autofmt_xdate()
来格式化x轴 - 用
x
和y
关键字来绘制一列和另一列 - 默认折线图,可以用
kind
参数指定以下图形:-
bar
或者barh
- 条形图 - `hist - 直方图
-
box
- 盒型图 -
area
- 面积图 -
scatter
- 散点图
-
条形图
- 有直接的
bar
方法绘制条形图 - 指定stacked=True为堆积条形图
- barh()方法绘制水平条形图
直方图
- 有
hist()
方法直接绘制直方图 -
bins
参数指定柱数 - 在DataFrame上调用分别为每列绘制不同的直方图
- 在DataFrame的plot上调用会在一个图上绘制整个DataFrame的图
箱形图
-
df.plot.box()
或者df.boxplot()
来绘制箱型图
面积图
- df.plot.area()绘制面积图
散点图
- df.plot.scatter()方法绘制散点图
饼状图
- df.plot.pie()方法绘制饼状图
- 要指定subplots或者y参数