-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotter.py
61 lines (47 loc) · 2.38 KB
/
plotter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import curvefitgui
import matplotlib.pyplot as plt
from uncertainvaluelist import UncertainValueList
import curvefitgui
#thinnk about this because maybe possibility to add multiple arrays and extract uncertainvalue from that if needed so taht its stored in most used format
#create UncertainValueList class to handle all the going from arrays of values and uncertainties to single object that can be used in plotting
# alse add possibilit of having the entire array have same uncertainty and the possibility to multiply these arrays (multiplies all underlying uncertain values) so that sets of data can be processed before being plotted
#add possibility for fits ass wel
def plotData(x, y, title=None):
"""
inputs x and y are expected to be uncertainvaluelists
"""
if not isinstance(x, UncertainValueList) or not isinstance(y, UncertainValueList):
raise ValueError("inputs are not of instance UncertainValueList")
xArray = x.values
xerrArray = x.absoluteErrors
yArray = y.values
yerrArray = y.absoluteErrors
plt.figure()
plt.scatter(xArray, yArray)
plt.errorbar(xArray, yArray, xerr=xerrArray, yerr=yerrArray, fmt="none", elinewidth=0.6)
if x.label is not None:
plt.xlabel(x.label)
if y.label is not None:
plt.ylabel(x.label)
if title is not None:
plt.title(title)
plt.minorticks_on()
plt.grid(which='major', color='#DDDDDD', linewidth=0.8)
plt.grid(which='minor', color='#EEEEEE', linestyle=':', linewidth=0.5)
plt.show()
def fitLinearData(x, y):
"""
inputs x and y are expected to be uncertainvaluelists
returns output of linearfitgui
"""
if not isinstance(x, UncertainValueList) or not isinstance(y, UncertainValueList):
raise ValueError("inputs are not of instance UncertainValueList")
return curvefitgui.linear_fit_gui(x.values, y.values, xerr=x.absoluteErrors, yerr=y.absoluteErrors, xlabel=x.label, ylabel=y.label)
def fitData(fitFunction, x, y):
"""
inputs x and y are expected to be uncertainvaluelists
returns output of curvefitgui
"""
if not isinstance(x, UncertainValueList) or not isinstance(y, UncertainValueList):
raise ValueError("inputs are not of instance UncertainValueList")
return curvefitgui.linear_fit_gui(fitFunction, x.values, y.values, xerr=x.absoluteErrors, yerr=y.absoluteErrors, xlabel=x.label, ylabel=y.label)