除了plot,经常会用到还有scatter,这个会显示散点图,首先给大家说一下在 pandas 中有多少种方法 bar hist box kde area scatter hexbin
In [1]:
import pandas as pdimport numpy as npimport matplotlib.pyplot as plt
In [2]:
# 随机生成1000个数据df = pd.Series(np.random.randn(1000),index=np.arange(1000),name='d')df.plot()
Out[2]:
In [3]:
df = pd.DataFrame(np.random.randn(1000,4), index=np.arange(1000), columns=list("ABCD"))df = df.cumsum()df.plot()plt.show()
In [4]:
ax = df.plot.scatter(x='A',y='B',color='DarkBlue',label='Class1')df.plot.scatter(x='A',y='C',color='LightGreen',label='Class2',ax= ax)
Out[4]:
In [5]:
df = pd.DataFrame(np.random.randn(50,4), index=np.arange(50), columns=list("ABCD"))df.plot.bar(y='B',color='DarkBlue',label='Class1')
Out[5]:
In [6]:
df['A'].plot.hist()
Out[6]:
In [7]:
df['A'].plot.box()
Out[7]:
In [8]:
df['A'].plot.kde()
Out[8]:
In [9]:
df.plot.area(stacked=False)
Out[9]:
In [10]:
ax = df.plot.area(y='B',stacked=False)
In [11]:
ax = df.plot.hexbin(x='A', y='B', gridsize=20)