- 3 traces against a primary y axis
- 2 traces against a secondary y axis
I have been using plotyy only to find that when I zoom into
the plot, only one of the traces will zoom.
The other traces stay fully zoomed out at 100% - this is
useless to me !
I need to be able to zoom into the graph and have all
traces zoom at the same time and at the same scale, all
relative to one another.
Theres also a problem when using the 'Data Cursor' tool to
mark data points - the tool will only work on one trace.
Am I doing something wrong or is this the limitation of
plotyy ?
For info, my code for plotyy is shown below:
[AX,H1,H2] = plotyy
(timetrace,InputSpeed,timetrace,ThrottlePedal,'plot');
%AX(1) is primary y axis
%AX(2) is secondary y axis
%H1 is plot against primary y axis
%H2 is plot against secondary y axis
set(H1,'Color','k')
set(H2,'Color','b')
set(get(AX(2),'Ylabel'),'String','Throttle Position (%) /
CSC Position (mm)')
hold;
%plot(timetrace,OutputSpeed,'m','LineWidth',2);
[BX,H3,H4] = plotyy
(timetrace,OutputSpeed,timetrace,CSCPosition,'plot');
%BX(1) is primary y axis
%BX(2) is secondary y axis
%H3 is plot against primary y axis
%H4 is plot against secondary y axis
set(H3,'Color','m')
set(H4,'Color',[0 0.5 0])
set(BX(2),'YColor','b')
set(get(AX(2),'Ylabel'),'String','CSC Position')
plot(timetrace,EngineSpeed,'r','LineWidth',2);
set(AX(1),'YColor','k')
set(AX(2),'YColor','k')
set(BX(1),'YColor','k')
set(BX(2),'YColor','k')
yscale=get(AX(2),'YLim');
set(BX(2),'YLim',yscale);
ytick=get(AX(2),'YTick');
set(BX(2),'YTick',ytick);
Another issue is that when I use plotyy for the second time
(to plot CSCPosition), the secondary y axis becomes
different to the secondary y plotted the first time
(ThrottlePedal).
This is why I have to make the YLim and YTick settings for
the first trace equal to that of the second trace.
But even then the y tick marks are wrong.
There must be an easier and better method of plotting
multiple traces on primary and secondary y axis?
Even excel can do better than this !
> - 3 traces against a primary y axis
> - 2 traces against a secondary y axis
>I have been using plotyy only to find that when I zoom into
>the plot, only one of the traces will zoom.
>The other traces stay fully zoomed out at 100% - this is
>useless to me !
linkaxes() ?
--
"If there were no falsehood in the world, there would be no
doubt; if there were no doubt, there would be no inquiry; if no
inquiry, no wisdom, no knowledge, no genius."
-- Walter Savage Landor
The issues you raise with PLOTYY have been addressed in R2008a. For versions
of MATLAB prior, there is no clean work around for getting ZOOM to work
properly, though there are MATLAB Central File Exchange postings which may
be able to point you in the right direction.
-I hope this helps.
Dan
---
Dan Sternberg
The MathWorks, Inc.
"John Lintern" <john.l...@zeroshift.com> wrote in message
news:fsquh2$nja$1...@fred.mathworks.com...
Dan, does that mean 'linkaxes' wont work either as
suggested by Walter ?
My version of MATLAB is R2007a (version 7.4.0.287)
"Dan Sternberg" <dster...@SPAMmathworks.com> wrote in
message <fsrhgk$al2$1...@fred.mathworks.com>...
No, no, you don't want to go there (Excel). I hear your
frustration with plotyy and looking at your code I see
you are working far to hard with little to show. I find
that plotyy works ok for very simple problems, but gets
cumbersome for more complicated situations, especially
with many traces on each axis. The sparce documentation
for plotyy is a negative factor too. Consider a more
powerful and better documented tool (called plt) available
from the file exchange. For simple calls the syntax is the
same as plot, but has some differences for the more
complicated uses. For example, the 'right' parameter
below tells plt to put the 2nd and 4th traces on the
right hand axis (with all the rest on the left axis).
Try this code which echoes most of the requirements
of the code you provided:
---------------------------------------------
timetrace = 1:50; % some fake data
InputSpeed = 1 + rand(1,50);
OutputSpeed = 4 + rand(1,50);
EngineSpeed = 7 + rand(1,50);
ThrottlePedal = 1 + 40*rand(1,50);
CSCPosition = 70 + 40*rand(1,50);
plotfunc = [InputSpeed; ThrottlePedal;
OutputSpeed; CSCPosition;
EngineSpeed];
traceID = {'InputSpeed'; 'ThrottlePedal';
'OutputSpeed'; 'CSCPosition';
'EngineSpeed'};
plt(timetrace,plotfunc,...
'traceID',traceID,...
'right',[2 4],...
'LineWidth',{1 1 1 1 3},...
'Xlabel','Seconds',...
'Ylabel','Speed',...
'YlabelR','Throttle/CSC position',...
'Position',[10 50 900 600],...
'Title','plt example',...
'Figname','Engine data');
----------------------------------------------
Notice that the legend is provided automatically
and how easy it is to zoom and pan around and to
enable/disable any of the traces. (For help with
that, click on the help tag and read the section
"Using the plt window").
Notice how all 5 traces are effected when you zoom
or pan the x-axis. Pan/zoom of the left axis affects
only the 3 left traces and similar for the right. They
are not linked since in general this flexibility is
needed. Due to a recent request, I've written a 10 line
helper function which links the left and right axes in
the way you seem to want. I'd be happy to email that
function to you, although soon I will add it to the
released version.
If you download plt, I recommend running demo\demoplt.m
to get an idea of some of the things it can do. Then
look at the source for those example programs so you
can borrow the relevant sections for use in your own
applications. The file exchange package provides plt
in pcode form although if you need the .m source, its
available for download from my website (www.mennen.org)
~Paul
However, there seems to be an error in plt.
When I save a figure, then close and reopen it, I get an
error message when I try to close the figure Ive opened.
The error message says....
??? Index exceeds matrix dimensions.
Error in ==> C:\Program
Files\MATLAB\R2007a\toolbox\local\plt\plt.p>plt at 925
??? Error using ==> plt('cursor',17,'clear');delete(findobj
('type','fig','user',gcf));closereq;
Index exceeds matrix dimensions.
??? Error while evaluating figure CloseRequestFcn
.... I cannot even close MATLAB because the same error
message occurs.
The only way I can close MATLAB is to do a CTRL-ALT-DEL and
end the program.
Do you know why this occurs ?
Reopen a figure?
Sorry I wasn't aware that a figure can be closed
and then reopened. Let me know how you tried to do that
and I will look into it.
By the way, normally plt figures can be closed like
any other figure, but if you run into any problems
closing a figure there is a fail safe mechanism.
Just type
> plt close
or if you prefer
> plt('close')
You might want to reply to my real email address to make
sure I see it. My email address is just my name with
a .org at the end: i.e "paul" followed by "@" followed
by "mennen" dot "org". Or an easier way is just type:
> plt help
and then click on "introduction" and then click on my
email address to send me a message.