how to represent the purple color by a string value

305 Ansichten (letzte 30 Tage)
jaah navi
jaah navi am 22 Feb. 2019
Beantwortet: Walter Roberson am 9 Apr. 2025
There are 8 colors that can be specified by a string value: 'r','g','b','c','m','y','k','w'.
How to specify the maroon,olive,purple color by a string value.
  2 Kommentare
KEERTHIGA
KEERTHIGA am 9 Apr. 2025
how to represent violet in string
Image Analyst
Image Analyst am 9 Apr. 2025
@KEERTHIGA you can't. Computers cannot reproduce violet. The spectrum of the blue emitting pixels does not go down to a short enough wavelength. You can do purple though. Purple is red and blue, so you could do
purple = [128, 0, 128] / 255;
You can then use "purple" wherever you need to specify the color, for example
plot(rand(1, 10), 'Color', purple, 'LineWidth', 9);

Melden Sie sich an, um zu kommentieren.

Antworten (3)

John D'Errico
John D'Errico am 22 Feb. 2019
Bearbeitet: John D'Errico am 22 Feb. 2019
You can't. MATLAB offers those string options for colors. If you want to set a specific color, you can, but as a numeric vector of length 3. You need to provide RGB code values.
For example, for a purple of sorts, you might do this:
H = surf(rand(10));
H.FaceColor = [.5 0 .5];
Not my favorite color scheme, but it is purple. And, for an olive, you might try something like this:
H.FaceColor = [.3 .4 .2];
You get the idea.

DGM
DGM am 9 Apr. 2025

Walter Roberson
Walter Roberson am 9 Apr. 2025
To represent colors by string, you can use a quoted hexadecimal triplet. For example,
plot(y, 'Color', '#800080')
However, the only available named colors are
"red", "green", "blue", "cyan", "magenta", "yellow", "black", "white", and "none"

Kategorien

Mehr zu Labels and Annotations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by