- 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
9 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Adam Danz
2023-3-26
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');
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Histograms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!