colormap does not work on histogram2

조회 수: 5 (최근 30일)
Sean
Sean 2023년 2월 10일
답변: Star Strider 2023년 2월 10일
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.

채택된 답변

Star Strider
Star Strider 2023년 2월 10일
That is not possible with histogram2, however it is with histcounts2 and bar3
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개)

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by