Matlab: Indicate on a plot when data is off the plot? -


is there way have mark on plot axis data points off current plot in matlab? great if method works zoom , pan, can live without it.

i have several data sets plotting using subplots. each plot contains 20 data points, similar marking darts landed on dart board. data sets, these plots within standard range, ie size of dart board, using standard axis range of each plot make subplots visually comparable. however, few data sets have outlier outside standard range (typically way outside). not want change axis show outlier, want user aware there 1 or more data points off plot, , preferably in direction off.

i thought bit trying use axis markers (set(gca, 'ytick', xlowerlimit: markspacing: xupperlimit)) , adding marker in different color indicate location of outlier, couldn't see how without disrupting regular markers , in automated way allow multiple outlier marks.

edit: see bottom improved method using callbacks.

you can find data points exceeding axes limits , draw them on limits, using different symbols:

a = randn(20, 2);  x_range = [-1.5, 1.5]; y_range = [-1.5, 1.5];  figure(1); clf; ah = axes; plot(ah, a(:,1), a(:,2), 'o') hold on set(ah, 'xlim', x_range, 'ylim', y_range)  x_lt = a(:,1) < x_range(1); x_gt = a(:,1) > x_range(2); y_lt = a(:,2) < y_range(1); y_gt = a(:,2) > y_range(2);  a_out = a; a_out(x_lt, 1) = x_range(1); a_out(x_gt, 1) = x_range(2); a_out(y_lt, 2) = y_range(1); a_out(y_gt, 2) = y_range(2); a_out = a_out(x_lt | x_gt | y_lt | y_gt, :); plot(ah, a_out(:,1), a_out(:,2), 'rx') 

this produces plot this:

example plot outliers

edit: add callbacks

if want go fancy, can add callbacks outliers automatically drawn (and removed) when figure zoomed. adding same functionality panning left exercise reader ;)

mark_outliers.m:

function mark_outliers(fig, ax) ah = ax.axes; lobj = findobj(ah, 'type', 'line'); x_range = ah.xlim; y_range = ah.ylim; ah.nextplot = 'add'; i_l = 1:numel(lobj)     xd = lobj(i_l).xdata;     yd = lobj(i_l).ydata;     x_lt = xd < x_range(1);     x_gt = xd > x_range(2);     y_lt = yd < y_range(1);     y_gt = yd > y_range(2);     outliers = x_lt | x_gt | y_lt | y_gt;     if any(outliers)         xd_out = xd;         xd_out(x_lt) = x_range(1);         xd_out(x_gt) = x_range(2);         yd_out = yd;         yd_out(y_lt) = y_range(1);         yd_out(y_gt) = y_range(2);         xd_out = xd_out(outliers);         yd_out = yd_out(outliers);          plot(ah, xd_out, yd_out, 'xr', 'tag', 'outliers')     end end 

delete_outliers.m:

function delete_outliers(fig, ah)     ah = ah.axes;     delete(findobj(ah, 'tag', 'outliers')); 

example.m:

a = randn(20, 2);  fh = figure(1); clf; ah = axes; plot(ah, a(:,1), a(:,2), 'o')  h = zoom(fh); h.actionprecallback=@delete_outliers; h.actionpostcallback=@mark_outliers; 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -