Drawing a line without creating a legend entry
Mostra commenti meno recenti
In the MWE below, the green line shows up as the second row of the legend box. I want to be able to draw lines and incrementally build the legend as illustrated, but without having the line enter into the legend as it does in this example. Obviously, if I do all the plots before drawing the lines, and then use AutoUpdate off, I can accomplish this, but sometimes I need to intersperse lines and plots as in the example.
Is there any way to do this?
close all ; hold on;plot(1:10);Legend = {'line 1'};h=line([1,10],[6,6],'Color','g');hold on;plot(10:-1:1);Legend=[Legend,'line 2'];legend(Legend)
Risposta accettata
Più risposte (1)
Carlos Alberto Diaz Galindo
il 16 Feb 2023
Modificato: Walter Roberson
il 13 Mar 2024
I think it's easier this way
plot(x1,y1)
hold on
plot(x2,y2)
h = legend('a','b')
h.AutoUpdate = 'off'
hold on
plot(x3,y3)
1 Commento
Cédric Cannard
il 13 Mar 2024
This is perfect, thanks!
Categorie
Scopri di più su Legend in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!