- bar3 does not have an x input. Solution is to adjust the x values after plotting.
- the y input to bar3 defines the center of each bin, not the edge. Solution is to compute the centers.
- defining colors to individual bars might be tricky since a handle is returned for each row along the x axis
How can i change color of a specific bin using histogram2 or anything similar
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
daniel mitchell
am 26 Mär. 2023
Kommentiert: Adam Danz
am 27 Mär. 2023
suppose i have some data which i want to cluster into 3D histogram
x = 100*randn(10000,1);
y = 100*randn(10000,1);
h2 = histogram2(x,y,-100:20:100,-100:20:100,'FaceColor','flat')
i want to change the color of a specific bin lets say bin which belongs to row and column 5
i would want something like this:
h2.Cdata(5,5,:) = [1 0 0] % set bin color to red
but theres no Cdata property
0 Kommentare
Akzeptierte Antwort
Adam Danz
am 26 Mär. 2023
One way to do this is to plot a histogram for each group.
rng('default') % For reproducibility of this example
x = 100*randn(10000,1);
y = 100*randn(10000,1);
[N, xEdges, yEdges] = histcounts2(x,y,-100:20:100,-100:20:100);
% Plot group 1
N1 = N;
N1(5,5) = 0;
h0 = histogram2('XBinEdges',xEdges,'YBinEdges',yEdges,'BinCounts',N1,'FaceColor','Flat');
% Plot group 2
N2 = N(5,5);
hold on
h1 = histogram2('XBinEdges',xEdges(4:5),'YBinEdges',yEdges(4:5),'BinCounts',N2,'FaceColor','r');
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Histograms finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!