MATLAB: Splitting an axis into a linear and log scale

axesplotting

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

Best Answer

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');