Plot disappears after axes command
34 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Joakim Magnusson
il 26 Lug 2016
Commentato: Joakim Magnusson
il 27 Lug 2016
I have a GUI where i plot two curves in the same figure. later in the program i want to plot a third curve in the same figure. To do so i first choose that figure to plot in with the axes command. When i do so one of the previous curves disappears and i can't understand why. Someone who knows?
7 Commenti
Adam
il 27 Lug 2016
Are you using R2016a or later? If so the help appears to now say that plotyy is "not recommended", although it doesn't say why. It says you should use 'yyaxis' instead, which is a newer function.
Stephen23
il 27 Lug 2016
Modificato: Stephen23
il 27 Lug 2016
Actually the axes documentation does describe one syntax which lets you provide an axes handle and it will make those axes the current axes: " axes(h) makes existing axes h the current axes and brings the figure containing it into focus"
However I would advise against using this in serious code, and instead always explicitly specify the axes in every plot function:
plotyy(axh,...)
Almost all plot functions support this, and it is ultimately much simpler and much more robust. It prevents users' clicking from changing the behavior of your code!
Risposta accettata
Joakim Magnusson
il 27 Lug 2016
2 Commenti
Adam
il 27 Lug 2016
plotyy, in common with all main plotting functions (possibly some older ones in toolboxes are exceptions, I'm not sure), has an overload that takes an explicit axes handle as its first argument.
I would strongly recommend to always use this form rather than trying to set which axes is in focus and then plotting with that as an assumption. Often that works fine, but if, for example, the user is able to click on a UI or bring a different figure into focus while the code is running this can lead to unexpected results.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Two y-axis in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!