Color indidual labels in plot

조회 수: 6 (최근 30일)
Hans Eberhardt
Hans Eberhardt 2019년 7월 26일
편집: Adam Danz 2019년 7월 29일
Hi,
I created a plot inside of a UI with text as one of the axis labels. I'd like to color one of the labels in red (not all of them). How do I do this?
This is the syntax I am using. I'd like to make 'Two' red.
set(handles.axPlot, 'YTickLabel', {'One', 'Two', 'Three});
I've tried html and latex, but neither works.

채택된 답변

Adam Danz
Adam Danz 2019년 7월 26일
편집: Adam Danz 2019년 7월 29일
As Walter The Great has explained here, this isn't possible to do since the tick labels are not processed through an interpreter nor HTML.
You can replace the y ticks with text() objects instead with the 2 lines of code below (axh is the handle to the axes).
axh = cla();
set(axh, 'YTick', 1:3, 'YTickLabel','')
ylim(axh,[0,4]) % Axis limits must be set first!
xlim(axh,[0,4]) % Axis limits must be set first!
h = text(min(xlim(axh))*ones(3,1), 1:3, {'one','two','three'},'rotation',90, ...
'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'center')
h(2).Color = 'r';
Alternatively, you can use this file exchange function (labelpoints.m) and the line of code below (axh is the handle to the axes).
axh = cla();
set(axh, 'YTick', 1:3, 'YTickLabel','')
ylim(axh,[0,4]) % Axis limits must be set first!
xlim(axh,[0,4]) % Axis limits must be set first!
labelpoints(min(xlim(axh)), 1:3, {'one','two','three'}, 'W', 0.3, ...
'rotation',90,'Color', {'k', 'r', 'k'},'FontSize', 12);

추가 답변 (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