How to set different colors for the text in a legend ?

Hi
I am using MATLAB 2015. I followed the post >https://se.mathworks.com/matlabcentral/newsreader/view_thread/73336> to set different colors for the different text but still it does not work. According to the link, my hText is empty and h is 1 x 1 legend, but it has more than 1 string. Whats the possible solution here ?

답변 (1개)

George
George 2016년 8월 30일
편집: George 2016년 9월 1일
Use TeX formatting to set the colors.
x = -pi:pi/20:pi;
y1 = sin(x);
y2 = cos(x);
plot(x,y1,'-ro',x,y2,'-.b');
l = legend('\color{red} sin(x)','\color{blue} cos(x)');
You can also set the color using RGB triplets with
\color[rgb]{0,0.5,0}

댓글 수: 5

Sorry, probably I was not clear. But in the example above, I want to set red for 'sin(x)' and blue for 'cos(x)'. In other words, different colors for the text.
George
George 2016년 8월 30일
편집: George 2016년 8월 30일
Use TeX markup! See here under Text -> Interpreter.
x = -pi:pi/20:pi;
y1 = sin(x);
y2 = cos(x);
plot(x,y1,'-ro',x,y2,'-.b');
l = legend('\color{red} sin(x)','\color{blue} cos(x)');
Thanks. It was helpful. As I have many entries in legend, how can I specify color from RGB Triplet e.g. [0,0.5,0] ?
George
George 2016년 9월 1일
편집: George 2016년 9월 1일
\color[rgb]{0,0.5,0}
It's on the doc page under TeX markup.
How can this be done with/under LaTex interpreter?

댓글을 달려면 로그인하십시오.

카테고리

질문:

2016년 8월 30일

댓글:

2018년 12월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by