how add multiple lines on 2 overlapped plots and brush all

hello, my problem is: I have for examples 4 cell arrays: X1 Y1 X2 Y2. In X1 and Y1 there are the vectors of data (of different lengths) to plot on the left axes. In X2 and Y2 vectors of data to plot in right axes. I have no problem to make it, and link axes together. The problem is that I can't brush all the data that I want. In particular I overlap the right axes to the left one and so I can brush data from the right axes, but not from left axes that are in the bottom. Any suggestion? p.s. I also tryed plotyy, but it seems to work fine with X_vectors of the same length, but not for different ones. I also tryed to make lines and add to the plots, but it seems that i can't brush a line. I'm searching in a lot of documentation, but I can't solve my problem.
thank you marco

 Accepted Answer

X1 = {1:10,5:14};
Y1 = {cos(1:10),rand(10,1)};
X2 = {3:6,1:8};
Y2 = {sin(3:6),rand(1,8)};
numE = numel(X1);
hold on
h = zeros(numE,2);
for s = 1:numE
[ax,h(s,1),h(s,2)] = plotyy(X1{s},Y1{s},X2{s},Y2{s});
end
h containts the handles to the graphic objects for the first axes (first column) and the second axes (second column). You can use it to change color for the objects.
EDIT
The simplest way is to add dummy pointwise coordinates to make the number of series equal, otherwise it becomes messy to set the axes limits and ticks.
An example:
X1 = {1:10};
Y1 = {cos(1:10)};
X2 = {3:6,1:8};
Y2 = {sin(3:6),rand(1,8)};
% Adapt axes1 to have same number of series as axes2:
X1 = [X1 1];
Y1 = [Y1 1];
The trick is to chose dummy coordinates so that the new fake series introduced into axes1 aren't visible.
EDIT 2 Since, you don't want to use plotyy here's the steps to synchronize two axes (as done in plotyy, I simply copied/simplified the relevant steps). NOTE: the order of execution is matters.
% Create the two axes
ax(1) = axes;
ax(2) = axes('units',get(ax(1),'units'),'pos',get(ax(1),'pos'),...
'Parent',get(ax(1),'Parent'));
% Plot all you need
plot(ax(1),1:10,1:10,'r')
plot(ax(2),1:10,10:-1:1,'g')
% Set properties for axes, like ticks colors etc...
set(ax(2),'YAxisLocation','right','Color','none', 'Box','off');
% Point to the other axes reciprocally
setappdata(ax(1),'graphicsPlotyyPeer',ax(2));
setappdata(ax(2),'graphicsPlotyyPeer',ax(1));

3 Comments

By the way, the problem to use plotyy consist in the fact that my cell arrays X1/Y1 and X2/Y2 have in some case different lengths. For example on my left axes I got 2 lines, instead on my right axes I need to put 4 lines. I also need to have a lot of plot in one figure or panel, plotyy seems to create on an existent axes other 2 axes, resetting the tag of the existent axes. I thougth to make a class to make 2 overlapped plots: 1 left, 1 right. It works fine, I can print as many meas I want holdin on the axes, but when I brush i can only brush values that are on the top axes. How can i link the brushing in 2 different axes (I seen an example of linkdata in 2-3-4 subplot, but can't solve problem with axes and not subplot.)
Thank you marco
See edits (especially the second)
second edit is what I was looking for. now I will try it ;)
thank you

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!