physics_for_all
physics_for_all

Reputation: 2263

Matplotlib negative axis

I want to fit y=mx+c straight line to my data points, but in log form. For this purpose I am using curve_fit module. My simple code is

def func(x,m,c):
  return (x*m + c)
x=log10(xdata)
y=log10(ydata)
err=log10(error)
coeff, var = curve_fit(func,x,y,sigma=err)
yfit = func(x,coeff[0],coeff[1])
pl.plot(x,y,'r0')
pl.plot(x,yfit,'k-')
pl.show()

This plot gives me negative numbers on y axis as my y values are in mV. Is there any way to use original xdata and ydata (in mV) on plots with log fitting?

Upvotes: 1

Views: 1491

Answers (1)

periphreal
periphreal

Reputation: 111

Plot transformed variables instead.

plot(10**x, 10**yfit, 'k-')

and maybe display the plot in log scale

set_yscale('log')

Upvotes: 1

Related Questions