MATLAB: Log scale graphic with negative value

lognegative

I want to plot a graphic with data that varies over many order (from 10e-4 to 10e-8) with some positive and negative values. Using 'semilog' or 'set xaxis log' can't plot my negative values (witch is normal). When I plot with a normal scale, we don't really see the variability of my datas, we only see the very high values and all the small one are not very visible because there are to close to zero. What would you suggest me to be able to show all my data (even the negative values) and be able to show the variability (like on a log-scale graph). Thank you

Best Answer

Oookay, I think I have it. If you're going to do this a lot, you may want to make yourself your own function. So, see if this does it for you:
function negsemilogx(x,y)
% Do log10 but keep sign
xlog = sign(x).*log10(abs(x));
% Just to get axis limits
plot(xlog,y,'o')
% Get limits
lims = xlim;
wdth = diff(lims);
% Wrap negative data around to positive side
xlog(xlog<0) = xlog(xlog<0) + wdth;
% Plot
plot(xlog,y,'o')
% Mess with ticks
tck = get(gca,'XTick')';
% Shift those that were wrapped from negative to positive (above) back
% to their original values
tck(tck>lims(2)) = tck(tck>lims(2)) - wdth;
% Convert to string, then remove any midpoint
tcklbl = num2str(tck);
tcklbl(tck==lims(2),:) = ' ';
% Update tick labels
set(gca,'XTickLabel',tcklbl)
Then to try it out:
>> x = -100:100;
>> y = x.^3;
>> negsemilogx(x,y)