Change color of diagonal bars (1,1), (2,2), (3,3)… in bar3
I am plotting a 2D histogram where there are 7 bars in each axis. An example of the data is attached as N.
On this plot, I would like to be able to color the diagonal bars [e.g., (1,1), (2,2) … (7,7)] green, while leaving the rest of the bars the the base color.
I’ve built the chart using:
[N, Xedges, Yedges] = histcounts2(Xvals, yVals, [7, 7]);
h = bar3(N);
And I’m trying to color the bars using something like this, but I can’t seem to figure out how to select the only the kth bar in each row:
for k = 1 : length(h) % operate on each row of bars
% Set FaceColor to ‘flat’ to use CData for coloring
h(k).FaceColor = ‘flat’;
set(h(k),’facecolor’,[0 1 0]) % green
end
Ideally, I’d like to color both the top and sides of the selected bars green.I am plotting a 2D histogram where there are 7 bars in each axis. An example of the data is attached as N.
On this plot, I would like to be able to color the diagonal bars [e.g., (1,1), (2,2) … (7,7)] green, while leaving the rest of the bars the the base color.
I’ve built the chart using:
[N, Xedges, Yedges] = histcounts2(Xvals, yVals, [7, 7]);
h = bar3(N);
And I’m trying to color the bars using something like this, but I can’t seem to figure out how to select the only the kth bar in each row:
for k = 1 : length(h) % operate on each row of bars
% Set FaceColor to ‘flat’ to use CData for coloring
h(k).FaceColor = ‘flat’;
set(h(k),’facecolor’,[0 1 0]) % green
end
Ideally, I’d like to color both the top and sides of the selected bars green. I am plotting a 2D histogram where there are 7 bars in each axis. An example of the data is attached as N.
On this plot, I would like to be able to color the diagonal bars [e.g., (1,1), (2,2) … (7,7)] green, while leaving the rest of the bars the the base color.
I’ve built the chart using:
[N, Xedges, Yedges] = histcounts2(Xvals, yVals, [7, 7]);
h = bar3(N);
And I’m trying to color the bars using something like this, but I can’t seem to figure out how to select the only the kth bar in each row:
for k = 1 : length(h) % operate on each row of bars
% Set FaceColor to ‘flat’ to use CData for coloring
h(k).FaceColor = ‘flat’;
set(h(k),’facecolor’,[0 1 0]) % green
end
Ideally, I’d like to color both the top and sides of the selected bars green. bar3, color specific bars, handles MATLAB Answers — New Questions