How to call a function within ax=gca format

2 views (last 30 days)
I got a plot
I want to colour the X Tick labels using cmu matlab package (
So, to call cmu function, just type
c = @cmu.colors;
c('deep carrot orange').
I tried this here,
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.

Accepted Answer

Rik on 25 Aug 2020
Edited: Rik on 25 Aug 2020
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
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
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];
ax.XTickLabel{n} = sprintf('\\color[rgb]{%f,%f,%f}%s', col, ax.XTickLabel{n});
  1 Comment
Jose Rego Terol
Jose Rego Terol on 25 Aug 2020
Thanks for this workaround. Using the RGB triplet is good for my needs.
I used this latex format because of this code (
I can replace them one by one. No more than seven labels at the same plot.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!