Why is the Tag property of the parent axes not retained when using the IMSHOW function?

1 view (last 30 days)
I have set a value to the Tag property of an axes. I then display another image using the IMSHOW command with the 'Parent' property set to the first axes. However, the Tag property of the first axes is not retained.
An example is provided below:
load spine;
imshow(X,map);
set(gca,'Tag','spineImagehere')
get(gca,'Tag') % Tag property has been set
imshow(X,map,'Parent',gca)
get(gca,'Tag') % Tag property does not exist

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 3 Aug 2016
This is expected behavior. The IMSHOW function internally creates a new plot. Since the axes "NextPlot" property to set to "replace" (the default), all the axes properties are reset (except for the 'Position' property) to their default values and all axes children are deleted before displaying graphics.
In order to change this behavior, set the "NextPlot" property of the axes to "add".
The MATLAB code incorporating this change is provided below:
 
load spine;
imshow(X,map);
set(gca,'Tag','spineImagehere')
get(gca,'Tag')
set(gca,'NextPlot','add')
imshow(X,map,'Parent',gca)
get(gca,'Tag') % Tag is retained

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!