change color of xticklabels or yticklabels
조회 수: 149 (최근 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!