# data of resistance measurements: voltage vs current
import numpy as np
import matplotlib.pyplot as plt
# data
U = np.array([4.5, 6, 7, 8, 9, 10]) # voltage in V
I = np.array([109.5, 115.3, 129.2, 134.8, 142.1, 144.6]) # current in A
plt.plot(U, I, 'o', label='data')
plt.errorbar(U, I, xerr=0.15, yerr=1.5, fmt='none')
plt.plot(np.unique(U), np.poly1d(np.polyfit(U, I, 1))(np.unique(U)), label='fit')
plt.plot([4.5, 10.5], [102,155], 'r--', label='linear fit')
plt.plot([4.5, 10.5], [115,143], 'r--', label='linear fit')
plt.xlabel('U [V]')
plt.ylabel('I [mA]')

The method:¶
Draw the best line using polynomial regression,
polyfitUsing points and error bars draw the minimum and maximum slopes
Get static sensitivity, i.e. slope uncertainty as the half the difference between the max and min slopes