realtime plot, y axes overlapping

4 views (last 30 days)
Vincent I
Vincent I on 28 Jun 2012
Hi,
the first time when the plot/s is created is fine. When i change the y values and axes start to overlap. I've tried everything but i'm unable to clear the old axes.what do i have to do to make the code down below look nice and pretty? Thank you
function addaxis(hObject, eventdata, handles,varargin)
%ADDAXIS adds an axis to the current plot
handles.output = hObject;
guidata(hObject, handles);...
% get current axis
axes(handles.Axes1)
set(gca,'Units','pixels');
cah=gca;
axesPosition = get(cah,'position'); %# y axes spacing, in pixels
yWidth = 30; %# Range of x values
x=evalin('base','t');
xLimit = [min(x) max(x)];
xOffset = -yWidth*diff(xLimit)/axesPosition(3);
%# Create the axes:
handles.Axes1 = axes('Units','pixels','Position',axesPosition,...
'Color','w','XColor','k','YColor','r','ylim',[-inf inf],...
'XTick',[],'XLim',xLimit,'NextPlot','add');
handles.Axes1 = axes('Units','pixels','Position',axesPosition+yWidth.*[-1 0 1 0],...
'Color','none','XColor','k','YColor','m',...
'XLim',xLimit+[xOffset 0],'YLim',[-inf inf],...
'XTick',[],'XTickLabel',[],'NextPlot','add');
handles.Axes1 = axes('Units','pixels','Position',axesPosition+yWidth.*[-2 0 2 0],...
'Color','none','XColor','k','YColor','b',...
'XLim',xLimit+[2*xOffset 0],'YLim',[-inf inf],...
'XTick',[],'XTickLabel',[],'NextPlot','add');
%# Plot the data:
plot(handles.Axes1,evalin('base','t'),evalin('base','y1'),'r');
plot(handles.Axes1,evalin('base','t'),evalin('base','y2'),'m');
plot(handles.Axes1,evalin('base','t'),evalin('base','y3'),'b');

Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!