zoukankan      html  css  js  c++  java
  • pandas中的绘图函数

     
    import matplotlib.pyplot as plt
    import pandas as pd
    import numpy as np
    from pandas import Series, DataFrame
    
    # 线形图
    s = Series(np.random.randn(10).cumsum(),index=np.arange(0,100,10)).plot()
    df = DataFrame(np.random.randn(10,4).cumsum(0),columns=['A','B','C','D'],index=np.arange(0,100,10)).plot()

    # 柱状图
    fig,axes = plt.subplots(2,1)
    data = Series(np.random.randn(16),index=list('abcdefghijklmnop'))
    data.plot(kind='bar',ax=axes[0],color='g',alpha=0.7)
    data.plot(kind='barh',ax=axes[1],color='b',alpha=0.7)
    
    # rand [0, 1)
    df = DataFrame(np.random.rand(6,4),
                   index=['one','two','three','four','five','six'],
                   columns=pd.Index(['A','B','C','D'],name='name'))
    df.plot(kind='barh',alpha=0.5)
    df.plot(kind='barh',stacked=True,alpha=0.5) # stacked=True 每行值堆积在一起

    # 直方图和密度图
    comp1 = np.random.normal(0,1,size=200)
    comp2 = np.random.normal(10,2,size=200)
    values = Series(np.concatenate([comp1,comp2]))
    #values.hist(bins=100,alpha=0.3,color='g',density=True)
    values.hist(bins=100,alpha=0.3,color='g',density=True,stacked=True)
    values.plot(kind='kde',style='k--',alpha=0.3)

    # 散布图
    macro = pd.read_csv('macrodata.csv')
    data = macro[['cpi','m1','tbilrate','unemp']]
    trans_data = np.log(data).diff().dropna()
    
    plt.scatter(trans_data['m1'],trans_data['unemp'])
    plt.title('Change in log %s vs. log %s' %('m1','unemp'))
    
    pd.plotting.scatter_matrix(trans_data,diagonal='kde',color='b',alpha=0.3)

  • 相关阅读:
    hdu 1305 Immediate Decodability
    hdu1247 Hat’s Words
    hdu 1251 统计难题 前缀出现次数
    hdu 3308 线段树,单点更新 求最长连续上升序列长度
    java内部类
    Fckeditor编辑器的安全问题
    Net-NTLMv1的利用
    redis提权
    windows认证过程
    c/c++中system函数在Linux和windows下区别
  • 原文地址:https://www.cnblogs.com/nicole-zhang/p/15214441.html
Copyright © 2011-2022 走看看