Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

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

1 vue (au cours des 30 derniers jours)
Shahid Rehman
Shahid Rehman le 6 Jan 2020
Clôturé : MATLAB Answer Bot le 20 Août 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 commentaires
Mohammad Sami
Mohammad Sami le 6 Jan 2020
Can you include some details about your code and output.
Adam Danz
Adam Danz le 6 Jan 2020
Why not specify the legend labels programmatically in your call to legend() or by using the DisplayName property of plot objects?

Réponses (1)

Meg Noah
Meg Noah le 7 Jan 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';

Cette question est clôturée.

Tags

Produits


Version

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by