Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling scatterhist bar colors

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]: enter image description here

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?

like image 237
z8080 Avatar asked Nov 20 '25 15:11

z8080


1 Answers

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:

Proper colors

like image 144
Dev-iL Avatar answered Nov 22 '25 04:11

Dev-iL



Donate For Us

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