2

I have the following data sets to plot:

data1 = [ 3 6 99 4 5];
data2 = [ 0.2 1.5 1.75 1.0 1.2];

What's peculiar about my situation is that I need data point data1(3), which is equal to 99, not show up on the graph. I'm using 99 as a way of pushing observations outside the desired axis limits so that there are no visible observations for certain values of the independent variable. (I'm plotting the data points with markers only, no lines.)

While data1 and data2 have totally unrelated scales and meanings, they share the exact same dependent variable:

X=40:1:44

I'm plotting with the following commands, which I derived from the MATLAB plotyy documentation page:

[AX,H1,H2] = plotyy(X,data1,X,data2);

set(get(AX(1),'Ylabel'),'String','This is vertical axis 1') 
set(get(AX(2),'Ylabel'),'String','This is vertical axis 2')     

set(H1,'LineStyle','none','Marker','*');
set(H2,'LineStyle','none','Marker','s');

So far, so good. What I cannot figure out is how to enforce the correct limits on both of the vertical axes. My desired limits are:

ylimits1=[0 3]
ylimits2=[0 10]

How can I set limits for each vertical axis?


I have tried this

set(get(AX(1),'Ylim'),ylimits1) 
set(get(AX(2),'Ylim'),ylimits2) 

and

foo = gca
set(foo(1),'ylim',ylimits1);
set(foo(2),'ylim',ylimits2);

but neither work.

4

2 回答 2

1

以下应该有效:

[AX,H1,H2] = plotyy(X,data1,X,data2);

set(AX(1),'ylim',ylimits1);
set(AX(2),'ylim',ylimits2); 
于 2013-09-29T17:01:53.973 回答
0

你可以做的其他一些随机的事情

x1 = 1:10
y1 = x1.^2
x2 = 10:120
y2 = sin(x2)
[AX,~,~] = plotyy(x1,y1,x2,y2);
set(get(AX(1),'Xlabel'),'String','both plots')
set(get(AX(2),'Ylabel'),'String','plot 2') 
set(AX(1),'YLim',[1  25],'YTick',7:23)
于 2014-03-07T03:47:15.663 回答