【问题标题】:Using Hist function to build series of 1D histograms in Python 3d plot使用 Hist 函数在 Python 3d 图中构建一系列 1D 直方图
【发布时间】:2011-05-16 23:34:55
【问题描述】:

我正在使用 pythons hist 函数来生成 1d 直方图,每个直方图都链接到给定的实验。 现在我了解到 Hist 函数允许在同一个 x 轴上绘制多个直方图以进行比较。我通常为此目的使用类似于以下内容的东西,结果是一个非常好的图,其中 x1、x2 和 x3 定义如下 x1 = 长度 expt1 x2 = 长度 expt2 x3 = 长度 expt3

P.figure()
n, bins, patches = P.hist( [x0,x1,x2], 10, weights=[w0, w1, w2], histtype='bar')
P.show()

我希望尝试实现 3d 效果,因此我问任何人知道是否可以通过给定的单位使每个唯一的直方图在 y 平面上从另一个偏移,从而产生 3d 效果。

我将不胜感激这方面的任何帮助。

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    我相信你只是想要matplotlib.pyplot.bar3d。

    import numpy as np
    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    
    x0, x1, x2 = [np.random.normal(loc=loc, size=100) for loc in [1, 2, 3]]
    
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    
    yspacing = 1
    for i, measurement in enumerate([x0, x1, x2]):
        hist, bin_edges = np.histogram(measurement, bins=10)
        dx = np.diff(bin_edges)
        dy = np.ones_like(hist)
        y = i * (1 + yspacing) * np.ones_like(hist)
        z = np.zeros_like(hist)
        ax.bar3d(bin_edges[:-1], y, z, dx, dy, hist, color='b', 
                zsort='average', alpha=0.5)
    
    plt.show()
    

    【讨论】:

      【解决方案2】:

      【讨论】:

      • 嗨,J,是的,我一直在检查页面。
      • 本教程似乎完全忽略了 hist 的功能
      • Python 中的 Hist 函数对于定义我的数据的分箱很有用。
      猜你喜欢
      • 1970-01-01
      • 2022-01-10
      • 2020-01-05
      • 1970-01-01
      • 2017-03-12
      • 2013-10-12
      • 2014-04-18
      • 1970-01-01
      相关资源
      最近更新 更多