36.Pandas绘图操作

%matplotlib inline
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
#绘制折线图
s = pd.Series(np.random.randn(10),index=np.arange(0,100,10))
s.plot()
<matplotlib.axes._subplots.AxesSubplot at 0xae43e10>

#cumsum(axis),前面元素的累加和
df = pd.DataFrame(np.random.randn(10,4).cumsum(0),index = np.arange(0,100,10),columns=['A',"B","C","D"])
df.plot()
<matplotlib.axes._subplots.AxesSubplot at 0x8c85518>

 

#绘制柱状图
data = pd.Series(np.random.randn(16),index=list('abcdefghijklmnop'))
#两行一列的子图
fig,axes = plt.subplots(2,1)
#ax为图表显示的位置,kind为bar,柱状图
data.plot(ax=axes[0],kind='bar')
#kind为barh,横向柱状图
data.plot(ax=axes[1],kind='barh')
<matplotlib.axes._subplots.AxesSubplot at 0xa34b518>

df = pd.DataFrame(np.random.rand(6,4),index=['one','two','three','four','five','six'],columns=pd.Index(['A','B','C','D'],name="Genus"))
#绘制柱状图
df.plot(kind='bar')
<matplotlib.axes._subplots.AxesSubplot at 0xa45e5c0>

#绘制直方图
df.A.plot(kind='hist',bins=50)

#散点图
df.plot.scatter('A','B')

 

#混合散点图,数据维度越大,越复杂
pd.plotting.scatter_matrix(df,color='g',alpha=0.3)
array([[<matplotlib.axes._subplots.AxesSubplot object at 0x000000000AA338D0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000000AA685C0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000000AA89B00>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000000AABB1D0>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x000000000AAE2860>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000000AAE2898>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000000AB3D5C0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000000AB63C50>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x000000000AB96320>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000000ABBD9B0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000000ABF1080>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000000AC17710>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x000000000AC41DA0>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000000AC72438>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000000AC99AC8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000000ACCC198>]],
      dtype=object)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值