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?
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:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With