1、绘制Series序列图
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
s1 = pd.Series(np.random.randn(100))
s1.plot()
plt.show()
s1 = pd.Series(np.random.randn(100))
#style设置线性风格,k表示黑色,o表示圆圈,--表示虚线
s1.plot(style='ko--',alpha=0.5,grid=True,label='s1',
title='Plot for 100 Random Data from Standard Normal Distribution')
plt.legend()
plt.show()
2、绘制DataFrame图表
df = pd.DataFrame(np.random.randn(10,3).cumsum(0),columns=['One','Two','Three'])#cumsum表示累加
#生成一个含有3列标准正态分布随机数累加值的DataFrame数据表
df.plot()
plt.show()
df = pd.DataFrame(np.random.randn(10,3).cumsum(0),columns=['One','Two','Three'])
df.plot(kind='bar')#kind设置图表的类型
#柱状图(bar),直方图(hist),箱线图(box),饼图(pie),散点图(scatter),密度图(density)
plt.show()
df = pd.DataFrame(np.random.randn(10,3).cumsum(0),columns=['One','Two','Three'])
df.plot(kind='bar',stacked=True)#堆叠柱状图
plt.show()
用juoyter notebook一步一步实现的,做一个笔记,参考了图书馆的书
这里是引用
《Python3快速入门与实战》