Does `imshow` just delete all other objects in the axes?

5 ビュー (過去 30 日間)
Albert Bing
Albert Bing 2020 年 11 月 21 日
編集済み: Mario Malic 2020 年 11 月 21 日
It seems that imshow just deletes all other objects or handles in the parenting axes. Say I have a script like this
fig = figure;
ax = axes(fig);
text(ax, 0.5, 0.5, 'string');
h0 = findobj(ax, 'Type', 'text');
img = randn(128, 128);
imshow(img); % why is `imshow(ax, img)` illegal?
h = findobj(ax, 'Type', 'text');
h0 is a 1x1 text, but h is empty!
Another wierd behaviour of imshow is that you cannot set the axes in the imshow command, i.e. imshow(ax, img) is not allowed.
Why is imshow so different?
  2 件のコメント
Albert Bing
Albert Bing 2020 年 11 月 21 日
編集済み: Albert Bing 2020 年 11 月 21 日
Sorry it was my carelessness. The point is the 'NextPlot' property of the axes. The default value is 'replace'. So to make the previous defined handles kept, it should be changed to 'add'.
Mario Malic
Mario Malic 2020 年 11 月 21 日
編集済み: Mario Malic 2020 年 11 月 21 日
You can also do it that way, or with hold.

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

採用された回答

Mario Malic
Mario Malic 2020 年 11 月 21 日
Hello,
To use hold on with handles to axes, this works.
hold(ax, 'on');
To assign image to axes with imshow
imshow(img, 'Parent', ax)
  1 件のコメント
Albert Bing
Albert Bing 2020 年 11 月 21 日
Thanks
I checked my other code, turned out the axes was used as axes(fig, 'NextPlot', 'add').
So I guess imshow is not so different.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by