1

I am building a demonstration application using the matlab application designer. It has two axes. One shows an image. The other shows the profile of the image, and the derivative of the profile.

In the example below, I have a 200 column, by 5 row image.

Below the image, I have a plot of the image profile, and a plot of the derivative. The image profile has (not surprisingly) 200 elements. I'd like the X/Y plots to align consistently with the image axis.

Is there a way to control the image axes, to align correctly with the plot axes?
Obviously, I could remove the axis(app.AxesImageView,'off') line below, and force the axes on. But, that doesn't work either, because the axis labels are very different, and so they don't line up. I want this to be flexible to work for any size image, and the label sizes impact this as well.

TLDR: Is it possible to force the axes in a plot or an imagesc to reside in a particular spot in the region the axes have set aside for rendering?

The current code for rendering the image and the plot are:

w = 5; l = 200;
parms.filterHalfWidth = 20;
img = zeros(w,l);
img(:,ceil(l/2):end)=255;
img = uint8(img);
imagesc(app.AxesImageView,img,[0,255]);
colormap(app.AxesImageView, 'gray');
axis(app.AxesImageView,'off');
title(app.AxesImageView,'Image to find edge');

profile = mean(img,2);
vals    = derivative(profile, parms.filterHalfWidth);
[~, peak] = max(vals);

plot(app.AxesProfiles, profile);
hold(app.AxesProfiles, 'all');
plot(app.AxesProfiles, parms.filterHalfWidth + (1:numel(vals)), vals);
plot(app.AxesProfiles, peak*[1,1], [0,255],'Color','Red','LineWidth',2);
hold(app.AxesProfiles, 'off');

screen shot of image and app designer

John
  • 5,735
  • 3
  • 46
  • 62
  • 1
    I don’t know app designer at all. In the classical GUI system, which works the same as all the regular plotting functionality, you specify the locations of the axes by specifying the rectangle where data is plotted, the labels are all outside this rectangle. That makes alignment trivial. – Cris Luengo Sep 04 '21 at 14:42
  • This might be relevant: https://www.mathworks.com/help/matlab/creating_guis/graphics-support-in-app-designer.html#mw_6208c258-534e-4e69-a74b-f4693d102d92 — They basically suggest to create a single panel in App designer, then use `tiledlayout` to create the plots inside. – Cris Luengo Sep 04 '21 at 14:50
  • @CrisLuengo, a tiled layout will suffer from this same problem. Usually, if I'm making a presentation, I manually stretch things to get them to align. I'm not clear on how one "specifies the location of the axes by specifying the rectangle ..." Can you point me to a doc? – John Sep 04 '21 at 15:01
  • The `position` property of the axes. https://www.mathworks.com/help/matlab/ref/matlab.graphics.axis.axes-properties.html#d123e62844 – Cris Luengo Sep 04 '21 at 15:06
  • `imagesc` should stretch the image to fit the axes. If you manually specify the position of the axes, these plotting functions will not move them. If you don’t, and use default axes, their position will be adjusted so that the labels all fit in the window. I think this is what you experienced. You can do that “manually stretch things” programmatically. – Cris Luengo Sep 04 '21 at 15:10
  • your code is not reproducible, i tested it with uifigure (and subplots) and two axes were perfectly aligned. – Hadi Sep 04 '21 at 23:28

1 Answers1

0

i wasn't able to reproduce your code but I wrote a piece of code with uifigure and ... (which is primary used in appdesigner) it is completely flexible p.s: I don't have required toolbox to calculate derivative so I used another plot.

f=uifigure;
f.Units = "normalized"; % essential 
f.Position= [0.3 0.2 0.5 0.7];
f.AutoResizeChildren='off'; % essential 

ax2=uiaxes(f);
ax2.Units = "normalized";
ax2.InnerPosition=[0.1 0.1 0.8 0.4]; %  set Innerposition of axes at your desired position relative to the figureto ensure axes alignment 

ax1=uiaxes(f);
ax1.Units = "normalized";
ax1.InnerPosition=[0.1 0.55 0.8 0.4];



w = 5; l = 200;
parms.filterHalfWidth = 20;
img = zeros(w,l);
img(:,ceil(l/2):end)=255;
img = uint8(img);
imagesc(ax1,img,[0,255]);
colormap(ax1, 'gray');
axis(ax1,'off');
title(ax1,'Image to find edge');

profile = mean(img,2);
vals    = derivative(profile, parms.filterHalfWidth);
[~, peak] = max(vals);

plot(ax2, profile);
hold(ax2, 'all');
plot(ax2, parms.filterHalfWidth + (1:numel(vals)), vals);
plot(ax2, peak*[1,1], [0,255],'Color','Red','LineWidth',2);
hold(ax2, 'off');

enter image description here enter image description here

Hadi
  • 1,203
  • 1
  • 10
  • 20