How do I control axis tick labels, limits, and axes tick locations?
조회 수: 65 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2011년 2월 7일
편집: MathWorks Support Team
2023년 4월 13일
I would like to know if I have to set the XTickLabel, YTickLabel, ZTickLabel, XTick, YTick, and ZTick properties.
채택된 답변
MathWorks Support Team
2023년 4월 13일
편집: MathWorks Support Team
2023년 4월 13일
You can control the axis limits using the "xlim", "ylim", and "zlim" functions. Pass the functions a two- element vector of the form [min max]. For example:
x = linspace(0,2*pi);
y = sin(x);
plot(x,y);
xlim([0 2*pi])
ylim([-1.5 1.5])
You can control the placement of the tick marks along an axis using the "xticks", "yticks", and "zticks" functions. Specify the tick mark locations as a vector of increasing values. The values do not need to be evenly spaced. For example:
xticks([0 pi 2*pi])
yticks([-1 0 1])
To control the labels associated with each tick mark, use the "xticklabels", "yticklabels", and "zticklabels" functions. Specify the labels using a cell array of character vectors. If you do not want tick labels to show, then specify an empty cell array {}.To include special characters or Greek letters in the labels, use TeX markup, such as \pi. For example:
xticklabels({'0','\pi','2\pi'})
yticklabels({'min','y = 0','max'})
You also can rotate the tick labels and change the format using functions such as "xtickangle" and "xtickformat". For more information about these functions, see:
If you are using R2016a or earlier, you can specify the limits, tick values, and tick labels by setting properties of the Axes object. For example, to modify the values in the x direction, use the XLim, XLimMode, XTick, XTickMode, XTickLabel, and XTickLabelMode properties, such as:
ax = gca;
ax.XLim = [0 2*pi];
ax.XTick = [0 pi 2*pi];
For more information about these properties, see:
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!