matlab imshow not fitting the defined axes
Ältere Kommentare anzeigen
Hello,
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:

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:
fig=figure('visible','on');
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]);
patchHeigth=limY_TBS;
colormap(ax1,'turbo')
p2=patch(ax1,x1,y,'w');
ylim([0 limY_TBS]);
ylabel("Film Thickness [" + char(181)+ "m]",'FontSize',15),
ax2=axes(fig,'Position',[0.1 0.20 0.8 0.3]);
mfile=matfile(Vid(1).path);
mOnes=size(cell2mat(mfile.newIred(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.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Images finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!