How to insert and adjust size of legend in already saved Fig

1 vue (au cours des 30 derniers jours)
Safi ullah
Safi ullah le 17 Juin 2017
Modifié(e) : dpb le 17 Juin 2017
Hi everybody, I saved my Fig by using the following code
set(gcf,'PaperUnits','inches')
set(gcf,'PaperPosition',[0 0 5 3])
print(gcf,'-dtiff','-r300',['./Fig'])
now I make legend in the same Fig using hold on command by using the code
lgd=legend('A','B')
set(lgd,'position',[0.5 0.8 0.1 0.1])
set(lgd,'FontSize',05,'FontName','Arial');
set(lgd,'units','inches');
but after saving the Fig, legend is not look proper it cross the Fig boundary, this command not controle the legend size. what should I do to make the legend size proper according to my Fig size.
  3 commentaires
Safi ullah
Safi ullah le 17 Juin 2017
@dpb I regenerate the Fig and add the legend before output but still face the same problem. the first code I used to save the Fig with desired size makes problem for legend size so how to overcome this?
dpb
dpb le 17 Juin 2017
Modifié(e) : dpb le 17 Juin 2017
Attach the figure(s) so folks can see...the original and then if possible a scan of the output...or does the opened .fig file display the same issue. If so, perhaps attaching it would help...a snippet that generates a sample that illustrates the problem that folks could just copy and run probably would engender more folks trying and seeing what happens.
I've never messed with the actual physical size on output much; I know there are lots of questions that arise that it seemingly isn't as robust as it might could/should be.
I guess also a pertinent question would be what release are you using and which OS?
ADDENDUM
I just drew an axes and a couple of lines then placed a legend with your 'position' vector and saved with the dimensions given. On reloading, the legend box had been rendered at the very top of the figure; I had to move it down in the actual figure to get it to look about where it is on page.
I don't know enough about the internals of the translation from displayed image to paper but I'm guessing it's got to do with .tiff being a bit image format and the resolution difference between CRT and paper and perhaps your fixed '-r300' plays in there, too.
I'd suggest using the printpreview feature and just "fixing up" the position until you get something that looks as you'd like. Probably you can then use a correction factor to do it programmatically going forward.
Not a perfect solution, granted, but best I can tell you.
Maybe somebody else will come along and know enough to answer in depth.
OBTW, one really strange symptom I noted was that if I used the 'position' as part of the call to legend the actual coordinates weren't even close to those in the passed position vector; I've no klew on that.
Try posting the additional info and if that doesn't elicit satisfactory answers, might be worth a support query if you do have support.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by