简体   繁体   English

Matplotlib Semilog最佳拟合图线

[英]Matplotlib semilog plot line of best fit

Below (blue dashed line) is what I get when I try to do linear regression on my data. 下面(蓝色虚线)是我尝试对数据进行线性回归时得到的结果。 It looks very off (but maybe it's correct?) Here is the image (does not allow me to embed): 它看起来很不正常(但也许是正确的吗?)这是图片(不允许我嵌入):

http://i.imgur.com/KiprZDB.png

and here is the code: 这是代码:

mm, cs, err = get_cols(data)
a = np.asarray(mm, dtype=float)
b = np.asarray(cs, dtype=float)
ax.errorbar(a, b, xerr=None, yerr=err, fmt='o', c='b', label='Detection Rate')
logB = np.log10(b)
m, y0 = np.polyfit(a, logB, 1)
ax.plot(a, np.exp(a*m+y0), '--')

The log scale of matplotlib uses the logarithm of base 10 by default. 默认情况下,matplotlib的对数刻度使用以10为底的对数。 It therefore makes sense to use np.log10(b) to transform the data for fitting. 因此,使用np.log10(b)转换数据以进行拟合是有意义的。

However, once fitting is done, the data needs to be backtransformed using the inverse of the transformation function. 但是,一旦拟合完成,就需要使用变换函数的逆函数对数据进行逆变换。

In case of y = log10(x) the inverse is x = 10**(y) , while y = log10(x)的情况下,逆为x = 10**(y) ,而
in case of y = log(x) the inverse is x = exp(y) . 如果y = log(x)则逆为x = exp(y)

So you need to decide for one of the cases. 因此,您需要确定其中一种情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM