Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab legend text overflows using Latex interpreter

I am trying to include a legend within my matlab plot which uses the Latex interpreter for the legend text.

When I set the legend to use the Latex interpreter though, the text within overflows outside the legend box.

I have tried adjusting the size of the text, but this occurs regardless of the FontSize.

The following is the relevant portion of my script:

I = legend([h1 h2 h3],'RainFall Flux', ... 
           'Temperature term ($$\rho \alpha$$dT)', ...
           'Salinity term ($$\rho \beta$$dS)');
c=get(I,'children');
set(c(5),'LineWidth',3); %adjust lineWidth in legend
set(c(2),'LineWidth',3); %adjust lineWidth in legend
set(I,'interpreter','latex'); %set Latex interpreter
set(I,'FontSize',15);

I am assuming this is because matlab is not taking into account the proper character size after the text has been interpreted using Latex. However, I don't know how to fix this.

Any insight would be much appreciated! Thanks!

like image 382
tuntun Avatar asked Sep 20 '13 18:09

tuntun


1 Answers

I don't have any problem with your code, in R2007b, if I remove [h1 h2 h3] (and the comma) from your first statement. However, the change in linewidths in the legend disappears after calling the latex interpreter, or after setting FontSize, so I had to switch those orders. In other words, this code works:

x=[1:100]; y=sin(pi*x/50); plot(x,y,x,y.^2,x,sqrt(abs(y)));
I = legend('RainFall Flux', ... 
           'Temperature term ($$\rho \alpha$$dT)', ...
           'Salinity term ($$\rho \beta$$dS)');
c=get(I,'children');
set(I,'interpreter','latex'); %set Latex interpreter
set(I,'FontSize',15);
set(c(5),'LineWidth',3); %adjust lineWidth in legend
set(c(2),'LineWidth',3); %adjust lineWidth in legend
like image 110
dmm Avatar answered Oct 19 '22 04:10

dmm