how do i get the color gray

3,060 ビュー (過去 30 日間)
lowcalorie 2012 年 5 月 23 日
編集済み: Hans Scharler 2022 年 5 月 13 日
how do i get the color gray on my graph


Hans Scharler
Hans Scharler 2022 年 5 月 13 日
編集済み: Hans Scharler 2022 年 5 月 13 日
As others have pointed out, gray is the result of the Red, Green, and Blue are equal somewhere between 0 and 1 where black is [0 0 0] and white is [1 1 1].
x = rand(200,4);
y = rand(200,4);
grayColor = [.7 .7 .7];
plot(x, y, 'Color', grayColor)
If you are you used to 255 color values from HTML for example, you can divide by 255 to get a value between 0 and 1. Classic HTML gray is [128, 128, 128].
x = rand(200,4);
y = rand(200,4);
htmlGray = [128 128 128]/255;
plot(x, y, 'Color', htmlGray)

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 5 月 23 日
Gray is any RGB color with Red, Green, and Blue components all equal, excepting black (all 0's) and white (all components the maximum).
For example,
plot(x, y, 'Color', [17 17 17])
  4 件のコメント
Walter Roberson
Walter Roberson 2020 年 7 月 28 日
Which MATLAB release are you using?
plot(rand(1,5), 'Color', uint8([17 17 17]))
hold on
plot(rand(1,5), 'Color', [17 17 17]/255)
hold off
works for me.
Note that there are some plot attributes that only accept floating point, such as most Alpha values. In that case you would need the /255 form.



Find more on Dates and Time in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by