Single non-linear x axis in figure

I have the following data set of deformation over time (first figure). A lot of the deformations are occuring during the first day, which I would like to more emphasis to by a piecewise linear time scale on the x axis, see my sketch below (second figure).
I would love if someone could show me how this can be done!
untitled.png
DSC_0043.JPG

Answers (2)

Ok, so here's a brute solution to my problem. Geuss there's a more elegant way, but this should work.
t %x values (time)
y %y values (deformations)
tSplitPoint = 1; %Data point at which axis is to change
tScaleShift = 5; %Point on x axis to change scale (aesthetics, trial-n-err)
% Dirty manipulation of time data to fit two linear scales
tModOver = t(t>tSplitPoint)+tScaleShift-tSplitPoint;
tModUnder = t(t<tSplitPoint).*tScaleShift;
tMod = [tModUnder; tSplitPoint*tScaleShift; tModOver];
% Insert interpolated y @ tSplitPoint for sharp angle correction in plot
idxChange = find(t>tSplitPoint,1,'first');
yPoint = interp1(t,y,tSplitPoint,'linear');
yMod = [y(1:idxChange-1); yPoint; y(idxChange:end)];
figure
hPlot=plot(...
t,y,...
tMod,yMod,...
[tScaleShift tScaleShift],[0 0.4],':');
xticks([0 0.5*tScaleShift tScaleShift:5:25+tScaleShift])
set(gca,'xticklabel',num2str([0 0.5 1 5:5:25]'));
axis([0 25+tScaleShift 0 0.55]);
yticks([0 0.2 0.4 0.6])
legend('Original','Modified','tScaleShift','Location','se')
untitled.png
Read about xlim. Read about axis. Also you can pick your required data using logicals.
Let t,y be your data.
idx = t<5 ;
t1 = t(idx) ;
y1 = y(idx);
plot(t1,y1)

3 Comments

Thanks for your prompt reply.
However, I fail to see how I can manipulate the axis. I regard xlim as another way to limit the axis boundaries, similar to axis. It is not the limits that are of interest here, rather manipulating a linear x axis to become piecewise linear at a given value (here 1 day).
I can manipulate the axis to some extent using the following, but not as flexible as I would like.
t=[linspace(0,1,10) linspace(2,10,10)];
y=linspace(0,10,length(t));
figure
plot(y)
set(gca,'XTick',1:length(t))
set(gca,'xticklabel',num2str(t.'));
have a look on interp1
Again I fail to see the connection to the plot axis. How can interpolation of the data set manipulate the axis?

Sign in to comment.

Categories

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

Asked:

on 5 Feb 2019

Answered:

on 5 Feb 2019

Community Treasure Hunt

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

Start Hunting!