-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdarcy_forchheimer_fit_plots.py
149 lines (102 loc) · 2.96 KB
/
darcy_forchheimer_fit_plots.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# py3 only, see below for py2
import numpy as np
import pandas as pd
from io import StringIO
import scipy.optimize as scy
import matplotlib.pyplot as plt
import proplot as pplt
dims = (6, 2.5)
fig, ax = plt.subplots(figsize=dims)
# Robin Red Holly Cut 0 PA
d1 = '''x y
0.00 0.00
2.41 9.56
3.65 22.15
4.63 35.56
5.22 44.41
5.71 53.81
6.25 64.55
6.98 79.58
7.30 87.10 '''
Robin_Red_Holly_Cut_0_PA = pd.read_csv(StringIO(d1), sep='\s+')
# Bakers Blue Spruce, Cut 3 (PC)
d2 = '''x y
0.00 0.00
3.06 2.26
4.61 6.21
5.82 9.38
6.56 12.57
7.18 15.50
7.88 17.61
8.72 22.41
9.07 24.01 '''
Bakers_Blue_Spruce = pd.read_csv(StringIO(d2), sep='\s+')
# Blue Shag Eastern White Pine, Cut 0 (PA)
d3 = '''x y
0.00 0.00
1.79 17.40
2.70 38.35
3.48 59.85
3.86 75.44
4.29 89.42
4.67 108.25
5.18 130.03 '''
Blue_Shag_Eastern = pd.read_csv(StringIO(d3), sep='\s+')
#
blueish = (0/255, 127/255, 255/255)
magenta = (247/255, 60/255, 124/255)
teal = (23/255, 142/255, 146/255)
colors = [blueish, magenta, teal]
labels = [
"Robin Red Holly, Cut 0 (PA)",
"Blue Shag Eastern White Pine, Cut 0 (PA)",
"Bakers Blue Spruce, Cut 3 (PC)"
]
data = [Robin_Red_Holly_Cut_0_PA,Blue_Shag_Eastern, Bakers_Blue_Spruce ]
# objective function
def objective(x, a, b, c):
# 2nd order polynomial
return a * x**2 + b*x+c
for i, d in enumerate(data):
print(i, d)
# fit curve
popt, _ = scy.curve_fit(objective, d['x'], d['y'])
xx = np.linspace(0,10,100)
yy = [objective(j, popt[0], popt[1], popt[2]) for j in xx]
plt.plot(xx,yy ,color = colors[i], label= labels[i])
plt.scatter(d['x'], d['y'], color=colors[i], facecolors='none',)
#
#
ax.set(xlim=(0, 10), ylim=(0, 150))
ax.set(xlabel="U [m/s]", ylabel='$\Delta$P [Pa]')
# Put the legend out of the figure
plt.legend()
#plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.tight_layout()
# plt.text(0.5, 0.5, 'matplotlib', horizontalalignment='center', verticalalignment='center', transform=ax.transAxes)
plt.savefig("Darcy_Forchheimer_Fit.pdf")
plt.savefig("Darcy_Forchheimer_Fit.png", dpi=600)
plt.show()
# ProPlot
for i, d in enumerate(data):
print(i, d)
# fit curve
popt, _ = scy.curve_fit(objective, d['x'], d['y'])
xx = np.linspace(0,10,100)
yy = [objective(j, popt[0], popt[1], popt[2]) for j in xx]
fig = pplt.figure(share=False)
ax = fig.subplot(title='Alternate y twin x')
ax.plot(d)
ax.plot(d)
#
#
ax.set(xlim=(0, 10), ylim=(0, 150))
ax.set(xlabel="U [m/s]", ylabel='$\Delta$P [Pa]')
# Put the legend out of the figure
pplt.legend()
#plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
pplt.tight_layout()
# plt.text(0.5, 0.5, 'matplotlib', horizontalalignment='center', verticalalignment='center', transform=ax.transAxes)
pplt.savefig("Darcy_Forchheimer_Fit_pplot.pdf")
pplt.savefig("Darcy_Forchheimer_Fit_pplot.png", dpi=600)
pplt.show()