3D bar graph with gradient Z values
30 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Michael Abboud
2017-8-28
编辑:Michael Abboud
2017-8-28
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 个评论
Michael Abboud
2017-8-29
编辑:Michael Abboud
2017-8-30
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!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete Data Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!