Problems overlaying contour on image in uifigure

I am trying to mimic the following code:
f1=figure;
a1=gca;
hi1 = imshow(repmat(reshape(uint8(normalize(dose(:), "range")* 256), size(xg)), [1 1 3]), R, 'Parent', a1, 'InitialMagnification', 1500)
hold on
w = 17;
[~, hc] = contour(reshape(actual_positions(:, 1), w, []), reshape(actual_positions(:, 2), w, []), reshape(points, w, []), 'Parent', a1)
which works OK and outputs the following:
in a UIFigure like this:
f2 = uifigure();
a2 = uiaxes(f2);
hi2 = imshow(repmat(reshape(uint8(normalize(dose(:), "range")* 256), size(xg)), [1 1 3]), R, 'Parent', a2, 'InitialMagnification', 1500);
which displays the image OK:
The Image seems to be a child of the figure:
>> f2.Children(1).Children
ans =
Image with properties:
CData: [53×53×3 uint8]
CDataMapping: 'direct'
Show all properties
But it fails to overlay the contours properly with this code:
hold all
[~, hc] = contour(reshape(actual_positions(:, 1), w, []), reshape(actual_positions(:, 2), w, []), reshape(points, w, []), 'Parent', a2);
hc.Parent.Color = 'none';
It seems to remove the image and replace it with the contour plot instead of overlaying it.
There is only one child and it is the contour plot:
>> f2.Children(1).Children
ans =
Contour with properties:
EdgeColor: 'flat'
LineStyle: '-'
LineWidth: 0.5000
FaceColor: 'none'
LevelList: [0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700 0.0800 0.0900]
XData: [17×17 double]
YData: [17×17 double]
ZData: [17×17 double]
Show all properties
Is there any way to make the behavior the same for a figure and a uifigure?

 Akzeptierte Antwort

Voss
Voss am 13 Mär. 2024
Use
hold(a2,'all')
That is, you need to specify the axes you want to hold.

3 Kommentare

Voss
Voss am 13 Mär. 2024
To explain:
hold and other functions, when no axes is specified, use the CurrentAxes (which is a (ui)figure property) of the CurrentFigure (which is a Graphics Root (a.k.a. groot) property).
A uifigure will not be the CurrentFigure by default because uifigures' HandleVisibility is 'off' by default (whereas figures' HandleVisibility is 'on' by default).
So hold et al, with no axes specified, will not apply to an axes in a uifigure by default, so you need to specify which axes to apply to.
Jonathan
Jonathan am 18 Mär. 2024
Thanks, your solution works for me, the additional explanation was usefull in understanding the mechanisms behind it. I bet I would not have found that easily through Matlab documentation/help features. :-D
Voss
Voss am 18 Mär. 2024
You're welcome!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2023b

Gefragt:

am 13 Mär. 2024

Kommentiert:

am 18 Mär. 2024

Community Treasure Hunt

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

Start Hunting!

Translated by