Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Problem with text in legend of figure file generated through plot command

1 visualización (últimos 30 días)
Shahid Rehman
Shahid Rehman el 6 de En. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
When i get a figure file by using plot command everything is right but when I try to replace the legend default text to what I want to label it, the text which I key in through my keyboard is changed to some other text. I closed and open the matlab again but still same problem.
  2 comentarios
Mohammad Sami
Mohammad Sami el 6 de En. de 2020
Can you include some details about your code and output.
Adam Danz
Adam Danz el 6 de En. de 2020
Why not specify the legend labels programmatically in your call to legend() or by using the DisplayName property of plot objects?

Respuestas (1)

Meg Noah
Meg Noah el 7 de En. de 2020
Here's an example:
clc
close all
clear all
% fake data
f = -pi:0.01:pi;
y1 = sin(2.*f + pi/3) + 0.05*rand(size(f));
y2 = sin(3.*f + pi/2) + 0.05*rand(size(f));
y3 = sin(2.5.*f + 0) + 0.05*rand(size(f));
y4 = sin(0.75.*f + pi/6) + 0.05*rand(size(f));
% code
figure;
l1 = plot(f, y1, 'r','DisplayName','My Data 1');
hold on
l2 = plot(f, y2, 'color', [0.8 0.7 0],'DisplayName','My Data 2');
l3 = plot(f, y3, 'b','DisplayName','My Data 3');
l4 = plot(f, y4, 'color', [0 0.75 0],'DisplayName','My Data 4');
hleg = legend('location','best');
hold off
xlabel('xdata [radians]');
ylabel('ydata');
ylim([-1.2 1.2]);
xlim([-pi pi]);
title('just some random data');
% rename the data, change text properties
hleg.String = {'Random 1','Random 2','Random 3','Random 4'};
hleg.FontName = 'Ariel';
hleg.FontSize = 12;
hleg.FontWeight = 'bold';

La pregunta está cerrada.

Etiquetas

Productos


Versión

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by