Exact value of FaceColor in histogram

29 ビュー (過去 30 日間)
Purnendu Nath
Purnendu Nath 2018 年 5 月 16 日
コメント済み: Purnendu Nath 2018 年 5 月 17 日
When I use histogram, with default FaceColor... get(h, 'FaceColor') returns 'auto'. I do want to let it use the default, but I would like to know the value of the FaceColor as I would like to plot a line with the exact same color. How do I get the value of the FaceColor?

採用された回答

Ameer Hamza
Ameer Hamza 2018 年 5 月 16 日
編集済み: Ameer Hamza 2018 年 5 月 16 日
In case of 'auto' the histogram use ColorOrder property of its axis to choose the color
get(h.Parent, 'ColorOrder')
will give you a list of colors and first-row corresponds to the first plot (i.e. your histogram). By default it is
0 0.4470 0.7410 <- This is rgb value for your histogram
0.8500 0.3250 0.0980
0.9290 0.6940 0.1250
0.4940 0.1840 0.5560
0.4660 0.6740 0.1880
0.3010 0.7450 0.9330
0.6350 0.0780 0.1840
But if you draw the line using [0, 0.4470, 0.7410], you will not get the exact same color because histogram set the default transparency ( alpha ) to 0.6. So you will need to set both RGB and alpha value to get the correct color. From the documentation, you can see that plot does not have an alpha property. Therefore to get the exact same color you can use this web link to convert RGB and alpha values to a unique RGB value against a white background. The result is
[0.4000, 0.6667, 0.8431] <- This will give correct color against white background
You can check the color by plotting
plot((1:100).^2, 'Color', [0.4000, 0.6667, 0.8431], 'LineWidth', 4)
  5 件のコメント
Ameer Hamza
Ameer Hamza 2018 年 5 月 17 日
According to the documentation the colors should loop back. You can see what color with which the next plot will be printed using
get(h.Parent, 'ColorOrderIndex')
It will show that which color from 1 to 7 will be used for next plot.
Purnendu Nath
Purnendu Nath 2018 年 5 月 17 日
aha! perfect... thanks again!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by