how add multiple lines on 2 overlapped plots and brush all
12 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Oleg Komarov
on 31 May 2011
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
More Answers (0)
See Also
Categories
Find more on Two y-axis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!