colormap does not work on histogram2

3 visualizaciones (últimos 30 días)
Sean
Sean el 10 de Feb. de 2023
Respondida: Star Strider el 10 de Feb. de 2023
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.

Respuesta aceptada

Star Strider
Star Strider el 10 de Feb. de 2023
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
.

Más respuestas (0)

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by