필터 지우기
필터 지우기

Changing ylim properties of multiple plotyy figures

조회 수: 2 (최근 30일)
Anna
Anna 2013년 3월 25일
댓글: Walter Roberson 2019년 5월 19일
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!

채택된 답변

Walter Roberson
Walter Roberson 2013년 3월 25일
You are overwriting ax each time through your loop, so it no longer refers to figure 7's ax.
findobj(7,'type','axis')
would get you both axis of figure 7; you would have to figure out which is which (perhaps by examining which side the label is set to be drawn on.)
  댓글 수: 2
Anna
Anna 2013년 3월 26일
Hi Walter, I tried this (and a few variations of it) but it returns an empty matrix. It does bring up the correct figure but I guess it can't find any axes for it. Do you have any other ideas what I could try? cheers
Walter Roberson
Walter Roberson 2013년 3월 26일
Ah, try with
findobj(7,'type','axes')

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 3월 25일
Try
figure(7),
ax=gca,
set(ax(2),'ylim',[200 700]);
  댓글 수: 2
Anna
Anna 2013년 3월 25일
I tried this but gca only returns one axis (ax(1)) and when I try setting ylim for ax(2) I get an error message saying ??? Index exceeds matrix dimensions. Do you know how I can get gca to return both ax(1) and ax(2)?
Walter Roberson
Walter Roberson 2013년 3월 25일
gca cannot return both ax, as only one axis can be the current axis.

댓글을 달려면 로그인하십시오.


Nicolò Cogno
Nicolò Cogno 2019년 5월 15일
편집: Nicolò Cogno 2019년 5월 15일
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
Walter Roberson
Walter Roberson 2019년 5월 19일
Note these did not exist at the time the question was originally asked ;-)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by