繁体   English   中英

我可以在3d中绘制几个直方图吗?

[英]Can I plot several histograms in 3d?

我想绘制几个直方图,类似于绘制这些条形图的方式。 我已经尝试过使用hist返回的数组,但似乎返回了bin边缘,所以我不能在bar使用它们。

有没有人有什么建议?

如果使用np.histogram预先计算直方图,就会发现你将获得hist数组和bin 边缘 plt.bar期望bin中心,所以计算它们:

xs = (bins[:-1] + bins[1:])/2

要适应Matplotlib示例:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
nbins = 50
for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]):
    ys = np.random.normal(loc=10, scale=10, size=2000)

    hist, bins = np.histogram(ys, bins=nbins)
    xs = (bins[:-1] + bins[1:])/2

    ax.bar(xs, hist, zs=z, zdir='y', color=c, ec=c, alpha=0.8)

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

plt.show()

在此输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM