问题
I was trying to make the bars in my scatterhist
plot be of the same color as the markers:
x = randn(1,20);
y = randn(1,20);
myColour = [1 0 0]; % red
scatterhist(x, y, 'Color', myColour);
mygca = get(gca,'children');
set(mygca,'markerfacecolor', myColour);
However, the bars are of a slightly different color, namely a reddish hue, [249 96 96]:
The Scatterhist documentation seems to suggest bar colors just follow marker color, which in this case does not happen.
How can I control color of the scatterhist
bars, on MATLAB R2016a?
回答1:
This happens because the bars have an alpha (transparency) setting.
To fix this, make sure the 'FaceAlpha'
setting is set to 1. For example:
x = randn(1,20);
y = randn(1,20);
myColour = [1 0 0];
hSh = scatterhist(x, y, 'Color', myColour);
hSh(1).Children.MarkerFaceColor = myColour;
hSh(2).Children.FaceAlpha = 1;
hSh(3).Children.FaceAlpha = 1;
Which yields:
来源:https://stackoverflow.com/questions/50466320/controlling-scatterhist-bar-colors