Initial commit
This commit is contained in:
@@ -0,0 +1,233 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def get_data(filename):
|
||||
file = open(filename)
|
||||
lines = file.readlines()
|
||||
x = []
|
||||
y = []
|
||||
for i in range(len(lines)):
|
||||
if i % 2 == 0:
|
||||
lines[i].strip()
|
||||
data = lines[i].split()
|
||||
x.append(float(data[0]))
|
||||
y.append(float(data[1]))
|
||||
return x, y
|
||||
|
||||
|
||||
time, power = get_data('Drone Comparison Data for Dan/required_power.txt')
|
||||
|
||||
time1, e_power = get_data('Drone Comparison Data for Dan/engine_power.txt')
|
||||
|
||||
time2, hb_power = get_data('Drone Comparison Data for Dan/hybrid_battery_power.txt')
|
||||
|
||||
time3, bo_power = get_data('Drone Comparison Data for Dan/battery_only_power.txt')
|
||||
|
||||
time4, hb_soc_small = get_data('Drone Comparison Data for Dan/hybrid_SOC.txt')
|
||||
|
||||
time5, bo_soc_small = get_data('Drone Comparison Data for Dan/battery_only_SOC.txt')
|
||||
|
||||
hb_soc =[]
|
||||
bo_soc = []
|
||||
for data in hb_soc_small:
|
||||
hb_soc.append(data*100)
|
||||
|
||||
for data in bo_soc_small:
|
||||
bo_soc.append(data*100)
|
||||
|
||||
# Basic Styling
|
||||
plt.rcParams.update({
|
||||
'font.family': 'Courier New', # monospace font
|
||||
'font.size': 20, # Fonts
|
||||
'axes.titlesize': 20, # |
|
||||
'axes.labelsize': 15, # V
|
||||
'xtick.labelsize': 15,
|
||||
'ytick.labelsize': 15,
|
||||
'legend.fontsize': 15,
|
||||
'figure.titlesize': 20,
|
||||
'figure.figsize': [10,10] # Figure Size
|
||||
})
|
||||
|
||||
# Figure Setup
|
||||
fig, ax = plt.subplots(3, 1, gridspec_kw={'height_ratios': [3, 2, 2]})
|
||||
title = 'Power Output vs Time' # Title
|
||||
# fig.suptitle(title, y=0.95) #pad controls distance to plot
|
||||
|
||||
### Figure 1 (top) ###
|
||||
x_1_title = 'Jetfire Hybrid System Power Output'
|
||||
ax[0].set_title(x_1_title)
|
||||
x_1_lab = 'Time [min]' # X Label
|
||||
y_1_lab = 'Power [kW]' # Y Label
|
||||
ax[0].set_xlabel(x_1_lab)
|
||||
ax[0].set_ylabel(y_1_lab)
|
||||
ax[0].spines['top'].set_visible(False) # Controls non axis borders
|
||||
ax[0].spines['right'].set_visible(False)
|
||||
ax[0].spines['bottom'].set_visible(False)
|
||||
|
||||
### Figure 2 (middle) ###
|
||||
x_2_title = 'Electric System Power Output'
|
||||
ax[1].set_title(x_2_title)
|
||||
x_2_lab = 'Time [min]' # X Label
|
||||
y_2_lab = 'Power [kW]' # Y Label
|
||||
ax[1].set_xlabel(x_2_lab)
|
||||
ax[1].set_ylabel(y_2_lab)
|
||||
ax[1].spines['top'].set_visible(False) # Controls non axis borders
|
||||
ax[1].spines['right'].set_visible(False)
|
||||
|
||||
### Figure 3 (middle) ###
|
||||
x_3_title = 'State of Charge'
|
||||
ax[2].set_title(x_3_title)
|
||||
x_3_lab = 'Time [min]' # X Label
|
||||
y_3_lab = 'Charge [%]' # Y Label
|
||||
ax[2].set_xlabel(x_3_lab)
|
||||
ax[2].set_ylabel(y_3_lab)
|
||||
ax[2].spines['top'].set_visible(False) # Controls non axis borders
|
||||
ax[2].spines['right'].set_visible(False)
|
||||
|
||||
|
||||
### axis is the same for both graphs ###
|
||||
### x displays on bottom graph only ###
|
||||
x_1_min = 0 # Axis Limits and Ticks
|
||||
x_1_max = 95
|
||||
x_1_step_maj = 10 #steps not division
|
||||
x_1_step_min = 1
|
||||
|
||||
ax[0].set_xlim(x_1_min,x_1_max) # X limits
|
||||
ax[0].set_xticks(np.arange(x_1_min,x_1_max,x_1_step_maj)) # X Major Ticks
|
||||
# ax[1].set_xticks([-180,-90,0,90,180], minor=True) # X Minor Ticks
|
||||
|
||||
x_2_min = 0 # Axis Limits and Ticks
|
||||
x_2_max = 9.5
|
||||
x_2_step_maj = 1 #steps not division
|
||||
x_2_step_min = 1
|
||||
|
||||
ax[1].set_xlim(x_2_min,x_2_max) # X limits
|
||||
ax[1].set_xticks(np.arange(x_2_min,x_2_max,x_2_step_maj)) # X Major Ticks
|
||||
# ax[1].set_xticks([-180,-90,0,90,180], minor=True) # X Minor Ticks
|
||||
|
||||
x_3_min = 0 # Axis Limits and Ticks
|
||||
x_3_max = 95
|
||||
x_3_step_maj = 10 #steps not division
|
||||
x_3_step_min = 1
|
||||
|
||||
ax[2].set_xlim(x_3_min,x_3_max) # X limits
|
||||
ax[2].set_xticks(np.arange(x_3_min,x_3_max,x_3_step_maj)) # X Major Ticks
|
||||
# ax[1].set_xticks([-180,-90,0,90,180], minor=True) # X Minor Ticks
|
||||
|
||||
|
||||
### Figure 1 (top) ###
|
||||
y_1_min = -5
|
||||
y_1_max = 17
|
||||
y_1_step_maj = 5
|
||||
y_1_step_min = 1
|
||||
|
||||
ax[0].set_ylim(y_1_min,y_1_max) # Y limits
|
||||
ax[0].set_yticks(np.arange(y_1_min,y_1_max,y_1_step_maj)) # Y Major Ticks
|
||||
# ax.set_yticks(np.arange(y_min,y_max,y_step_min),minor=True) # Y Minor Ticks
|
||||
|
||||
|
||||
ax[0].grid(True, which='major',alpha=0.5) # Turn On Major Grid
|
||||
# ax[0].grid(True, which='minor',alpha=0.2) # Turn on Minor Grid
|
||||
# alpha controls transparency
|
||||
|
||||
### Figure 2 (bottom) ###
|
||||
y_2_min = 0
|
||||
y_2_max = 17
|
||||
y_2_step_maj = 5
|
||||
y_2_step_min = 1
|
||||
|
||||
ax[1].set_ylim(y_2_min,y_2_max) # Y limits
|
||||
ax[1].set_yticks(np.arange(y_2_min,y_2_max,y_2_step_maj)) # Y Major Ticks
|
||||
# ax[1].set_yticks(np.arange(y_2_min,y_2_max,y_2_step_min),minor=True) # Y Minor Ticks
|
||||
|
||||
ax[1].grid(True, which='major',alpha=0.5) # Turn On Major Grid
|
||||
# ax[1].grid(True, which='minor',alpha=0.2) # Turn on Minor Grid
|
||||
# alpha controls transparency
|
||||
|
||||
|
||||
y_3_min = 0
|
||||
y_3_max = 110
|
||||
y_3_step_maj = 25
|
||||
y_3_step_min = 1
|
||||
|
||||
ax[2].set_ylim(y_3_min,y_3_max) # Y limits
|
||||
ax[2].set_yticks(np.arange(y_3_min,y_3_max,y_3_step_maj)) # Y Major Ticks
|
||||
# ax[1].set_yticks(np.arange(y_2_min,y_2_max,y_2_step_min),minor=True) # Y Minor Ticks
|
||||
|
||||
ax[2].grid(True, which='major',alpha=0.5) # Turn On Major Grid
|
||||
# ax[1].grid(True, which='minor',alpha=0.2) # Turn on Minor Grid
|
||||
# alpha controls transparency
|
||||
|
||||
|
||||
|
||||
###################### Single Line ######################
|
||||
'''
|
||||
# x = []
|
||||
# y = []
|
||||
|
||||
ax.plot(x,y,color='black',linestyle='-',linewidth='1')
|
||||
# Basic Line Styles: -, --, :, -.
|
||||
# Basic Colors: red, blue, green, purple, cyan, magenta, black, brown, etc
|
||||
# Can Specify Hex code for colors
|
||||
|
||||
# ax.scatter(x,y,color='black',marker='o',size=20)
|
||||
# # Many Markers: circle-'o', square-'s', triangle-'^',star-'*', x-'x'
|
||||
|
||||
# plt.show()
|
||||
'''
|
||||
|
||||
###################### Stacked Line ######################
|
||||
|
||||
x1 = [time, time1, time2,[71.5,71.5],[0,95]] # List of Lists
|
||||
y1 = [power, e_power, hb_power,[-2,10],[0,0]] # List of Lists
|
||||
|
||||
dl1 = ['Total Power','Jetfire Engine','Electric Motor','Fuel Runs Out',''] # Data Labels (list)
|
||||
lc1 = ["#A30F48","#1db9be","#0C53AF",'black','black'] # Line Color |
|
||||
ls1 = ['-','-','-',':','-'] # Line Style |
|
||||
lw1 = [2,2,2,1.5,1] # Line Width V
|
||||
a1 = [1,1,1,1,1] # Transparency
|
||||
|
||||
for i in range(len(x1)):
|
||||
ax[0].plot(x1[i],y1[i],label=dl1[i],color=lc1[i],linestyle=ls1[i],linewidth=lw1[i], alpha=a1[i])
|
||||
|
||||
ax[0].legend(loc='center', bbox_to_anchor=(0.6,0.8), ncol=2, frameon=True,edgecolor='white',framealpha=1, labelspacing=0.2, columnspacing=0.75,handlelength=0.9, handletextpad=0.3)
|
||||
# anchor loc is based on the plot area, 0.5 is half the width, 1.01 is just above the top
|
||||
# labelspacing is for vertical spacing, column is for horizontal, handel is for line length, textpad is for handl eto text
|
||||
|
||||
x2 = [time3] # List of Lists
|
||||
y2 = [bo_power] # List of Lists
|
||||
|
||||
dl2 = ['Electric Motor'] # Data Labels (list)
|
||||
lc2 = ['#008349'] # Line Color |
|
||||
ls2 = ['-'] # Line Style |
|
||||
lw2 = [2] # Line Width V
|
||||
a2 = [1] # Transparency
|
||||
|
||||
for i in range(len(x2)):
|
||||
ax[1].plot(x2[i],y2[i],label=dl2[i],color=lc2[i],linestyle=ls2[i],linewidth=lw2[i], alpha=a2[i])
|
||||
|
||||
# ax[1].fill_between(x_temp,y_temp,hatch='///', alpha=0)
|
||||
|
||||
# ax[1].legend(loc='center', bbox_to_anchor=(0.8,0.8), ncol=1, frameon=True,edgecolor='white',framealpha=1, labelspacing=0.2, columnspacing=0.75,handlelength=0.9, handletextpad=0.3)
|
||||
# anchor loc is based on the plot area, 0.5 is half the width, 1.01 is just above the top
|
||||
# labelspacing is for vertical spacing, column is for horizontal, handel is for line length, textpad is for handl eto text
|
||||
|
||||
x3 = [time4, time5] # List of Lists
|
||||
y3 = [hb_soc, bo_soc] # List of Lists
|
||||
|
||||
dl3 = ['Hybrid', 'Electric'] # Data Labels (list)
|
||||
lc3 = ["#1db9be","#0C53AF"] # Line Color |
|
||||
ls3 = ['-','-'] # Line Style |
|
||||
lw3 = [2,2] # Line Width V
|
||||
a3 = [1,1] # Transparency
|
||||
|
||||
for i in range(len(x3)):
|
||||
ax[2].plot(x3[i],y3[i],label=dl3[i],color=lc3[i],linestyle=ls3[i],linewidth=lw3[i], alpha=a3[i])
|
||||
|
||||
ax[2].legend(loc='center', bbox_to_anchor=(0.65,0.45), ncol=2, frameon=True,edgecolor='white',framealpha=1, labelspacing=0.2, columnspacing=0.75,handlelength=0.9, handletextpad=0.3)
|
||||
|
||||
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
|
||||
Reference in New Issue
Block a user