diff --git a/matlab/gdat_plot.m b/matlab/gdat_plot.m
index 8fa184d1a1fde4242bd200671ed97184918da096..29895699b09e889c7085e485ec014d4c66f645f3 100644
--- a/matlab/gdat_plot.m
+++ b/matlab/gdat_plot.m
@@ -40,10 +40,12 @@ if doplot==0; return; end
 redo_legend_from_Tags = 0;
 do_legend = 1;
 
+nb_linehandles_current = numel(linehandles);
 for ishot=1:numel(gdat_data)
+  nb_linehandles_prev = nb_linehandles_current;
   if all(isfield(gdat_data(ishot),{'data','t'})) && ~isempty(gdat_data(ishot).data) && ~isempty(gdat_data(ishot).t)
     fighandle = get(0,'CurrentFigure');
-    if numel(gdat_data) > 1 && gdat_data(1).gdat_params.doplot==1
+    if ishot > 1 && gdat_data(1).gdat_params.doplot==1
       % assume that for a series of shot, need doplot=-1 after 1st plot if doplot was 1 in request
       doplot = -1;
     end
@@ -161,12 +163,13 @@ for ishot=1:numel(gdat_data)
       zoom on;
     end
     maxnblines = 1;
+    nb_linehandles_current = numel(linehandles);
     if ~exist('ab','var'), ab=get(gca,'children'); end
     if do_legend==0 || redo_legend_from_Tags || any(strcmp(gdat_data(ishot).gdat_params.data_request,'powers'))  ...
           || (numel(ab)==numel(gdat_data(ishot).label) && numel(ab)>1)
       % keep legend as is
     else
-      for i=1:numel(linehandles)
+      for i=nb_linehandles_prev+1:nb_linehandles_current
         maxnblines = max(maxnblines,numel(linehandles{i}));
         if numel(linehandles{i}) == 1
           set(linehandles{i},'DisplayName',[num2str(gdat_data(ishot).shot)]);