Latex en la leyenda de los graficos
3 views (last 30 days)
Show older comments
¿Por que la leyenda del grafico no me toma la fuente de latex?
x=[0:0.02:1];
u1=0.13-1.37.*x+1.9.*x.^2-1.11.*x.^3-0.88.*x.^4;
u2=0.13-1.46.*x+0.09.*x.*(1-x)+1.99.*x.^2.*(1-x)+0.88.*x.^3.*(1-x);
plot(x,u1);
hold on;
grid on;
plot(x,u2,'k--');
legend('u','\hat{u}','interpreter','latex');
xlabel('$x$','interpreter','latex')
ylabel('$u \hspace{3mm} \hat{u}$','interpreter','latex')
0 Comments
Answers (3)
VBBV
on 10 May 2023
Edited: VBBV
on 10 May 2023
you can use the $\hat{u}$ in legend function , The latex interpreter fonts usually appear smaller compared to regular fontsize.
x=[0:0.02:1];
u1=0.13-1.37.*x+1.9.*x.^2-1.11.*x.^3-0.88.*x.^4;
u2=0.13-1.46.*x+0.09.*x.*(1-x)+1.99.*x.^2.*(1-x)+0.88.*x.^3.*(1-x);
plot(x,u1);
hold on;
grid on;
plot(x,u2,'k--');
%
legend('u','$\hat{u}$','interpreter','latex','fontsize',18)
xlabel('$x$','interpreter','latex','fontsize',18)
ylabel('[$u ,\hspace{3mm} \hat{u}$]','interpreter','latex','fontsize',18)
0 Comments
Gonçalo
on 17 Jun 2025
Edited: Walter Roberson
on 17 Jun 2025
% Define o domínio de x, evitando
x = 0
x1 = -10:0.01:-0.01;
% Valores de x de -10 até -0.01 (aproximando-se de 0 pela esquerda)
x2 = 0.01:0.01:10;
% Valores de x de 0.01 até 10 (aproximando-se de 0 pela direita)
% Calcula f(x) para cada parte dodomínio
f_x1 = (61 * pi * x1.^3 + 927) ./ x1;
f_x2 = (61 * pi * x2.^3 + 927) ./ x2;
% Cria uma nova figura para o gráficofigure;
% Plota a primeira parte da função (x < 0)
plot(x1, f_x1, 'b-', 'LineWidth', 1.5);
hold on;
% Mantém o gráfico atual para adicionar mais plots
% Plota a segunda parte da função (x > 0)
plot(x2, f_x2, 'b-', 'LineWidth', 1.5);
% Adiciona rótulos e título ao gráfico
xlabel('x');
ylabel('f(x)');
title('Gráfico da Função f(x) = (61\pix^3 + 927)/x');
grid on;
% Adiciona uma grade ao gráfico
% Limita os eixos para uma melhor visualização, se necessário
% ylim([-5000 5000]);
% Exemplo: Ajuste esses valores conforme a necessidade para ver detalhes
% xlim([-5 5]);
% Exemplo: Ajuste esses valores conforme a necessidadehold off;
% Libera o gráfico
2 Comments
Walter Roberson
on 17 Jun 2025
I formatted your code for you. Please check that I did it properly.
In particular, please check whether you want your xlim and ylim to be commented out.
Walter Roberson
on 17 Jun 2025
I do not understand how this answer relates to the original question? The original question was asking about \hat{u} but your suggested response does not use \hat{u} at all ?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

