Effacer les filtres
Effacer les filtres

Matlab figure: The legend replaces the graph completely and there is no graph

3 vues (au cours des 30 derniers jours)
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 commentaires
Adam Danz
Adam Danz le 26 Fév 2024
Don't forget to formally "accept" the answer :)
Sherwin
Sherwin le 26 Fév 2024
@Adam Danz Thank you so much for the reminder :)

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 24 Fév 2024
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.

Plus de réponses (0)

Catégories

En savoir plus sur Discrete Data Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by