- Recreate the plot from the data and incorporate a legend as needed.
 - Create a dummy plot using the same linestyle and color; add a legend to the dummy plot and save as an image. Crop the legend from the dummy plot and paste it into the old image using any convenient image editing software.
 - Create a dummy plot, display the image in the same axes, then call legend so that it's stacked on top of the image. Wrestle with position properties in order to make it not look ridiculous.
 
how to manually add a legend?
    6 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
I have generated a Matlab plot, but unfortunately I did not save it in Matlab. I saved only a screenshot from the figure. I need to add a legend.
How can I add it manually? 
2 Commenti
  DGM
      
      
 il 24 Nov 2021
				
      Modificato: DGM
      
      
 il 24 Nov 2021
  
			I see three obvious options:
Risposta accettata
  DGM
      
      
 il 24 Nov 2021
        
      Modificato: DGM
      
      
 il 24 Nov 2021
  
      The suggestions I gave were in order of decreasing quality.  Option #3 was intended to appear impractical enough that option #1 would seem more appealing.  It's not impossible or terribly difficult; it's just going to require more work and the results are almost guaranteed to be worse.
Say I have the saved plot

% read image
A = imread('badplot.png');
s = size(A);
% plot something
% doesn't matter so long as linestyle matches
% i'm only plotting one point here so that it's hidden
plot(s(2)/2,s(1)/2,':o');
% overlay image and legend
hold on; 
imshow(A)
axis image
hl = legend('banana');
% adjust legend position
hl.Position(1:2) = [0.65 0.80]; 
% recapture image
print(gcf,'fixedplot3.png','-dpng'); 

Image displays are for visualization purposes only.  They are presented using nearest-neighbor interpolation.  Trying to take screenshots of images as an image processing workflow is unnecessarily destructive unless an unwarranted amount of care is taken.  Don't be surprised if your image looks worse after creating what amounts to a screenshot of a screenshot.
Options 1 and 2 should be self-explanatory.  Even if option 1 isn't acceptable (e.g. due to loss of data, etc), then option 2 should only take a few minutes.  It only took me 47 seconds to use GIMP to copy and paste the legend into the original plot image:

0 Commenti
Più risposte (0)
Vedere anche
Categorie
				Scopri di più su Legend in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!