In App Designer, how can I keep the X and Y Grids on top of an image I display in UIAxes using imshow?

10 ビュー (過去 30 日間)
I am creating an app that will display plots on top of an image in a UIAxes object. The issue I'm running into is that once I load the image into UIAxes using imshow, the X and Y Grid lines are covered by the image. If I increase the transparency of the image while debugging I can see that they are still there, but I haven't been able to figure out how to move them in front of the image.
Data I plot will appear in front of the image, so I feel like there is a layering issue I can't figure out. I created a quick test app to demonstrate.
The code that creates that updates UIAxes when the button is pressed is:
% Button pushed function: Button
function ButtonPushed(app, event)
%Load Test Image
rgbImage = imread("peppers.png");
%Flip Image so it displays properly
rgbImage = flip(rgbImage);
hold(app.UIAxes,"on");
%Display image in test axes
hImage = imshow(rgbImage, 'XData', [0.0, 1.0], 'YData', [0.0, 1.0],'Parent', app.UIAxes);
%return axes to normal position (imshow reverses the direction
%automatically when called)
app.UIAxes.YDir = 'normal';
%Turn the axes back on
app.UIAxes.XGrid = 'on';
app.UIAxes.YGrid = 'on';
%Plot test data to show it appears on top of the image
xData = [0.4,0.6,0.6,0.4];
yData = [0.4,0.6,0.6,0.4];
plot(xData,yData,'parent',app.UIAxes);
end
Thanks for your help!

採用された回答

Cris LaPierre
Cris LaPierre 2025 年 1 月 20 日 18:17
This has to do with how images are displayed in MATLAB, meaning the issue is not unique to App Designer.
I would use xline and yline. I've modified your code so that it runs here.
rgbImage = imread("peppers.png");
%Display image in test axes
hImage = imshow(rgbImage, 'XData', [0.0, 1.0], 'YData', [0.0, 1.0]);
% Add grid
xline(0:0.2:1,'w')
yline(0:0.2:1,'w')
  4 件のコメント
Cris LaPierre
Cris LaPierre 2025 年 1 月 20 日 22:33
App Designer does have a slightly different behavior. Send the Grid Layer to 'top' is also necessary.
% Button pushed function: Button
function ButtonPushed(app, event)
%Load Test Image
rgbImage = imread("peppers.png");
%Flip Image so it displays properly
rgbImage = flip(rgbImage);
hold(app.UIAxes,"on");
%Display image in test axes
hImage = imshow(rgbImage, 'XData', [0.0, 1.0], 'YData', [0.0, 1.0],'Parent', app.UIAxes);
%return axes to normal position (imshow reverses the direction
%automatically when called)
app.UIAxes.YDir = 'normal';
%Turn the axes back on
app.UIAxes.XGrid = 'on';
app.UIAxes.YGrid = 'on';
%Plot test data to show it appears on top of the image
xData = [0.4,0.6,0.6,0.4];
yData = [0.4,0.6,0.6,0.4];
plot(xData,yData,'parent',app.UIAxes);
axis(app.UIAxes, 'on')
app.UIAxes.Layer = 'top';
app.UIAxes.GridLineWidth = 5;
end
hawks1282
hawks1282 2025 年 1 月 21 日 13:56
Hi Cris,
Sending the grid layer to the top worked perfectly! Thank you so much!
-Brendan

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by