Plot line in subplot removes axes title

조회 수: 3 (최근 30일)
Lask
Lask 2017년 7월 5일
댓글: Adam 2017년 7월 5일
Hi everyone,
I'm having an issue regarding plot and subplot commands. I created a figure ( figure graphic object) as follows:
f = figure;
Then I created a subplot ( axes graphic object), assigned a title to it and placed it in the figure like this:
a = subplot(2,1,1, 'Parent',f)
a.Title.String = 'This is a subplot'
Finally I created a dummy plot and tried to display it in subplot "a" as follows
p = plot(a,1:10,1:10:100)
However, the behavior was not as I expected. The plot is correctly displayed in the "a" subplot axes but the title I assigned to "a" was removed.
I'd like to know why is this happening. Thanks in advance.

채택된 답변

Adam
Adam 2017년 7월 5일
편집: Adam 2017년 7월 5일
Functions like plot have side effects, one of which is to clear the title. Just change the order:
p = plot(a,1:10,1:10:100);
a.Title.String = 'This is a subplot';
Well, technically, it is not the plot function that has this effect, it is the axes property
'NextPlot'
which defaults to
'Replace'
and when it is set to 'replace' the next instruction to plot (or imagesc or anything that plots onto the axes) will not only remove existing plots but will also reset all axes properties except position and units (this is in the help for Axes Properties under 'Next Plot', but is not obvious from the help of 'plot' itself).
  댓글 수: 2
Lask
Lask 2017년 7월 5일
편집: Lask 2017년 7월 5일
Really helpful, Adam. Just changed 'NexPlot' property of my axes to 'add' and everything worked as I wanted.
Thanks so much.
Eduardo
Adam
Adam 2017년 7월 5일
Beware though that this setting will also cause any new plots to be plotted on top of existing ones rather than replacing them, as is the default behaviour.

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

추가 답변 (0개)

카테고리

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