import numpy as numpy from astropy.io import ascii import matplotlib.pyplot as plt from BayesicFitting import PolynomialModel from BayesicFitting import Fitter from BayesicFitting import formatter as fmt
tbl = ascii.read( "data/temp-rijn.txt" ) jr = tbl['Jaar'].data te = tbl['gemiddelde'].data jr -= 1900
mdl = PolynomialModel( 2 ) print( mdl )
Polynomial: f( x:p ) = p_0 + p_1 * x + p_2 * x^2
ftr = Fitter( jr, mdl ) par = ftr.fit( te ) print( "params :", fmt( par ) ) print( "stdevs :", fmt( ftr.stdevs ) )
params : [ 10.410 0.028 0.000] stdevs : [ 0.230 0.008 0.000]
#plt.plot( jr + 1900, te, 'k. ' ) xx = numpy.linspace( 0, 120, 121, dtype=float ) yfit = mdl( xx ) yerr = ftr.monteCarloError( xdata=xx ) fig, ax = plt.subplots() ax.plot(xx+1900, yfit, 'r-') ax.fill_between( xx+1900, yfit - yerr, yfit + yerr, color='b' ) ax.plot(jr+1900, te, 'k.') plt.xlabel( "Year") plt.ylabel( "Temperature") plt.title( "Water of the Rhine" ) plt.show()