在python matplotlib中绘制3d直方图/条形图 [英] plotting 3d histogram/barplot in python matplotlib

查看:106
本文介绍了在python matplotlib中绘制3d直方图/条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在scipy/numpy中有一个Nx3矩阵,我想制作一个3维条形图,其中X轴和Y轴由矩阵的第一列和第二列的值确定,高度每个条形图的第一个是矩阵中的第三列,条形数由N确定.

I have an Nx3 matrix in scipy/numpy and I'd like to make a 3 dimensional bar graph out of it, where the X and Y axes are determined by the values of first and second columns of the matrix, the height of each bar is the third column in the matrix, and the number of bars is determined by N.

换句话说,如果数据"是矩阵,则:

In other words, if "data" is the matrix then:

data[:, 0] # values of X-axis
data[:, 1] # values of Y-axis
data[:, 2] # values of each Z-axis bar

每个len(数据)应该有一个小节

and there should be one bar for each len(data)

如何在Matplotlib中做到这一点?

How can I do this in Matplotlib?

第二,作为此方法的一种变体,我该如何做同样的事情,但是这次直方图将条形图分成每个X,Y,Z维度中的N个面元? IE.代替每个点的条形图,只需将数据直方图绘制到每个维度的那些箱中,然后为每个箱形图绘制一条条形图.

Secondly, as a variant of this, how can I do the same thing, but this time histogram the bars into N bins in each X, Y, Z dimension? I.e. instead of a bar for each point, just histogram the data into those bins in every dimension, and plot a bar for each bin.

非常感谢您的帮助.

推荐答案

这是3D条形图的一个示例. 这里是另一个.

Numpy具有一个名为 histogram2d histogram2d 进行所需的矩形装仓.

Numpy has a function called histogram2d to do the rectangular binning you want.

这篇关于在python matplotlib中绘制3d直方图/条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆