Splitting an axis into a linear and log scale

37 views (last 30 days)
Hi,
I'm interested in splitting the x-axis of a plot into a linear section and a log section. For example, I want to plot -1 to 20 on a linear scale then switch to a log scale for 20 to 4500 on the same axis. I've looked into functions like semilog and plotxx, and log log, but I can't find anything that allows me to split the axis into two separate scales.
Thanks a lot, Charles

Accepted Answer

Teja Muppirala
Teja Muppirala on 20 Jun 2013
I don't think there's an easy way to do it, but you might be able to piece together two axes to make it look like its half linear / half log.
x = -1:4500;
y = sin(x/10);
ax1 = subplot(121);
plot(x(x <= 20),y(x <= 20));
ax2 = subplot(122);
plot(x(x >= 20),y(x >= 20));
set(ax1,'units','normalized','position',[0.1 0.1 0.4 0.8]);
set(ax2,'units','normalized','position',[0.5 0.1 0.4 0.8]);
set(ax2,'xscale','log','xlim',[20 5000],'yticklabel','');
set([ax1 ax2],'ylim',[-1.5 1.5],'ytick',-1.5:0.5:1.5,'box','off');
set(ax2,'yticklabel','');
uistack(ax1,'top');
grid(ax1,'on');
grid(ax2,'on');
  1 Comment
Enis Arik
Enis Arik on 10 Dec 2018
Edited: Enis Arik on 10 Dec 2018
I think this script is the best solution for lin/log plots. I am writing my PhD thesis in time-resolved spectroscopy, and ling/log plots are crucial to show kinetic data in a very long time axis. Those kinetic plots give the best visuals when the short time scale (from femtosecond to few picoseconds) is shown in linear axis and long time scale (from picosecond to milliseconds) is in logarithmic. You may need to tweak this script according to your plot. You can either plot graphs side by side or even top/bottom.
It is sad that there is not direct/easy solution for this in matlab, but I guess there is in python. But this requires of course learning a different language.. :)

Sign in to comment.

More Answers (1)

Youssef  Khmou
Youssef Khmou on 20 Jun 2013
Edited: Youssef Khmou on 20 Jun 2013
hi Senaasa,
There must a sophisticated way to produce such arrangement, that method is used in many papers related to geophysics, however i propose to you a manual way to try :
Let us consider the problem that we want represent a sinusoidal function on N=600 points such as 230 is limit between the linear and log scales,
N=600;
T=400; % Number of points on the first interval
x1=linspace(0,230,T);
TT=(N-230)*T/230;
x2=logspace(230,N,TT);
x=[x1 x2];
y=sin(2*pi*x*0.025); % frequency of 0.25Hz
Now the most important part, is to use the plot command without the x axis, if you add the x axis, that will create an entropy in the figure :
figure, plot(y);
title(' Linear AND logarithmic scales merged, break point =230' );
  1 Comment
Senaasa
Senaasa on 20 Jun 2013
Thanks for your response, I was hoping matlab had a built in function to do this kind of plot though.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!