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?
0 个评论
采纳的回答
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
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!