【Python】绘图和可视化

可视化工具:matplotlib

matplotlib API

import matplotlib.pyplot as plt

Figure和Subplot

fig = plt.figure() # 创建新的figure
ax1 = fig.add_subplot(2,2,1)
ax2 = fig.add_subplot(2,2,2)
ax3 = fig.add_subplot(2,2,3)
# 结果就是带有三个subplot的figure
from numpy.random import randn
plt.plot(randn(50).cumsum(),'k--')
# 会在最后一个subplot中绘制
ax1.hist(randn(100), bins=20, color='k', alpha=0.3) # 直方图
ax2.scatter(np.arrange(30), np.arrange(30)+3*randn(30)) # 散点图

pands绘图函数

线型图
Series和DataFrame都有plot方法,默认生成线型图。
s = Series(np.random.randn(10).comsum(), index=np.arrange(0, 100, 10))
注意:
该对象的索引会被传给matplotlib,并绘制x轴,可以通过use_index=Fales禁用。
x,y轴的刻度和界限可以通过xticks(yticks)和xlim(ylim)选项进行调节。
这里写图片描述
这里写图片描述

df = DataFrame(np.random.randn(10,4).cumsum(0),\
        colums=['A','B','C','D'],index=np.arange(0,100,10))

这里写图片描述

猜你喜欢

转载自blog.csdn.net/alvin93/article/details/81408818