Hi. I am using ginput to select some points and plot the points like this:
fig = figure;
ha1 = axes;
ha1.Position = [0.5 0.5 0.3 0.3]
ha1.XLim = [-10 -5];
ha1.YLim = [-5 -1];
set(ha1,'xlimMode','manual');
set(ha1,'ylimMode','manual');
[x,y] = ginput;
plot(x,y);
But every time the points are plotted, the xlim and ylim of the axes are changed automatically. And the ha1.XLimMode and ha1.YLimMode are changed to 'auto' somehow.
Anybody any ideas about this?
Best,
Shizhu

 採用された回答

Ameer Hamza
Ameer Hamza 2018 年 6 月 27 日
編集済み: Ameer Hamza 2018 年 6 月 27 日

1 投票

If you check the xLimMode after running your code, you will see that it has changed back to auto after the plot() statement. You need to hold() the axis to stop it from changing automatically.
fig = figure;
ha1 = axes;
ha1.Position = [0.5 0.5 0.3 0.3]
ha1.XLim = [-10 -5];
ha1.YLim = [-5 -1];
set(ha1,'xlimMode','manual');
set(ha1,'ylimMode','manual');
[x,y] = ginput;
hold(ha1); %<--- this line will prevent automatic changes.
plot(x,y);

4 件のコメント

Jan
Jan 2018 年 6 月 27 日
編集済み: Jan 2018 年 6 月 27 日
+1. Or equivalently:
ha1.NextPlot = 'add'
Then the high-level graphics function plot does not reset the axes' properties. Alternatively you can use the low-level function line instead of plot.
painter wang
painter wang 2018 年 6 月 27 日
That works. Thank you guys. But what if I want to hold xaxis and set YLimMode to 'auto'?
Ameer Hamza
Ameer Hamza 2018 年 6 月 27 日
Then set the required values of 'auto' or 'manual'. For example
ax = gca;
hold(ax);
ax.XLim = [0 10];
ax.XLimMode = 'manual';
ax.YLimMode = 'auto';
plot(1:10);
plot((1:20).^2)
Here x-axis will still be fixed between [0 10] although the second plot has 20 elements. Note if you set YLim property after YLimMode then YLimMode will automatically become manual. For example
ax.YLimMode = 'auto';
ax.YLim = [0 10];
will implicitly set YLimMode as 'manual'.
painter wang
painter wang 2018 年 6 月 27 日
Roger.
Thks :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by