Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 1 (최근 30일)
Shahid Rehman
Shahid Rehman 2020년 1월 6일
마감: MATLAB Answer Bot 2021년 8월 20일
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
Mohammad Sami
Mohammad Sami 2020년 1월 6일
Can you include some details about your code and output.
Adam Danz
Adam Danz 2020년 1월 6일
Why not specify the legend labels programmatically in your call to legend() or by using the DisplayName property of plot objects?

답변 (1개)

Meg Noah
Meg Noah 2020년 1월 7일
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';

이 질문은 마감되었습니다.

태그

제품


릴리스

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by