Numpy是Python开源的数值计算扩展，可用来存储和处理大型矩阵，比Python自身数据结构要高效；

matplotlib是一个Python的图像框架，使用其绘制出来的图形效果和MATLAB下绘制的图形类似。

pip install numpypip install matplotlib

### 生成直方图

import numpy as npfrom pylab import *num=100sigma=20x=num+sigma*np.random.randn(20000)                    #样本数量plt.hist(x,bins=100,color="green",normed=True)        #bins显示有几个直方,normed是否对数据进行标准化plt.show()                                            #显示图像plt.savefig()                                         #保存图片

### 生成条形图

import numpy as npfrom pylab import *value=[22,13,34]index=["root","admin","lyshark"]#index=np.arange(5)plt.bar(left=index,height=value,color="green",width=0.5)plt.show()

运行结果：

### 生成折线图

import numpy as npfrom pylab import *x=np.linspace(-10,10,100)y=x**3plt.plot(x,y,linestyle="--",color="green",marker="<")plt.show()

运行结果：

### 生成散点图

import numpy as npfrom pylab import *x=np.random.randn(1000)y=x+np.random.randn(1000)*0.5plt.scatter(x,y,s=5,marker="<")            #s表示面积  Marker表示图形plt.show()

### 生成饼状图

import numpy as npfrom pylab import * labels="cangjingkong","jizemingbu","boduoyejieyi","xiaozemaliya"fracs=[45,10,30,15]plt.axes(aspect=1)explode=[0,0.05,0,0]plt.pie(x=fracs,labels=labels,autopct="%0f%%",explode=explode)plt.show()

### 生成箱形图

import numpy as npfrom pylab import *np.random.seed(100)data=np.random.normal(size=(1000,4),loc=0,scale=1)labels=["A","B","C","D"]plt.boxplot(data,labels=labels)plt.show()

### 生成多个图例

import numpy as npfrom pylab import *x=np.arange(1,11,1)          plt.plot(x,x*2)          plt.plot(x,x*3)          plt.plot(x,x*4)      plt.legend(["BoDuoYeJieYi","CangJingKong","JiaTengYing"])          plt.show()

import numpy as npfrom pylab import *mpl.rcParams['font.sans-serif'] = ['KaiTi']label = "windows xp","windows 7","Windows 8","Linux 4","Centos 6","Huawei交换机"fracs = [1,2,3,4,5,1]plt.axes(aspect=1)plt.pie(x=fracs,labels=label,autopct="%0d%%")plt.show()