Changing ylim properties of multiple plotyy figures
Mostra commenti meno recenti
Hello,
I am creating multiple figures using plotyy inside a loop. After creating the figures, I want to change the y-limits of some of the figures manually. Figure properties only lets me change ax(1) properties but not ax(2) so I tried setting properties via command line but to no success.
This is my code for creating figures:
for k=1:30
figure(k)
[ax, h1, h2]=plotyy(year, precip.(varnames{k}),year,runoff.(varnames{k}));
set(gca,'NextPlot','add');
drawnow
print('-dtiff','-r200',varnames{k});
hold off
end
I then tried changing y-limits of ax(2) using this command:
figure(7),set(ax(2),'ylim',[200 700]);
But receive this error: ??? Error using ==> set Invalid handle object.
A few times matlab did run the command without producing an error but did not actually change the limits. I was wondering if you could show me how to get matlab to remember the axis handles I set when creating each figure so I can use them to change figure properties afterwards? Or another way to change plotyy properties after creating the figures? many thanks!
Risposta accettata
Più risposte (2)
Azzi Abdelmalek
il 25 Mar 2013
Try
figure(7),
ax=gca,
set(ax(2),'ylim',[200 700]);
2 Commenti
Anna
il 25 Mar 2013
Walter Roberson
il 25 Mar 2013
gca cannot return both ax, as only one axis can be the current axis.
Nicolò Cogno
il 15 Mag 2019
Modificato: Nicolò Cogno
il 15 Mag 2019
Hi,
I would also suggest trying this:
figure(1), ax=gca;
set(ax.YAxis(1),'Limits',[0 1]);
set(ax.YAxis(2),'Limits',[0 1]);
1 Commento
Walter Roberson
il 19 Mag 2019
Note these did not exist at the time the question was originally asked ;-)
Categorie
Scopri di più su Two y-axis 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!