How to remove tick label from y axis

조회 수: 873 (최근 30일)
James
James 2013년 11월 12일
댓글: Image Analyst 2024년 5월 28일
Hi,
I have a y axis with labels on the y axis -1 -0.5 0 0.5 1 1.5 2 2.5 3 3.5 I want to remove the first origin label -1. How do I do that?
I have done it with the X axis by the following: set(gca,'XTick',x(2:end)); set(gca,'XTickLabel',x(2:end),'fontsize',14);
but when I try with the y axis I get an error message as follows:
Error using set Values must be monotonically increasing
regards James

답변 (2개)

Image Analyst
Image Analyst 2013년 11월 12일
Does this do the trick for you:
plot(1:10)
set(gca,'YTickLabel',[]);
  댓글 수: 3
__init__.py
__init__.py 2024년 5월 28일
What is the reverse operation to this?
Image Analyst
Image Analyst 2024년 5월 28일
@__init__.py You can set up tick labels to be "auto" or whatever custom labels you want with the yticklabels function.
help yticklabels
YTICKLABELS Set or query y-axis tick labels YTICKLABELS(labels) specifies the y-axis tick labels for the current axes. Specify labels as a cell array of character vectors, for example, {'January','February','March'}. This command will also set both YTickMode and YTickLabelMode to 'manual'. yl = YTICKLABELS returns the y-axis tick labels for the current axes. YTICKLABELS('auto') lets the axes choose the y-axis tick labels. Use this option if you set the labels and then want to set them back to the default values. This command sets the YTickLabelMode property for the axes to 'auto'. YTICKLABELS('manual') freezes the y-axis tick labels at the current values. This command sets the YTickLabelMode property for the axes to 'manual'. m = YTICKLABELS('mode') returns the current value of the tick labels mode, which is either 'auto' or 'manual'. By default, the mode is automatic unless you specify tick labels or set the mode to manual. ___ = YTICKLABELS(ax, ___ ) uses the axes specified by ax instead of the current axes. YTICKLABELS sets or gets the YTickLabel or YTickLabelMode property of an axes. Unlike setting the YTickLabel property directly (which will have no effect on the YTickMode), YTICKLABELS will set the YTickMode to 'manual' in addition to setting the YTickLabelMode properties to 'manual'. If you specify fewer labels than there are tick values, YTICKLABELS will append blank labels so the number of labels matches the number of tick values. See also YTICKS, XTICKLABELS, ZTICKLABELS, THETATICKLABELS, RTICKLABELS. Documentation for yticklabels doc yticklabels

댓글을 달려면 로그인하십시오.


The Matlab Spot
The Matlab Spot 2013년 11월 12일
Hello James, I tried your problem statement in the following example.
fh = plot(-10:10);
axis = get(fh,'Parent');
yTick = get(axis,'YTick');
set(axis,'YTick',yTick(2:end));
It did not give the error while setting the values as the axis YTickLabels get automatically updated when you update the YTick values.
Can you give more details of the scenario what you are facing?

카테고리

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