简体   繁体   中英

plotting 3d bar plot in matlab

I have an Nx3 matrix in matlab 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(:, 1) % values of X-axis
data(:, 2) % values of Y-axis
data(:, 3) % values of each Z-axis bar

and there should be one bar for each 1:length(data)

How can I do this in MATLAB?

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? Ie instead of a bar for each point, just histogram the data into those bins in every dimension, and plot a bar for each bin.

thanks very much for your help.

Regarding your 1st question, you can achieve something similar to your request, by:

stem3 (data(:,1), data(:,2), data(:,3), 'marker', 'none', 'linewidth',10)

Not exactly bars, but produces a similar effect.

To plot 'real' bars (such as the ones bar3 plots), I think you'll have to use low-level graphics function such as surface (which is used by bar3 to plot bars).

Regarding your 2nd question, I'm not sure I understand --- if you calculate a histogram for each dimension, you end up with 4-dimensional data --- the bin location for each dimension + the hist count itself. What exactly do you want to plot?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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