控制散点图条的颜色 [英] Controlling scatterhist bar colors

查看:134
本文介绍了控制散点图条的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使scatterhist图中的条形与标记具有相同的颜色:

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);

但是,条形的颜色略有不同,即偏红色,[249 96 96]:

However, the bars are of a slightly different color, namely a reddish hue, [249 96 96]:

Scatterhist 文档似乎表明条形颜色仅跟随标记颜色,在这种情况下不会发生.

The Scatterhist documentation seems to suggest bar colors just follow marker color, which in this case does not happen.

如何在MATLAB R2016a上控制scatterhist条的颜色?

How can I control color of the scatterhist bars, on MATLAB R2016a?

推荐答案

之所以会发生这种情况,是因为这些条具有 alpha (透明度)设置.

This happens because the bars have an alpha (transparency) setting.

要解决此问题,请确保将'FaceAlpha'设置设置为1.例如:

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;

哪个产量:

这篇关于控制散点图条的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆