【问题标题】:Plotting a probability distribution using matplotlib使用 matplotlib 绘制概率分布
【发布时间】:2017-06-10 02:31:53
【问题描述】:

我想绘制神经网络分类任务的 softmax 概率,类似于下图

但是,我在SOmatplotlib 的文档页面上找到的大部分代码都使用直方图。

例子:

plotting histograms whose bar heights sum to 1 in matplotlib

Python: matplotlib - probability mass function as histogram

http://matplotlib.org/gallery.html

但它们都不符合我在该情节中想要实现的目标。非常感谢代码和示例图。

【问题讨论】:

    标签: python matplotlib softmax


    【解决方案1】:

    我猜你只是在寻找不同的情节类型。改编自here

    # Import 
    import numpy as np
    import matplotlib.pyplot as plt
    
    # Generate random normally distributed data
    data=np.random.randn(10000)
    
    # Histogram
    heights,bins = np.histogram(data,bins=50)
    
    # Normalize
    heights = heights/float(sum(heights))
    binMids=bins[:-1]+np.diff(bins)/2.
    plt.plot(binMids,heights)
    

    这会产生这样的结果:

    希望这就是你想要的。

    【讨论】:

      猜你喜欢
      • 2014-10-23
      • 1970-01-01
      • 1970-01-01
      • 2022-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-06
      相关资源
      最近更新 更多