Splitting an axis into a linear and log scale
조회 수: 23 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
Teja Muppirala
2013년 6월 20일
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
Enis Arik
2018년 12월 10일
편집: Enis Arik
2018년 12월 10일
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.. :)
추가 답변 (1개)
Youssef Khmou
2013년 6월 20일
편집: Youssef Khmou
2013년 6월 20일
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' );
참고 항목
카테고리
Help Center 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!