From: Lukáš Jiřiště Date: Tue, 30 Jul 2024 14:09:41 +0000 (+0200) Subject: Fix bug where a plot is rendered on incorrect fig X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=9b8f4cc985bf36cbd3d63f86cb7be9f47972a86a;p=Bubble_column.git Fix bug where a plot is rendered on incorrect fig I dont know whether Matlab can't keep up and does not keep track of figures, but some figures had no plots and other figures had the missing plots. This is (hopefully) fixed by directly telling imshow and plot what figure (axes) to use. --- diff --git a/Bubliny.m b/Bubliny.m index 2249ad2..9534b11 100755 --- a/Bubliny.m +++ b/Bubliny.m @@ -80,11 +80,11 @@ for iii=1:1:nSelectedDirectory % Cycles for directories with files IntensitiesAverFin{jjj} = get_representative_intensities(ContrastFigure); % Figure with average intensity, without the bands with hole and meter - figure - imshow(ContrastFigure) - hold on - plot(IntensitiesAverFin{jjj},'-y','linewidth',2) - hold on + f = figure(); + ax = axes(f); + imshow(ContrastFigure, 'Parent', ax) + hold(ax, 'on'); + plot(ax, IntensitiesAverFin{jjj},'-y','linewidth',2) if jjj>=startFile+step %subtracts the intensities plot(IntensitiesAverFin{jjj-step},'Color',[0.9290 0.6940 0.1250],'linewidth',2) hold on @@ -112,7 +112,7 @@ for iii=1:1:nSelectedDirectory % Cycles for directories with files [Height(1,jjj),pkH]=max(pk); qH=lk(pkH); Metr_fit_H(1,jjj)=polyval(polypar_Metr,qH); - plot(qH,-Height(jjj),'or','linewidth',2) + plot(ax, qH, -Height(jjj), 'or', 'linewidth', 2) elseif jjj>=startFile+step if waytrend<=0; [pk,lk] = findpeaks(-IntensitiesAverFin_2{jjj}(1:(LevelPixels+30))); %10 @@ -124,7 +124,7 @@ for iii=1:1:nSelectedDirectory % Cycles for directories with files qH=lk(pkH); Metr_fit_H(1,jjj)=polyval(polypar_Metr,qH); end - plot(qH,Height(jjj),'om','linewidth',2) + plot(ax, qH, Height(jjj), 'om', 'linewidth', 2) end elseif D_num==2 @@ -134,7 +134,7 @@ for iii=1:1:nSelectedDirectory % Cycles for directories with files [Height(1,jjj),pkH]=max(pk); qH=LevelPixels+lk(pkH); Metr_fit_H(1,jjj)=polyval(polypar_Metr,qH); - plot(qH,-Height(jjj),'or','linewidth',2) + plot(ax, qH, -Height(jjj), 'or', 'linewidth', 2) elseif jjj>=startFile+step if waytrend<=0; [pk,lk] = findpeaks(-IntensitiesAverFin_2{jjj}(LevelPixels:end)); %10 @@ -148,7 +148,7 @@ for iii=1:1:nSelectedDirectory % Cycles for directories with files qH=NaN; Metr_fit_H(1,jjj)=NaN; end - plot(qH,Height(jjj),'om','linewidth',2) + plot(ax, qH, Height(jjj), 'or', 'linewidth', 2) end end @@ -190,7 +190,7 @@ for iii=1:1:nSelectedDirectory % Cycles for directories with files Metr_fit_B(1,jjj)=NaN; % For 1-4 files qB=NaN; end - plot(qB,Bottom(jjj),'ob','linewidth',2) + plot(ax, qB, Bottom(jjj), 'ob', 'linewidth', 2) else if D_num==1 LevelPixels=MeterScale(1+(1000-LevelNum(1,jjj))/100); % x level in pixels in the original image @@ -206,7 +206,7 @@ for iii=1:1:nSelectedDirectory % Cycles for directories with files qB=NaN; Metr_fit_B(1,jjj)=NaN; end - plot(qB,Bottom(jjj),'oc','linewidth',2) + plot(ax, qB, Bottom(jjj), 'oc', 'linewidth', 2) elseif D_num==2 LevelPixels=MeterScale(1); % x level in pixels in the original image if waytrend<=0; @@ -221,7 +221,7 @@ for iii=1:1:nSelectedDirectory % Cycles for directories with files qB=NaN; Metr_fit_B(1,jjj)=NaN; end - plot(qB,Bottom(jjj),'oc','linewidth',2) + plot(ax, qB, Bottom(jjj), 'oc', 'linewidth', 2) end end @@ -232,7 +232,6 @@ for iii=1:1:nSelectedDirectory % Cycles for directories with files clear ContrastFigure clear ContrastFigureFin % clear IntensitiesAverFin - end % jjj, Cycles for figures files hf4=figure ('Name','Velocity','NumberTitle','off','PaperSize',[8.5 6],'PaperUnits','centimeters');