I want to plot 3 parameters in a line graph (revolutions Vs Thrust & Torque). Thrust and Torque are output of loop, which are required to plot live (update each time of iteration) with increasing revolution which depends upon the input time!
This is the result of code
Revolution Thrust Torque
-----------------------------------------------------------------
1 3955.56 6307.18
2 3955.56 6307.18
3 3955.56 6307.18
4 3955.56 6307.18
5 3955.56 6307.18
6 3955.56 6307.18
7 3955.56 6307.18
8 3955.56 6307.18
9 3955.56 6307.18
10 3955.56 6307.18
11 3955.56 6307.18
12 3955.56 6307.18
13 3955.56 6307.18
14 3955.56 6307.18
15 3955.56 6307.18
16 3955.56 6307.18
17 3955.56 6307.18
18 3955.56 6307.18
19 3955.56 6307.18
20 3955.56 6307.18
21 3955.56 6307.18
22 3955.56 6307.18
23 3955.56 6307.18
24 3955.56 6307.18
All three parameters are generated with the following code! Code is given!
import math
import matplotlib.pyplot as plt
# Basic data
azimuth = [14, 213, 345]
tilt = [0, 2, 4.5]
lat = [2, 3.75, 4.16]
long = [1.1, -1.1, 0.2]
# Generate the accumulative
accum_lat = [round(sum(lat[:i+1]), 2) for i in range(len(lat))]
# Average
avg_lat = [(lat[i] + lat[i+1]) / 2 if i != len(lat)-1 else lat[i] for i in range(len(lat))]
# Generate the accumulative
accum_long = [round(sum(long[:i+1]), 2) for i in range(len(long))]
# Define Radii
outer_radius = 65
inner_radius = 63
# Compute x , y and z
x = [round(((accum_lat[i] * math.cos(math.radians(azimuth[i])) - (inner_radius / 2)) - outer_radius), 2) for i in range(len(accum_lat))]
y = [round((accum_lat[i] * math.sin(math.radians(azimuth[i]))), 2) for i in range(len(accum_lat))]
max_accum_long = max(accum_long)
z_1 = [max_accum_long - x for x in accum_long]
z = [round(x, 2) for x in z_1]
# Define the Advance
advance_rate = 1.5
# Compute the actual advance
act_pen = [round((advance_rate * math.cos(math.radians(x))), 2) for x in tilt]
# Conditioning Inputs
RPM = 16
Time = 1.5
revolution = RPM * Time
radius_multiplier = 2 * math.pi
# Show headers of print function
headers = ['Revolution', 'Thrust', 'Torque']
separator = '-' * 65
print("{:<15}{:<25}{:<25}".format(*headers))
print(separator)
# Coefficients
N_N_a = 939
N_N_b = 0.1570
N_N_c = 0.289
N_M_a = 1858
N_M_b = 0.1590
N_M_c = 0.164
N_W_a = 2671
N_W_b = 0.1590
N_W_c = 0.181
# Coefficients
D_N_a = 471
D_N_b = 1.1070
D_N_c = 0.449
D_M_a = 471
D_M_b = 1.1070
D_M_c = 0.449
D_W_a = 492
D_W_b = 1.1740
D_W_c = 0.27
for rev in range(int(revolution)):
for r in accum_lat:
distance = [(rev+1)* (radius_multiplier * r) for _ in range(len(accum_lat))]
distance_travel_list = [round(d, 2) for d in distance]
# Conditions
def get_condition(distance_travel_list):
tool_cond = []
for i, x in enumerate(distance_travel_list):
if x < 5000:
tool_cond.append(1)
elif 5000 <= x < 6000:
tool_cond.append(2)
else:
tool_cond.append(3)
return tool_cond
tool_cond = get_condition(distance_travel_list)
# Normal
NF = []
for i in range(len(act_pen)):
if tool_cond[i] == 1:
NF.append(abs(N_N_a * (Avg_Lat[i]**N_N_b) * (act_pen[i]**N_N_c)))
elif tool_cond[i] == 2:
NF.append(abs(N_M_a * (Avg_Lat[i]**N_M_b) * (act_pen[i]**N_M_c)))
elif tool_cond[i] == 3:
NF.append(abs(N_W_a * (Avg_Lat[i]**N_W_b) * (act_pen[i]**N_W_c)))
NF = [round(n, 2) for n in NF]
# Cut
DF = []
for i in range(len(act_pen)):
if tool_cond[i] == 1:
DF.append(abs(D_N_a * (Avg_Lat[i]**D_N_b) * (act_pen[i]**D_N_c)))
elif tool_cond[i] == 2:
DF.append(abs(D_M_a * (Avg_Lat[i]**D_M_b) * (act_pen[i]**D_M_c)))
elif tool_cond[i] == 3:
DF.append(abs(D_W_a * (Avg_Lat[i]**D_W_b) * (act_pen[i]**D_W_c)))
DF = [round(n, 2) for n in DF]
# Side
s_percent = 0.15
SF = [round(NF[i] * s_percent * (1 + math.sin(math.radians(Tilt[i]))), 2) for i in range(len(NF))]
# NFX
NFX = [round(NF[i] * math.sin(math.radians(Tilt[i])) * math.cos(math.radians(Azimuth[i])), 2) for i in range(len(NF))]
# DFX
DFX = [round(DF[i] * math.sin(math.radians(Azimuth[i])), 2) for i in range(len(DF))]
# SFX
SFX = [round(SF[i] * math.cos(math.radians(Tilt[i])) * math.cos(math.radians(Azimuth[i])), 2) for i in range(len(SF))]
# Create a new list for the results
FX = [round(-NFX[i] - DFX[i] + SFX[i], 2) for i in range(len(NFX))]
Lat_Force = sum(FX)
# NFY
NFY = [round(NF[i] * math.sin(math.radians(Tilt[i])) * math.sin(math.radians(Azimuth[i])), 2) for i in range(len(NF))]
# DFY
DFY = [round(DF[i] * math.cos(math.radians(Azimuth[i])), 2) for i in range(len(DF))]
# SFY
SFY = [round(SF[i] * math.cos(math.radians(Tilt[i])) * math.sin(math.radians(Azimuth[i])), 2) for i in range(len(SF))]
# Create a new list
FY = [round(-NFY[i] + DFY[i] + SFY[i], 2) for i in range(len(NFY))]
Vertical_Force = sum(FY)
# NFZ
NFZ = [round(NF[i] * math.cos(math.radians(Tilt[i])), 2) for i in range(len(NF))]
# SFZ
SFZ = [round(SF[i] * math.sin(math.radians(Tilt[i])), 2) for i in range(len(SF))]
# Create a new list
FZ = [round(NFZ[i] + SFZ[i], 2) for i in range(len(NFZ))]
Thrust = sum(FZ)
# Iterate over the data
XFY = [round((x[i]+106.5) * FY[i], 2) for i in range(len(FY))]
XFZ = [round(x[i] * FZ[i], 2) for i in range(len(FZ))]
YFZ = [round(y[i] * FZ[i], 2) for i in range(len(FZ))]
YFX = [round(y[i] * FX[i], 2) for i in range(len(FX))]
ZFY = [round(z[i] * FY[i], 2) for i in range(len(FY))]
ZFX = [round(z[i] * FX[i], 2) for i in range(len(FX))]
# Create a new list
MX = [round((-YFZ[i] + ZFY[i]) / 12, 2) for i in range(len(YFZ))]
MY = [round((XFZ[i] - ZFX[i]) / 12, 2) for i in range(len(ZFX))]
Lat_Moment = sum(MY)
MZ = [round((XFY[i] - YFX[i]) / 12, 2) for i in range(len(YFX))]
Torque = [round(sum(MZ), 2)]
# Convert Thrust and Torque to list if they are not already
if not isinstance(Thrust, list):
Thrust = [Thrust]
if not isinstance(Torque, list):
Torque = [Torque]
# Calculate the results
Thrust = sum(FZ)
Torque = sum(MZ)
Revolutions = [rev]
print("{:<15.0f}{:<15.2f}{:.2f}".format(rev+1, Thrust, Torque))