Effacer les filtres
Effacer les filtres

Using a second call to copyobj is not working

2 vues (au cours des 30 derniers jours)
Bill
Bill le 11 Mai 2018
Commenté : Bill le 11 Mai 2018
I'm copying the left axis of a plot over to its right side, making a change to the left axis, and then trying to recopy those changes over to the right side. But I can't get the right axis to clear before copying the new changes over. I've tried clearing the right axis, and also setting the Cax.Right.YTick and Cax.Right.YTickLabel directly, but none of those attempts worked. Thanks!
x=1:10;
y=1:10;
plot(x,y)
Cax.Left = gca;
Cax.Right = copyobj(Cax.Left, gcf);
Cax.Right.YAxisLocation = 'Right';
Cax.Left.YLim = [0,20];
Cax.Right = copyobj(Cax.Left, gcf);
Cax.Right.YAxisLocation = 'Right';
  2 commentaires
Jan
Jan le 11 Mai 2018
Modifié(e) : Jan le 11 Mai 2018
"Is not working" is a weak description of the problem. Prefer to explain, what you observe instead: an error message or does the result differ from your expectation?
You do not copy the "left axis", but the complete axes object. The copied object let not vanish the formerly existing object, such that the figure contains 2 axes objects at the end. There might be a more direct way to produce, what you want to achieve.
Bill
Bill le 11 Mai 2018
Hi Jan. That's a fair critique of the title of my question, although I did try to be more detailed in the actual question. Nevertheless I wanted to thank you because your comment helped me solve the issue. Putting in the line of code:
delete(Figure.Children(2));
prior to calling copyobj the second time worked. So, thanks!.. - Bill

Connectez-vous pour commenter.

Réponses (1)

Steven Lord
Steven Lord le 11 Mai 2018
If you want an axes with rulers on both the left and right, you should use yyaxis. If you're using a release that predates the introduction of yyaxis in release R2016a, use plotyy.

Catégories

En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange

Tags

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by