Legend command does not distinguish the colours specified in the plot command
조회 수: 2 (최근 30일)
이전 댓글 표시
Here is my code. The signals are send from the Simulink to the workspace and the save format is ' Structure with time' . The code does displays the plot but in the legend first three Machines are shown with same red colour and the fourth machine i.e. Machine 19 is depicted by blue colour. Can anyone help me correct this?
figure
plot(Vpu_15.time, Vpu_15.signals.values,'r')
hold on
plot(Vpu_16.time, Vpu_16.signals.values,'b')
hold on
plot(Vpu_17.time, Vpu_17.signals.values,'g')
hold on
plot(Vpu_19.time, Vpu_19.signals.values,'k')
hold off
xlabel('Time (s)')
ylabel('Voltage (pu)')
title('Machine Voltages')
legend('Machine 15', 'Machine 16', 'Machine 17', 'Machine 19')
legend('TextColor', 'black')
댓글 수: 5
Aakash
2023년 6월 23일
Can you share your variables 'Vpu_5, Vpu_16, Vpu_17, Vpu_19' which you told are stored in the MATLAB Workspace.
You can refer to this link on how to save your variables: https://www.mathworks.com/help/matlab/matlab_env/save-load-and-delete-workspace-variables.html. Then share as attachments
채택된 답변
Walter Roberson
2023년 6월 23일
The code does displays the plot but in the legend first three Machines are shown with same red colour and the fourth machine i.e. Machine 19 is depicted by blue colour.
We can predict that Vpu_15.signals.values has three columns, so
plot(Vpu_15.time, Vpu_15.signals.values,'r')
is creating three lines, all of them colored red.
legend() matches to graphic objects not to the number of times that graphics functions are called. graphics functions can create multiple graphics objects in one call.
Work-around:
figure
h1 = plot(Vpu_15.time, Vpu_15.signals.values,'r');
hold on
h2 = plot(Vpu_16.time, Vpu_16.signals.values,'b');
hold on
h3 = plot(Vpu_17.time, Vpu_17.signals.values,'g');
hold on
h4 = plot(Vpu_19.time, Vpu_19.signals.values,'k');
hold off
xlabel('Time (s)')
ylabel('Voltage (pu)')
title('Machine Voltages')
legend('Machine 15', 'Machine 16', 'Machine 17', 'Machine 19')
legend([h1(1); h2(1); h3(1); h4(1)], 'TextColor', 'black')
댓글 수: 4
Walter Roberson
2023년 6월 23일
figure
h1 = plot(Vpu_15.time, Vpu_15.signals.values,'r');
hold on
h2 = plot(Vpu_16.time, Vpu_16.signals.values,'b');
hold on
h3 = plot(Vpu_17.time, Vpu_17.signals.values,'g');
hold on
h4 = plot(Vpu_19.time, Vpu_19.signals.values,'k');
hold off
xlabel('Time (s)')
ylabel('Voltage (pu)')
title('Machine Voltages')
legend([h1(1); h2(1); h3(1); h4(1)], {'Machine 15', 'Machine 16', 'Machine 17', 'Machine 19'}, 'TextColor', 'black');
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!