0

I have to generate a video made of three main objects coming from some data previously generated: 1)patch graph of a thickness 2)a grey-scale image 3)a plot

I generated three axes: ax1,ax2,ax3 with their properties. When I put the image inside ax2, I always get an image that is smaller, centred, and scaled.

This is what i get: ResultNotWanted

the upper patch graph and the image should be of the same length but I'm not able to figure out how.

Part of the code:

File=dir(File2Load);

%Figure handles and figure object before the loop to reduce the
%computational power required by the loop itself.

fig=figure('visible','on'); %set off when doing the loop of the whole video
fig.Position=([0 0 900 500]);

pipeLength=371;  
limY_TBS=400;

img=[];
x=(1:pipeLength);
xp=[x flip(x)];
z=[];
x1=[-1 x x(end)+1 x(end)+1 flip(x) -1];
y=ones(1,numel(x1));
y(1:end/2)=y(1:end/2)*(limY_TBS+10);
y(end/2+1:end)=-1*y(end/2+1:end);

ax1=axes(fig,'Position',[0.1 0.60 0.80 0.3]);
p1=patch(ax1,x1,y,ones(length(x1),1),'FaceColor','interp'); 
hc=colorbar(ax1,'Location','manual','Position',[0.91 0.6 0.02 0.3]);

title(hc,'°C');
xticks(ax1,0:50:350)
xticklabels(ax1,["0","35","70","105","140","175","210","245      [mm]"])
set(ax1,'TickDir','out')

xlim(ax1,[0 pipeLength])
yticks(ax1,0:25:limY_TBS)
yticklabels(ax1,["0","","","","100","","","","200","","","","300","","","","400"])

clim(ax1,[20 40]);  

%limit of the techinique, the value will build a patch over te region that are out of interest because too thick
patchHeigth=limY_TBS; %patch heigth to be plot when thickness>limT_TBS. This will be the heigth of the patch plotted

colormap(ax1,'turbo')
p2=patch(ax1,x1,y,'w');
ylim([0 limY_TBS]);
ylabel("Film Thickness  [" + char(181)+ "m]",'FontSize',15),

%set axes 2 for the image
ax2=axes(fig,'Position',[0.1 0.20 0.8 0.3]);

mfile=matfile(Vid(1).path);
mOnes=size(cell2mat(mfile.newIred(1,1)));
size(cell2mat(mfile.newIred(1,1)),2)],'YData',[-10 size(cell2mat(mfile.newIred(1,1)),1)]);
imgGraph=imshow(mOnes,'Parent', ax2,'XData',[0 size(cell2mat(mfile.newIred(1,1)),2)],...
    'YData',[-10 size(cell2mat(mfile.newIred(1,1)),1)],...    
    initialMagnification','fit');

imgGraph.CDataMapping="direct";

t1=text(ax2,1,200,' ','FontSize',15,'FontSmoothing', 'on'); %time text
t2=text(ax2,600,200,' ','FontSize',15,'FontSmoothing', 'on'); %acceleration text
t3=text(ax2,300,200,' ','FontSize',15,'FontSmoothing', 'on'); %power text

ax3=axes(fig,'Position',[0.1 0.05 0.8 0.1]); %axis for the acceleration graph

I would like that the image on ax2 to completely fit the defined axes to have the same horizontal span of the top graph.

Thank you for any support that you can give.

Riccardo

  • Good morning! Are you sure you need/want to define your axes positions and sizes by hand? MATLAB has great ways to do that automatically for you ([this](https://www.mathworks.com/help/matlab/ref/subplot.html) or [that](https://www.mathworks.com/help/matlab/ref/tiledlayout.html)). Without a [Minimal, Reproducible](https://stackoverflow.com/help/minimal-reproducible-example) example, it is hard to help, but I'd check that the width to height ratio of your image is consistent with your defined sizes – BillBokeey Jul 11 '22 at 08:11
  • Thank you. I've figured out the problem, as you suggested the width and height of the ax2 were wrong. I set the height and length of the ax2 to be equal and then modifies it with XData and YData properties to change the position and the size and it worked. Here what I've changed: ax2=axes(fig,'Position',[0.1 0.15 0.8 0.8]); ---- imgGraph.XData=[-325,990]; imgGraph.YData=[100,200]; – Riccardo Clavenna Jul 11 '22 at 12:19

0 Answers0