views:

48

answers:

2

I'd like to plot data x & y with errorbars, ebar, and its fit, yfitted, on a semilog plot. This doesn't seem to work:

figure;
hold on;
errorbar(x,y,ebar);
semilogy(x,yfitted);

Instead of semilog plot I get a linear plot. What should I be doing differently?

+2  A: 

try

h = errorbar(x,y,ebar);
set(get(h,'Parent'), 'YScale', 'log')

or

ax = axes();
errorbar(ax, x,y,ebar);
set(ax, 'YScale', 'log');
Marc
sort of works but it screws all of the errorbars up.. e.g. it fails to draw some of the vertical lines
AndyL
As you probably realize, you can't take the log of 0 or a negative number
Marc
+1  A: 

This is what the documentation says.

"If you attempt to add a loglog, semilogx, or semilogy plot to a linear axis mode graph with hold on, the axis mode will remain as it is and the new data will plot as linear"

I would suggest that you just reverse the order of your plotting, that is.

semilogy(x,yfitted);
hold on;
errorbar(x,y,ebar);
Ghaul
I had tried that first. It doesn't actually work. :/
AndyL
I'm on MATLAB R2009a
AndyL
It should work. Are you writing >>figure; >>hold on; before using semilogy? If you do, it wont work. Just write the three lines in my post and you'll get the same result as the answer above.
Ghaul
I got this solution to work on 2010a, so +1, but it's more direct and generalizable to set axis properties directly than to worry about what matlab freezes with the hold command
Marc