필터 지우기
필터 지우기

How to call a function within ax=gca format

조회 수: 3 (최근 30일)
Jose Rego Terol
Jose Rego Terol 2020년 8월 25일
편집: Rik 2020년 8월 25일
Hi,
I got a plot
I want to colour the X Tick labels using cmu matlab package (http://matlab.cheme.cmu.edu/2011/09/13/check-out-the-new-fall-colors/#8)
So, to call cmu function, just type
c = @cmu.colors;
c('deep carrot orange').
I tried this here,
ax=gca
ax.XTickLabel{1}= ['\color{black}' ax.XTickLabel{1}];
ax.XTickLabel{2}= ['\color{red}' ax.XTickLabel{2}];
ax.XTickLabel{3}= [c('deep carrot orange') ax.XTickLabel{3}];
But there is no label for 3rd position. I do not know how to call c here.
Thanks.

채택된 답변

Rik
Rik 2020년 8월 25일
편집: Rik 2020년 8월 25일
This seems to be impossible. The closest I came was the code below.
c = @cmu.colors;
col=c('deep carrot orange');%returns this col=[0.9100 0.4100 0.1700];
%convert the triplet to a hex RGB color code
col=dec2hex(round(col*255),2);col=col';col=col(:)';
figure(1),clf(1)
plot(rand(1,10))
ax=gca;
ax.TickLabelInterpreter='tex';%using 'latex' instead doesn't help
ax.XTickLabel{1}= ['{\color{black}' ax.XTickLabel{1} '}'];
ax.XTickLabel{2}= ['\color{red}' ax.XTickLabel{2}];
ax.XTickLabel{3}=['\color[HTML]{' col '}' ax.XTickLabel{3}];
Note that this function returns an RGB triplet, not some magic indication of what the color should be.
I must therefore echo Walter in that old post: you will have to live with the default colors or use text to replace them one by one
Edit:
I stand corrected. It seems you can indeed use RGB triplets:
c = @cmu.colors;
col=c('deep carrot orange');%returns this col=[0.9100 0.4100 0.1700];
n=3;
ax.XTickLabel{n} = sprintf('\\color[rgb]{%f,%f,%f}%s', col, ax.XTickLabel{n});
  댓글 수: 1
Jose Rego Terol
Jose Rego Terol 2020년 8월 25일
Thanks for this workaround. Using the RGB triplet is good for my needs.
I used this latex format because of this code (https://undocumentedmatlab.com/articles/customizing-axes-tick-labels)
I can replace them one by one. No more than seven labels at the same plot.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by