colormap does not work on histogram2
3 views (last 30 days)
Show older comments
Hello, I have created a custom colormap which is just turbo but with more indices, and the first entry is white.
cmapturbo=turbo(25600);
cmapturbo(1, 1) = 1;
cmapturbo(1, 2) = 1;
cmapturbo(1, 3) = 1;
I try to implement this custom colormap to a histogram2:
histogram2(x, y, [10, 10], 'normalization', 'probability', 'DisplayStyle','bar3', 'FaceColor','flat')
colorbar
colormap(cmapturbo)
However, it results in a figure as shown in histogram2.jpg. I am hoping to make it so that it can look like something in hist3.jpg.
The reason why I am not using hist3 to graph my data is because hist3 does not support graphing the frequency as a probability.
Thank you.
0 Comments
Accepted Answer
Star Strider
on 10 Feb 2023
X = randn(1000,1);
Y = randn(1000,1);
[N,XEdges,YEdges] = histcounts2(X,Y,[10 10]);
XCntrs = XEdges(1:end-1) + diff(XEdges/2);
YCntrs = YEdges(1:end-1) + diff(YEdges/2);
figure
hb3 = bar3(N);
colormap(turbo)
for k = 1:numel(hb3)
zdata = hb3(k).ZData;
hb3(k).CData = zdata;
hb3(k).FaceColor = 'interp';
end
.
0 Comments
More Answers (0)
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!