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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1823736/image.png)
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!
0 件のコメント
採用された回答
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.
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
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1823763/image.png)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Develop Apps Using App Designer についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!