pandas plot参数

封装matplotlib的plot函数

  • pandas.plot

    DataFrame.plot(x=None, y=None, kind=‘line’, ax=None, subplots=False, sharex=None, sharey=False, layout=None, figsize=None, use_index=True, title=None, grid=None, legend=True, style=None, logx=False, logy=False, loglog=False, xticks=None, yticks=None, xlim=None, ylim=None, rot=None, fontsize=None, colormap=None, table=False, yerr=None, xerr=None, secondary_y=False, sort_columns=False, **kwds)

    • kind : str

      • ‘line’ : line plot (default)

      • ‘bar’ : vertical bar plot

      • ‘barh’ : horizontal bar plot

      • ‘hist’ : histogram

      • ‘box’ : boxplot

      • ‘kde’ : Kernel Density Estimation plot

      • ‘density’ : same as ‘kde’

      • ‘area’ : area plot

      • ‘pie’ : pie plot

      • ‘scatter’ : scatter plot

      • ‘hexbin’ : hexbin plot

    • alpha
      点的不透明度,当点的透明度很高时,单个点的颜色很浅。这样点越密集,对应区域颜色越深。通过颜色很浅就可以就看一看出数据的几种区域。alpha=0,无色,整个绘图区域无图,类似于[R, G, B, alpha]四通道中的alpha通道

      housing_copy.plot(kind="scatter", x='longitude', y='latitude', alpha=0.1)
      

      pandas plot参数_第1张图片

      housing_copy.plot(kind="scatter", x='longitude', y='latitude', alpha=1)
      

      pandas plot参数_第2张图片

    • s :注意此参数为kind="scatter"下才有的,否则会报错 unknown property
      各个点的大小,数值越大,对应点越大

      import matplotlib.pyplot as plt
      allDf = pd.DataFrame({
          'x':[0,1,2,4,7,6],
          'y':[0,3,2,4,5,7],
          's':[0,1,2,3,4,5],
          'c':['red','green','blue','red','green','blue']
      },index = ['p1','p2','p3','p4','p5','p6'])
      
      print(allDf) 
      
      allDf.plot(x='x', y='y', kind="scatter",s=allDf['s']*10 , label='s')
      plt.legend()
      

      pandas plot参数_第3张图片

    • c : 此参数也是kind="scatter"下才能用的,为每一点赋予颜色。
      建议用以下语句,只改变c就好。保留cmap和colorbar

        allDf = pd.DataFrame({
        		    'x':[0,1,2,4,7,6],
        		    'y':[0,3,2,4,5,7],
        		    's':[0,1,2,3,4,5],
        		    'c':[1,20, 5, 15, 25, 30]
        		    },index = ['p1','p2','p3','p4','p5','p6'])
        allDf.plot(x='x', y='y', kind="scatter",c='c',cmap=plt.get_cmap("jet"), colorbar=True)
      

      pandas plot参数_第4张图片
      利用c和s两个参数在图像上显示housing,其中点大小表示人口密度,颜色表示房屋价格多少。

        housing.plot(kind="scatter", x="longitude", y="latitude", alpha=0.3,
       								s=housing["population"]/100, label="population",
       								c="median_house_value", cmap=plt.get_cmap("jet"), colorbar=True,
       								)
       plt.legend()
      

      pandas plot参数_第5张图片

你可能感兴趣的:(Python数据处理及可视化)