3D bar graph of Z with data in X Y Z array

Hello,
I am having difficulty creating a 3D bar graph. I have the data in X Y Z array and need a 3d bar graph for Z.

Respuestas (1)

Konrad
Konrad el 23 de Jul. de 2021
Hi,
provided that x and y are always positive integers, this may be a good start:
tab = readtable('XYZ_Data.txt');
zarray = zeros(max(tab.Y),max(tab.X)); % you could also use NaNs
lind = sub2ind(size(zarray),tab.Y,tab.X);
zarray(lind) = tab.Z;
bar3(zarray); % you may want to reverse the direction of your z-axis if z is always <0
Note that I assume that there is only 1 z-value per x- & y- coordinate.
Best, Konrad

7 comentarios

FNU Dhanraj
FNU Dhanraj el 23 de Jul. de 2021
Thanks Konrad for the help.
I was abbe to get the plot using the scriot you provided. Although there was one issue when running it. I get following error
Error: File: three_D_barPlot.m Line: 24 Column: 56
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
But when I run the commands one after another it works and I get the plot.
Konrad
Konrad el 26 de Jul. de 2021
Hi,
sounds like a syntax error. Please post your code.
FNU Dhanraj
FNU Dhanraj el 26 de Jul. de 2021
Thanks Conrad. here is the code
tab = readtable('XYZ_Data.txt');
zarray = zeros(max(tab.Y),max(tab.X)); % you could also use NaNs
lind = sub2ind(size(zarray),tab.Y,tab.X);
zarray(lind) = tab.Z;
b= bar3(zarray);
for k = 1:length(b)
zdata = b(k).ZData;
b(k).CData = zdata;
b(k).FaceColor = 'interp';
end
I am able to generate the following 3d Bar graph. I want to increase the size of those bars. Is there any way to do that. When I am trying to increase the width they are getting overlapped on each other.
Konrad
Konrad el 26 de Jul. de 2021
I'm not quite sure what you mean by 'increase size'? Scale z-value?
As you noticed, you cannot increase the width because bars have a fixed position and there is no space left in between bars. Try playing around with x-,y-,z-limits or think about a different plot-type; e.g. 2d color-coded?
FNU Dhanraj
FNU Dhanraj el 26 de Jul. de 2021
I want to increase the width of the Z bars like the following graph.
The main difference in this figure is that there are fewer bars visible. Constrain your x- and y-limit and your bars will look similar.
set(gca,'XLim',[60.5 75.5],'YLim',[60.5 75.5])
Best, K
FNU Dhanraj
FNU Dhanraj el 27 de Jul. de 2021
Thanks Konrad

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Productos

Versión

R2019b

Etiquetas

Preguntada:

el 23 de Jul. de 2021

Comentada:

el 27 de Jul. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by