首页 > 其他 > 详细

matplot画图详解

时间:2019-05-08 13:47:20      阅读:313      评论:0      收藏:0      [点我收藏+]

所有的图的画法见https://matplotlib.org/ 官网,里面有各种图的示例。

1、直方图绘图:

plt.hist:

参数设置:

x: 指定每个bin(箱子)分布的数据,对应x轴

bins: (num_bins) 总共有几条条状图

color:颜色

density:如果为True,则返回元组的第一个元素将是规范化以形成概率密度的计数,即直方图下的面积(或积分)将总和为1.这是通过将计数除以观察次数来实现的。

    # example data  
    mu = 100 # mean of distribution  
    sigma = 15 # standard deviation of distribution  
    x = mu + sigma * np.random.randn(10000)  #生成均值是100方差是15的数据,作为x轴
      
    num_bins = 50  # 条状图的个数
    # the histogram of the data  
    n, bins, patches = plt.hist(x, num_bins, normed=1, facecolor=blue, alpha=0.5)  
    # add a ‘best fit‘ line  
    y = mlab.normpdf(bins, mu, sigma)  
    plt.plot(bins, y, r--)  #画出分布曲线
    plt.xlabel(Smarts)  
    plt.ylabel(Probability)  
    plt.title(rHistogram of IQ: $\mu=100$, $\sigma=15$)  

 

matplot画图详解

原文:https://www.cnblogs.com/yanxingang/p/10831282.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!