Controlling scatterhist bar colors

僤鯓⒐⒋嵵緔 提交于 2019-12-13 14:09:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!