3D bar graph with gradient Z values
28 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposte (1)
Michael Abboud
il 28 Ago 2017
Modificato: Michael Abboud
il 28 Ago 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:
3 Commenti
Michael Abboud
il 29 Ago 2017
Modificato: Michael Abboud
il 30 Ago 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!
Vedere anche
Categorie
Scopri di più su Discrete Data Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!