Splitting an axis into a linear and log scale

43 Ansichten (letzte 30 Tage)
Senaasa
Senaasa am 20 Jun. 2013
Bearbeitet: Enis Arik am 10 Dez. 2018
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

Akzeptierte Antwort

Teja Muppirala
Teja Muppirala am 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 Kommentar
Enis Arik
Enis Arik am 10 Dez. 2018
Bearbeitet: Enis Arik am 10 Dez. 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.. :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Youssef  Khmou
Youssef Khmou am 20 Jun. 2013
Bearbeitet: Youssef Khmou am 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 Kommentar
Senaasa
Senaasa am 20 Jun. 2013
Thanks for your response, I was hoping matlab had a built in function to do this kind of plot though.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by