How to set color of scatterplot bars?

3 ビュー (過去 30 日間)
z8080
z8080 2018 年 5 月 22 日
コメント済み: Sandro Lecci 2018 年 5 月 22 日
I was trying to have 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 the marker color, which in this case does not happen.
How can I control color of scatterhist bars, on Matlab 2016a?

採用された回答

Sandro Lecci
Sandro Lecci 2018 年 5 月 22 日
編集済み: Sandro Lecci 2018 年 5 月 22 日
dear z8080,
Somehow the histograms are plotted with a FaceAlpha value of 0.6. This makes the red color looking "flatter". To restore it to the correct value type:
x = randn(1,20);
y = randn(1,20);
myColour = [1 0 0]; % red
SH = scatterhist(x, y, 'Color', myColour);
mygca = get(SH,'children');
mygca{2}.FaceAlpha = 1;
mygca{3}.FaceAlpha = 1;
set(mygca{1},'markerfacecolor', myColour);
It should do the trick you are looking for.
Best, Sandro
  2 件のコメント
z8080
z8080 2018 年 5 月 22 日
Many thanks Sandro, this indeed fixes it.
As a side note, any idea why the FaceAlpha defaults to a (seemingly) random 0.6 and not to 1?
Sandro Lecci
Sandro Lecci 2018 年 5 月 22 日
Honestly no.. I have no idea. This was a tricky one, I didn't even see the color difference at the beginning. I'm happy I could help you with this.
Have a good day. Sandro

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

製品


リリース

R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by