setting the "hold" property for axes

58 ビュー (過去 30 日間)
hans
hans 2021 年 12 月 7 日
編集済み: hans 2021 年 12 月 8 日
the suggested way to set hold to "on" "all" oder "off" seems to be writing
hold on
or
ax=plot(x,y); hold(ax,'on');
To set most other properties, a syntax like
txt=xlabel(t,'My_Xlabel'); txt.FontSize = 18; txt.FontWeight = 'bold';
seems to be suggested.
Is there a way to apply this syntax to the hold property of the axes ?
A code like
ax.hold='on'
which was intuitive to me, doesn't work.

採用された回答

Dave B
Dave B 2021 年 12 月 7 日
編集済み: Dave B 2021 年 12 月 7 日
The hold function corresponds to the NextPlot property on the Axes.
I realize that's a little confusing - hold has only two states, on or off, but NextPlot has a few more options. All the way at the bottom of the hold documentation page you'll find this text:
The hold function sets these properties:
  • NextPlot axes property - Sets this property of the associated Axes, PolarAxes, or GeographicAxes object to either 'add' or 'replace'.
  • NextPlot figure property - Sets this property of the Figure object to 'add'.
So the code snippet you're looking for is:
ax.NextPlot = 'add';
There's a small caveat not mentioned in the documentation above, which is that hold off has some slightly different behavior with uiaxes. Instead of setting the NextPlot property to 'replace' it sets it to 'replacechildren'. This can be more useful in apps - it means that the children of the axes will be replaced but the axes will retain other settings. Details about all the different kinds of NextPlot on figure and axes are here:

その他の回答 (1 件)

hans
hans 2021 年 12 月 8 日
編集済み: hans 2021 年 12 月 8 日
OK, thank You a lot for this hint.

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by