Matlab figure: The legend replaces the graph completely and there is no graph
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to plot four matrices as a line graph with two y axes, when the legend is added it completely replaces the graph and covers the whole figure. I believe the graph is not even behind the legend. There is just one empty figure with a full-screen legend! not graphs! Same thing happens if I just plot the graph and add the legend manually in the figure wondow. Here is my code and I would be grateful if you could help me fix it.
load('PS1.mat')
load("PS2.mat")
load("PS21.mat")
load("PS22.mat")
figure;
yyaxis left; % Use the left y-axis
plot(PS1, 'DisplayName', 'Scenario 1', 'Color', rand(1,3));
hold on;
plot(PS2(:, 1), 'DisplayName', 'Scenario 2', 'Color', rand(1,3));
plot(PS21, 'DisplayName', 'Scenario 3', 'Color', rand(1,3));
plot(PS22, 'DisplayName', 'Scenario 4', 'Color', rand(1,3));
ylabel('Optimal (h)');
% Adding the second column of D with a second y-axis
yyaxis right; % Use the right y-axis
plot(PS2(:, 2), 'DisplayName', 'Scenario 2', 'Color', rand(1,3));
ylabel('Modules');
% Adding legend
lgd.Position = [0.85, 0.65, 0.1, 0.1];
% Adding x-axis label
xlabel('Demand');
% Display the grid
grid on;
댓글 수: 9
채택된 답변
Walter Roberson
2024년 2월 24일
C:\Users\Elino\OneDrive\Documents\MATLAB\ENCI711\Copy_of_Publish Version\set.m
You need to rename that file, or move it so that it is not on your MATLAB path.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!