tight_subplot not showing tick marks

조회 수: 38 (최근 30일)
Jonathan
Jonathan 2011년 10월 17일
댓글: IFEOLUWA 2023년 9월 20일
Hi,
I'm using tight_subplot from the file exchange to plot 4 similar graphs. I'm finding that, when I run my script, the x and y tick marks (i.e. 1,2,3...12) are disappearing for all 4 subplots. I'm not doing anything intentional to suppress them, but I am using a for loop to generate the four plots, which makes me wonder whether some information is being lost each time I end a loop.
Is there any sort of set command that I could use to bring these back up? Something like... set(ha(1:2),'XTickLabel','on')? (That doesn't work... ) I'd prefer not to have to actually assign the tick marks explicitly, but to get them from the metadata associated with the figures.
Thanks, Jonathan

채택된 답변

Walter Roberson
Walter Roberson 2011년 10월 17일
If the plots are sufficiently close together, then the endpoints of the ticks might not be within the axes span: in such a case, MATLAB suppresses the line. This is the same case is if you have given specific axis limits and then you add a new line that starts or ends outside of the drawing area: the line will simply not be drawn. In order for MATLAB to draw a line, both endpoints must be within the clipping area.
  댓글 수: 2
Jonathan
Jonathan 2011년 10월 17일
Thanks for the information, Walter. Is there any way to recover the tick marks after Matlab has decided to suppress them?
Walter Roberson
Walter Roberson 2011년 10월 17일
Only by expanding the plotting area (and triggering a redraw.)

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

추가 답변 (2개)

Andreas
Andreas 2014년 1월 8일
Once tick labels have been removed, I don't think they can be automatically regenerated: you have to add them explicitly using set(gca,'XTickLabel',[...]).
The better option, of course, is to prevent them from disappearing in the first place: tight_subplot contains the lines 'XTickLabel','', ... 'YTickLabel',''... Remove them and you're golden!

Peter Attia
Peter Attia 2017년 9월 6일
I know this question is old, but this had stumped me too for some time. It turns out calling "hold on" before a plot is generated causes the x and y tick marks to disappear.
My original for loop looked like this:
hold on, box on
for j = 1:5
plot(x,y)
end
The working for loop looks like this:
for j = 1:5
plot(x,y)
hold on
end
box on
Hope this helps! -Peter
  댓글 수: 4
Marc
Marc 2023년 3월 31일
Thanks for your comment Peter, its never too late for a solution. Even years later this is the problem, bringing the hold function inside the loop fixed it.
IFEOLUWA
IFEOLUWA 2023년 9월 20일
Thanks Peter. Works perfectly

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

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by