【问题标题】:how to scale the histogram plot via matplotlib如何通过 matplotlib 缩放直方图
【发布时间】:2014-06-23 15:39:28
【问题描述】:

您可以看到下面有直方图。
它就像 pl.hist(data1,bins=20,color='green',histtype="step",cumulative=-1)
如何缩放直方图?
例如,让直方图的高度为现在的三分之一。

另外,是去掉左边竖线的方法吗?

【问题讨论】:

    标签: python matplotlib histogram


    【解决方案1】:

    matplotlib hist 实际上只是调用其他一些函数。直接使用这些通常更容易,您可以直接检查数据并对其进行修改:

    # Generate some data
    data = np.random.normal(size=1000)
    
    # Generate the histogram data directly
    hist, bin_edges = np.histogram(data, bins=10)
    
    # Get the reversed cumulative sum
    hist_neg_cumulative = [np.sum(hist[i:]) for i in range(len(hist))]
    
    # Get the cin centres rather than the edges
    bin_centers = (bin_edges[:-1] + bin_edges[1:]) / 2.
    
    # Plot
    plt.step(bin_centers, hist_neg_cumulative)
    
    plt.show()
    

    hist_neg_cumulative 是正在绘制的数据数组。因此,在将其传递给绘图函数之前,您可以根据需要重新缩放。这也不会绘制垂直线。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-29
      • 2021-02-19
      • 1970-01-01
      • 2017-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-26
      相关资源
      最近更新 更多