Экстраполяция в питоне (кривая температуры в бомбовом калориметре) - PullRequest
0 голосов
/ 31 октября 2019

2 красные линии на графике - это две экстраполированные линии. Верхняя линия работает хорошо, но нижняя линия, кажется, учитывает данные вне диапазона time2 и temp2, что делает линию неуклюжей после точки t=420s. Я хотел бы знать, как это исправить.

* На менее важном примечании: как я могу удалить лишние отметки на оси x слева от начала координат? Большое спасибо.

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
from matplotlib.ticker import (MultipleLocator, FormatStrFormatter,
                               AutoMinorLocator)
from sklearn.linear_model import LinearRegression
from scipy.interpolate import InterpolatedUnivariateSpline

%matplotlib inline

file = pd.read_excel("T8.xlsx","Phthalansäureanhydrid",usecols=[2,3])
X = file['Zeit(s)']
Y = file['Temperatur(Celcius Grad)']

fig, ax = plt.subplots()
ax.plot(X,Y,'-',color='#10A5F3', label="Phthalansäureanhydrid")
ax.grid(True, which='major', axis='both', color='#F19211', linestyle='-')
#ax.grid(True, which='minor', axis='both', color='#F19211', linestyle='--')
ax.spines['left'].set_position('zero')
ax.spines['right'].set_color('none')
#ax.spines['bottom'].set_position('zero')
ax.spines['top'].set_color('none')
#ax.legend(loc='upper center', frameon=True)

#major & minor ticks
ax.xaxis.set_major_locator(MultipleLocator(100))
ax.xaxis.set_major_formatter(FormatStrFormatter('%d'))
ax.xaxis.set_minor_locator(MultipleLocator(10))

#extrapolation - first line
temp1 = []
time1 = []
xnew1 = []
for i in file.index:
    if i > 630:
        temp1.append(file['Temperatur(Celcius Grad)'][i])
        time1.append(file['Zeit(s)'][i])
    else:
        xnew1.append(file['Zeit(s)'][i])

order = 1
extrapo1 = InterpolatedUnivariateSpline(time1, temp1, k=1)
ynew1 = extrapo1(xnew1)

#extrapolation - second line
temp2 = []
time2 = []
xnew2 = []
for i in file.index:
    if 100<i<400:
        temp2.append(file['Temperatur(Celcius Grad)'][i])
        time2.append(file['Zeit(s)'][i])
    if i>200:
        xnew2.append(file['Zeit(s)'][i])

ynew2 = []
f = interpolate.interp1d(time2, temp2, fill_value='extrapolate')
for i in xnew2:
    ynew2.append(f(i))



plt.xlabel(r'Zeit[s]')
plt.ylabel(r'Temperatur[c]')
plt.plot(xnew1,ynew1,'-', color = '#B94A4D')
plt.plot(xnew2,ynew2,'-', color = '#B94A4D')


plt.savefig('kmn.pdf')

Ссылка на данные: enter image description here https://docs.google.com/spreadsheets/d/1xznXj-aA-Szq2s4KWb-qPWYxZbQNrA5FgUCQT6i7oVo/edit?usp=sharing

...