change color of xticklabels or yticklabels

154 次查看(过去 30 天)
I need help with this:
ax = gca;
ax.XColor = 'w';
ax.YColor = 'w';
changes the color of the axis and the xticklabels. I want the x axis to be a certain color, but the xticklabels another color.
Any suggestions?

采纳的回答

Star Strider
Star Strider 2021-7-16
One approach —
x = 0:0.1:10;
y = exp(-(x-5).^2);
figure
plot(x, y)
hold on
plot(xlim, [0 0]+min(ylim), 'g')
hold off
Ax = gca;
xt = Ax.XTick;
xtv = compose('%.0f',xt);
Ax.XAxis.Visible = 'off';
text(xt,zeros(size(xt)), xtv, 'Color','r', 'Horiz','center', 'Vert','top')
This turns the x-axis visibility off, draws the x-axis in green, and plots the tick values in red. The ticks themselves are also now invisible, they would have to be added back with a plot call if desired.
.
  2 个评论
Star Strider
Star Strider 2021-7-16
As always, my pleasure!
Also, for the y-tick labels, the text call would be:
text(zeros(size(yt)), yt, ytv, 'Color','r', 'Horiz','right', 'Vert','middle')
although that could require some experimentation.
.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Grid Lines, Tick Values, and Labels 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by