![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/177996/image.png)
3D bar graph with gradient Z values
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm trying to make a 3D bar graph from a 3-column matix (let's call the columns x-y-z). For any x-y combo, there are multiple z values (sort of like a stacked 3D bar graph). I want to make a plot where the Z values are a gradient, instead of discrete stacks.
Here's an example from different software... I'm having trouble replicating it. I'd like to be able to replicate it and preferably have the vertical colors be a gradient.
Thanks for any help, and apologies if this solution is out there and I have simply missed it.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/166871/image.jpeg)
0 comentarios
Respuestas (1)
Michael Abboud
el 28 de Ag. de 2017
Editada: Michael Abboud
el 28 de Ag. de 2017
Hi Alex,
If I've understood your question correctly, I believe the following link should provide the solution. Essentially you can accomplish this in 3 steps:
1. Use the 'bar3' function to create a 3-D bar graph
Then for each 'surface' element of the returned object (AKA for each row of bars):
2. Set the 'CData' property equal to the current 'ZData'
3. Set the 'FaceColor' property to 'interp'
From here you can adjust the colormap as for whatever scheme you'd like.
Reference:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/177996/image.png)
3 comentarios
Michael Abboud
el 29 de Ag. de 2017
Editada: Michael Abboud
el 30 de Ag. de 2017
Hi Alex, thanks for providing more information.
It looks like the primary issue is transforming your data from [x,y,z] format, to more of an 'image' format, where the (x,y) location in your matrix contains a value 'z'. Consider:
data3 = zeros(max(x),max(y));
for i = 1:length(x)
xx = x(i); yy = y(i); zz = z(i);
if zz > data3(xx,yy)
data3(xx,yy) = zz;
end
end
Note that I'm only taking the largest Z since there are many duplicate points. Also I've found in some cases, using an ">> axis tight" greatly helps the appearance after plotting.
Using the provided data and copying the example from my answer, it should look something like this before any further modifications. Hope this helps!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/186686/image.jpeg)
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!