2

Below is a part of my code.

  [leg, hobj1] = legend('MFR1', 'MFR2', 'MFR3', 'MFR4', 'MFR5', 'Reference') ;
  textobj = findobj(hobj1, 'type', 'text');
  set(textobj, 'Interpreter', 'latex', 'fontsize', 12);
  legend(leg, "location", "northeast");

The code works perfectly fine. Now I change the last row with location from "northeast" to "northwest":

  legend(leg, "location", "northwest");

Problem: Although the legend moves to the location desired, the properties of the legend do not change. i.e., the font size does not change, the text Reference goes outside the box. This happens for all the locations except northeast.

For me, the latex interpreter is not really necessary, I used it to solve my main problem of the legend box either going outside my plot or the text inside the box extending outside the box.

Can someone please help me with this?

Thank you

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
Emotional Damage
  • 138
  • 1
  • 1
  • 9
  • Which MATLAB version are you using? – Dev-iL Aug 05 '20 at 16:55
  • I am using MATLAB R2018b. @Dev-iL – Emotional Damage Aug 05 '20 at 22:15
  • Why does the title say "octave"? – Ander Biguri Aug 06 '20 at 11:29
  • The code is written in Octave. For wider reach and due to its similarities I used the "matlab" tag – Emotional Damage Aug 06 '20 at 19:24
  • 1
    If you are using Octave, use the [octave] tag, if you are using MATLAB use the [matlab] tag. The systems are similar but also very different, especially in the graphics department. Adding both tags is counter-productive. You’ll get answers you can’t use because they don’t work on your system be clear about what you use, and add version number too if it’s potentially a bug you ran into. – Cris Luengo Aug 08 '20 at 16:03

1 Answers1

0

I tried to reproduce your problem, but for me the "northeast" had the problem with text outside of the legend box. I am not sure, but I think that the fontsize isn't updated in your original northeast location, and updating for the other locations. Either way, the text fit inside the box when I used fontsize 10 instead.

  set(textobj, 'Interpreter', 'latex', 'fontsize', 10);
  • Thank you @graadiggrei. But for me even with the font size 10, the text remains outside the box. I tried different things, nothing worked, for now, so I switched to MATLAB from the octave. I will try making the code work in octave maybe later. The code works perfectly fine in MATLAB with some changes. `legend({'MFR1', 'MFR2','MFR3', 'MFR4', 'MFR5', 'Reference'}, 'location', 'northeast', 'FontSize', 12);` – Emotional Damage Aug 09 '20 at 12:10