How to plot 3D bar graph?

17 views (last 30 days)
Stephen
Stephen on 26 Jun 2019
Commented: Stephen on 26 Jun 2019
I've searched but can't find the solution on how to plot the following as a 3D graph. I have a matrix of x,y,z values, e.g.:
Capture.JPG
I want to generate a 3D plot in all 3 dimensions, with y as the height of the bar and z as the width, such as the following (not drawn to scale...I just kluged it together in powerpoint):
Capture.JPG
How do I do this? none of the following worked:
bar3(x,y,z)
bar3(z)
bar3(x,y)
bar3(y,z)

Answers (2)

sourav  malla
sourav malla on 26 Jun 2019
You can find the details in the documentation here:-
  1 Comment
Stephen
Stephen on 26 Jun 2019
nah, tried that. I can't find any answer on that page

Sign in to comment.


KALYAN ACHARJYA
KALYAN ACHARJYA on 26 Jun 2019
Edited: KALYAN ACHARJYA on 26 Jun 2019
You can use this custom function
scatterbar3(x,y,z,0.5)
grid on
For example
x=1:10;
y=2:2:20;
z=3:3:30;
scatterbar3(x,y,z,0.5)
grid on
99.png
  1 Comment
Stephen
Stephen on 26 Jun 2019
Thanks, Kalyan! Close, but no banana. For instance, for the following matrix:
1 1.00 3.43
2 1.00 3.24
3 1.00 3.20
4 0.91 3.15
5 0.69 3.07
6 1.00 2.82
7 1.00 2.76
8 1.00 2.62
9 1.00 2.61
10 0.68 2.55
I ran the following:
x=matrix(:,1);
y=matrix(:,2);
z=matrix(:,3);
scatterbar3(x,y,z,1)
I get this fig (ignore the colors, I'll fix that later):Capture.JPG
The z dimension (0.0 to 3.0) is accurate (the height of each bar), and the x sequence (1 to 10) is shown correctly, but the widths of the bars, y, are all fixed (=1). I need the "base" of all the bars to start at y=0 and the bar's width extend up to the corresponding value of y for each entry. In short, the width should = y, not a constant.
Any ideas?

Sign in to comment.

Products


Release

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!