Scatter plot in Matlab with x-axis ticks not equidistant -
consider following scatter plot in matlab
a=[1 0 0 0 2 0 0 0 0 0 0 0 1 2 0 0 0 2 1 200 300]'; xrange = 0: max(a); prob=zeros(size(xrange,2),1); r=1:size(xrange,2) prob(r) = sum(ismember(a,xrange(r)))/size(a,1); end scatter(xrange,prob, 'b'); xlim([-2 max(a)+2]) ylim([-0.5 1.5]) i want change way scatter looks in order make more clear: idea put following ticks on x-axis
[-0.5 0 1 2 3 301] but tricky part should equidistant can zoom on part of scatter plot higher values of prob.
any idea?
one way achieve transform data new scale using interpolation. let's want data values
tickval = [-0.5 0 1 2 3 301]; to appear @ graphical positions
tickpos = 0 : 5; determine graphical positions data interpolation, , plot transformed data:
xtransformed = interp1(tickval, tickpos, xrange); scatter(xtransformed, prob, 'b'); xlim([min(tickpos), max(tickpos)]) ylim([-0.5 1.5]) now have make sure ticks not reflect transformed, original data values:
set(gca, 'xtick', tickpos) set(gca, 'xticklabel', num2cell(tickval)) the result looks this:

is want?
Comments
Post a Comment