From: dpb on
Ken Kemal wrote:
> If you don't do figure and it will overwrite the current one.
> I removed figure, hold on and hold off and made no difference...
> I think there might be something that I am missing.
....

Walter points out one thing I overlooked/forgotted...

The sequence below works here...

>> ax=plotyy(1:10,y,1:10,x)
ax =
99.0009 101.0055
>> gca
ans =
99.0009 % simply checking on which is gca after plotyy()
>> hold on; scatter(1,y(1),'o') % this works on ax(1) (lh axis)
>> axes(ax(2));hold on;scatter(3,x(3)) % now do rh axis

I've an older version that doesn't support the optional axis argument to
scatter() hence the axes() call; you can use whichever option your
version supports, obviously.

--
From: jens on
"Ken " <kk61(a)cornell.edu> wrote in message <hoi6as$tt$1(a)fred.mathworks.com>...
> Thanks Walter,
>
> Yes I have tried it. The problem I am having now with:
>
> hold(ax2, 'on');
> scatter(ax2, x(1), y1(1), '*');
>
> It changes the entire the second graph(x, y2) to '*', not just (x(1), y1(1)).
>
> How do I fix it?
>
> Thanks,
>
> -ken
>
>
>
> Walter Roberson <roberson(a)hushmail.com> wrote in message <hoi4rh$sor$1(a)canopus.cc.umanitoba.ca>...
> > Ken wrote:
> >
> > > ax1 = gca;
> > > hl1 = line(x,y1,'Color','b');
> > >
> > > hl3 = line(x, y2,'Color','r','Marker', '*','Parent',ax1);
> > > set(ax1,'XColor','b','YColor','b');
> > >
> > > ax2 = axes('Position',get(ax1,'Position'),...
> > > 'XAxisLocation','top',...
> > > 'YAxisLocation','right',...
> > > 'Color','none',...
> > > 'XColor','k','YColor','k');
> >
> > hold(ax2, 'on')
> >
> > > scatter(ax2, x(1), y1(1));
> > >
> > > but the problem is that the scatter plot erases the graph(x, y2) which
> > > is I don't want.

Hi Ken

I think I have the same problem as you, but instead of scatterplots my problem is with double bar plots. I cannot get the standard deviation to be shown on each bar. Have you found a solution on your problem? My code is shown under. input3(x2,y2,x,y) is a function that create the bars. I cannot get the standard deviation to be shown on the blue bars.

Best Regards

Jens

x=1:3
x2=4:6
y1=[10 20 30]
y2=[200 300 300]
y=[y2 y1]

e1=[1 3 4]
e2=[10 20 10]
std=[1 2 3 10 20 20]

[AX,H1,H2]=plotyy(x,y1,x+length(x),y2,input3(x2,y2,x,y))%input1(x,y1,e1),input2(x2,y2,e2))
hold on

Max=round(max(y1))+5
Max1=round(max(y2))+50
ylim(AX(1), [0 Max]);
ylim(AX(2), [0 Max1]);
set(H1,'FaceColor','g');
set(H2,'FaceColor','b');
set(AX(1),'YColor','g')
set(AX(2),'YColor','b')
set(AX,'XGrid','on')
set(AX,'YGrid','on')



function [f5,f6]=input3(x2,y2,x,y)


f5 = @(x2, y2) bar(x2, y2,0.6,'group');
%f4=@(x2,y2,e2) errorbar(x2,y2, e2)

f6 = @(x, y) bar(x, y1,0.6,'group');

end
From: Ken Kemal on
Do this:

data1 = [shell bp wti];
data2 = [dji];

ts1 = timeseries(data1,datePassed);
ts2 = timeseries(data2,datePassed);
plotyy(ts1.Time,ts1.Data,ts2.Time,ts2.Data);

It solved my problem.

"someone" <someone(a)somewhere.net> wrote in message <hofrvh$8km$1(a)fred.mathworks.com>...
> "Ken " <kk61(a)cornell.edu> wrote in message <hofod6$rqn$1(a)fred.mathworks.com>...
> > Hi,
> >
> > Essentially what I want to do is to plot those y1, y2 vars with the same x axes, and then plot some points on each of the y1 and y2 graphs, I have the following plotyy...
> >
> > [ax, h1, h2] = plotyy(x,y1, x,y2);
> > but then the scatter plot with points '*' on top of both plots produce new graph which I don't want. I only want plots on the the same graph.
> >
> > I have seen such graphs with Matlab before, but I don't know how to do it.
> > Can you tell me how to do it?
> >
> > Thanks,
> >
> > -ken
>
> If I understand, maybe you need to use:
>
> hold on
>
> before you plot the '*' points.
>
> Otherwise, I suggest you show us some of your code.
From: jens on
"Ken Kemal" <kk61(a)cornell.edu> wrote in message <hqh54l$bv$1(a)fred.mathworks.com>...
> Do this:
>
> data1 = [shell bp wti];
> data2 = [dji];
>
> ts1 = timeseries(data1,datePassed);
> ts2 = timeseries(data2,datePassed);
> plotyy(ts1.Time,ts1.Data,ts2.Time,ts2.Data);
>
> It solved my problem.
>
> "someone" <someone(a)somewhere.net> wrote in message <hofrvh$8km$1(a)fred.mathworks.com>...
> > "Ken " <kk61(a)cornell.edu> wrote in message <hofod6$rqn$1(a)fred.mathworks.com>...
> > > Hi,
> > >
> > > Essentially what I want to do is to plot those y1, y2 vars with the same x axes, and then plot some points on each of the y1 and y2 graphs, I have the following plotyy...
> > >
> > > [ax, h1, h2] = plotyy(x,y1, x,y2);
> > > but then the scatter plot with points '*' on top of both plots produce new graph which I don't want. I only want plots on the the same graph.
> > >
> > > I have seen such graphs with Matlab before, but I don't know how to do it.
> > > Can you tell me how to do it?
> > >
> > > Thanks,
> > >
> > > -ken
> >
> > If I understand, maybe you need to use:
> >
> > hold on
> >
> > before you plot the '*' points.
> >
> > Otherwise, I suggest you show us some of your code.

Thank you very much for your help Ken

Maybe you could show an example where you plot some points on each of the y1 and y2 graphs?
For me it is a bit unclear how I pass my standard deviations

errorbar(1:6,[y1 y2],std(1:6),'+k') to the bar plots:

f5 = @(x2, y2) bar(x2, y2,0.6,'group');

f6 = @(x, y) bar(x, y1,0.6,'group');

Best Regards

Jens