MATLAB Answers

Set the Yticklabel to different colors

453 ビュー (過去 30 日間)
yang yang
yang yang 2012 年 2 月 9 日
コメント済み: Walter Roberson 2018 年 12 月 13 日
Hi all, I used this code to set the color of XLable:xlabel('\color{magenta}Love').It works.But I used this way to set the color of Yticklabel,it didn't work(set(h,'Yticklabel',{'\color{magenta}Love','b'})).I want to know how I can set the Yticklabel to different colors.
Thanks for all your kindly answering.

  1 件のコメント

yang yang
yang yang 2012 年 2 月 10 日
I want to know how I can make the YTickLabels in different colors.I mean I want every one label has a different color from the others.

サインイン to comment.

採用された回答

Walter Roberson
Walter Roberson 2012 年 2 月 10 日
There is no direct mechanism for doing this. The tick labels are not processed through the Interpreter, and are not processed as HTML, and there is no color specifier for them other than the axis color that Elige mentions.
The best you can do is to text() them in to place yourself.

  1 件のコメント

yang yang
yang yang 2012 年 2 月 11 日
Thanks for your answer.I think your idea may work,I will try later.

サインイン to comment.

その他の回答 (4 件)

Frank Zalkow
Frank Zalkow 2017 年 5 月 19 日
Something in this vein works:
% make a plot
plot([1,2,3])
% get the current tick labeks
ticklabels = get(gca,'YTickLabel');
% prepend a color for each tick label
ticklabels_new = cell(size(ticklabels));
for i = 1:length(ticklabels)
ticklabels_new{i} = ['\color{red} ' ticklabels{i}];
end
% set the tick labels
set(gca, 'YTickLabel', ticklabels_new);

  1 件のコメント

Walter Roberson
Walter Roberson 2017 年 5 月 20 日
Note: this requires R2014b or later; in versions earlier than that, the tick labels are not processed by latex or tex.

サインイン to comment.


Giorgio
Giorgio 2018 年 6 月 20 日
The possibility of customizing the colors of the tick labels is now available.
A well written explanation is reported here: https://undocumentedmatlab.com/blog/customizing-axes-tick-labels

  0 件のコメント

サインイン to comment.


Dr. Seis
Dr. Seis 2012 年 2 月 9 日
This not only changes the color of the tick label, it also changes the color of the specified axis:
set(h,'YTickLabel','Hate|Dislike|SoSo|Okay|Great|Love','YColor','magenta');
This example replaces the 6 default YTickLabels with the labels specified above in addition to changing the color of the text and axis to magenta.

  3 件のコメント

yang yang
yang yang 2012 年 2 月 10 日
Thanks for your answer.But I want to know how I can make the YTickLabels in different colors.I mean I want every one label has a different color from the others.
Dr. Seis
Dr. Seis 2012 年 2 月 10 日
Not sure if there is a way to do this with HTML... all my tests at trying to do so failed. Anyone else have an idea?
yang yang
yang yang 2012 年 2 月 11 日
Thanks for your answer again!

サインイン to comment.


Andrew Gibbons
Andrew Gibbons 2018 年 12 月 13 日
If you happen to be creating a GUI, use
axes(handles.axes1)
handles.axes1.XColor = [1 1 1] %[1 1 1] is for white, [0 0 0] for black, and in between are different colors
This specifies which axes you want to modify and then XColor changes the color of the x-axis.

  1 件のコメント

Walter Roberson
Walter Roberson 2018 年 12 月 13 日
This sets the color of everything to do with that axes, including grid lines and tick marks.

サインイン to comment.

サインイン してこの質問に回答します。


Translated by