Right and top axes disappear when I hold on a figure

Hello,
My question seems so stupid that I feel obliged to say I have already looked for an answer on Mathworks. When I use hold on with a figure, the right and top axes of the figure disappear. I would like to get all four axes so that my figure has a real frame. Any idea on how I can do that?
Thank you very much,

댓글 수: 8

Something besides hold is causing the issue; hold by itself only toggles the state of whether subsequent "stuff" is added to or replaces earlier "stuff" on the axes.
Pare an example down to the minimum it takes w/ a set of random data to illustrate the problem...something like
figure
plot(rand(10,1))
hold on
plot(sqrt([1:10])-0.5)
Then, add what it is from there that you're doing in your case to cause your symptoms and if that doesn't give you the answer of what not to do or how to fix the problem, post that series of commands.
did you try "box on" after the axes disappear! You may try Box On at the end of all plots.
dpb
dpb 2013년 8월 8일
Or conversely remove any box off :)
I was trying to get OP to find where he turned it off in his code...
Hello,
First, thanks to both of you. I am certain that the problem is caused by hold on. I tried these two examples:
x = linspace(-1,1,100);
figure,
plot(x,x.^2,'r')
x = linspace(-1,1,100);
figure, hold on
plot(x,x.^2,'r')
The first one gives a correct frame and on the second one the right and top axes are missing. This happened to all my plots. I solved the problem specifying box on at the end of the plot.
I wonder why I am the only one to have this issue. I probably should mention that I'm a Linux user, maybe this makes the difference? I don't know...
Anyway, thanks again!
dpb
dpb 2013년 8월 8일
Well, that's a logic flow error; you're putting hold on before you put anything on the axes. Rearrange the code to not execute the hold until the first plot is there and I think the "symptom" will also disappear.
IOW, I think this is a case of "working as designed".
Jessica Piper
Jessica Piper 2017년 3월 23일
편집: Jessica Piper 2017년 3월 23일
dpb, I don't see why this is a logic error. Moreover, this behavior did not occur pre hg2, at least for me.
One of the most natural use cases for "hold on" is when you have a loop that plots a number of data sets. The natural way to write that code would place the statements "figure;hold on;" outside of the loop, and the plot command within the loop. Requiring the user to do one extra-loop plot is ugly.
Also for the record, I am having this problem on R2015a.
I had the same issue. "Box on" solves it. Thanks for the hint!
Thanks for the explanation, I found one of the subplots has a 'hold on' command before plot. Everything happens for a reason, indeed.

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

 채택된 답변

Pl Pl
Pl Pl 2013년 8월 8일
편집: Pl Pl 2013년 8월 8일

1 개 추천

For those having a similar problem, what worked for me was the solution provided by Sandip here : http://www.mathworks.com/matlabcentral/answers/84308#comment_163486

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

질문:

2013년 8월 8일

댓글:

2020년 12월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by