How do I add a key to my plot?

131 vues (au cours des 30 derniers jours)
Chester Rosie
Chester Rosie le 23 Fév 2022
Modifié(e) : Voss le 23 Fév 2022
My plot has four variables in it (x1,y1,x2,y2) representing two EN coordinates. How do I add a key to show which is which?
Also, it would be useful if I could ensure the x and y had the same scale (but not a fixed scale).
  1 commentaire
DGM
DGM le 23 Fév 2022
You mean legend()?
For the second part, can you use axis equal or axis square? If not, you'll need to clarify what you want.

Connectez-vous pour commenter.

Réponse acceptée

Voss
Voss le 23 Fév 2022
Modifié(e) : Voss le 23 Fév 2022
To add a key showing which line is which, you can use legend().
To ensure the same x- and y-scale, you can use axis equal.
figure();
% random data with different y-scales
line_x1 = plot(randn(1,10),4*randn(1,10));
hold on
line_y1 = plot(randn(1,10),3*randn(1,10));
line_x2 = plot(randn(1,10),2*randn(1,10));
line_y2 = plot(randn(1,10),randn(1,10));
% equal x- and y-scale
axis equal
% make a line key (a.k.a. legend)
names = {'x1','y1','x2','y2'};
legend([line_x1 line_y1 line_x2 line_y2],names);

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by