数据分析之scipy常用方法(五) (2)

线型图

#采用Series做法 import numpy as np import pandas as pd from pandas import Series,DataFrame import matplotlib.pyplot as plt np.random.seed(0) s = Series(np.random.randn(10).cumsum(),index = np.arange(0,100,10)) s.plot() plt.show(s.plot()) #DataFrame图标实例 np.random.seed(0) df = DataFrame(np.random.randn(10,4).cumsum(0), columns= ['A','B','C','D'], index = np.arange(0,100,10)) plt.show(df.plot())

柱状图

#水平与垂直柱状图Series fig,axes = plt.subplots(2,1) data = Series(np.random.rand(16),index = list('abcdefghijklmnop')) data.plot(kind = 'bar',ax = axes[0],color = 'b',alpha = 0.9) data.plot(kind = 'barh',ax = axes[1],color = 'b',alpha = 0.9) #DataFrame柱状图 df = DataFrame(np.random.rand(6,4), index = ['one','two','three','four','five','six'], columns = pd.Index(['A','B','C','D'],name = 'Genus')) plt.show(df.plot(kind = 'bar')) df = DataFrame(np.random.rand(6,4), index = ['one','two','three','four','five','six'], columns = pd.Index(['A','B','C','D'],name = 'Genus')) plt.show(df.plot(kind = 'bar',stacked = True))

直方图与密度图

a = np.random.random(10) b = a/a.sum() s = Series(b) plt.show(s.hist(bins = 100)) #bins直方图的柱数 #密度图 a = np.random.random(10) b = a/a.sum() s = Series(b) plt.show(s.plot(kind = 'kde'))

带有密度估计的规格化直方图

%matplotlib inline comp1 = np.random.normal(0,1,size = 200) comp2 = np.random.normal(10,2,size = 200) values = Series(np.concatenate([comp1,comp2])) p1 = values.hist(bins = 100,alpha = 0.3,color = 'k',density = True) p2 = values.plot(kind = 'kde',style = '--',color = 'r')

数据分析之scipy常用方法(五)

散布图

#简单的散布图 df = DataFrame(np.random.randint(0,100,size = 100).reshape(50,2),columns = ['A','B']) df.plot('A','B',kind = 'scatter',title = 'x Vs y')

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zygypj.html