Initial commit
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
'''
|
||||
This file gives the trace for 2 data sets (Nominally measured and simulated)
|
||||
but can be modified to do 1 or more if needed.
|
||||
|
||||
It will automatically scale from -180 to 180 for a 2-Stroke
|
||||
|
||||
It needs .txt files copied from the data of GT-Power with the format of:
|
||||
|
||||
title line
|
||||
data CAD
|
||||
data CAD
|
||||
. .
|
||||
. .
|
||||
. .
|
||||
|
||||
Other needed info: Max y value for the y axis
|
||||
|
||||
**Will need to adjust colors, line type, etc.**
|
||||
'''
|
||||
|
||||
|
||||
def get_data(filename):
|
||||
file = open(filename)
|
||||
title = file.readline()
|
||||
lines = file.readlines()
|
||||
x = []
|
||||
y = []
|
||||
x_shift = []
|
||||
y_shift = []
|
||||
for line in lines:
|
||||
line.strip()
|
||||
data = line.split()
|
||||
if float(data[0])<=180:
|
||||
x.append(float(data[0]))
|
||||
y.append(float(data[1]))
|
||||
else:
|
||||
x_shift.append(float(data[0])-360)
|
||||
y_shift.append(float(data[1]))
|
||||
|
||||
return x_shift+x, y_shift+y
|
||||
|
||||
x_meas, y_meas = get_data('Python/Plotting/Base/Measured_P.txt') #Files go here
|
||||
x_sim, y_sim = get_data("Python/Plotting/Base/Simulated_P.txt")
|
||||
y_max_data = 36
|
||||
|
||||
################################# BASIC PLOT CODE #################################
|
||||
|
||||
# Basic Styling
|
||||
plt.rcParams.update({
|
||||
'font.family': 'Courier New', # monospace font
|
||||
'font.size': 20, # Fonts
|
||||
'axes.titlesize': 20, # |
|
||||
'axes.labelsize': 20, # V
|
||||
'xtick.labelsize': 15,
|
||||
'ytick.labelsize': 15,
|
||||
'legend.fontsize': 15,
|
||||
'figure.titlesize': 20,
|
||||
'figure.figsize': [10,5] # Figure Size
|
||||
})
|
||||
|
||||
# Figure Setup
|
||||
fig, ax = plt.subplots()
|
||||
title = 'Cylinder Pressure Trace' # Title
|
||||
xlab = '' # X Label
|
||||
ylab = 'Pressure [Bar]' # Y Label
|
||||
ax.set_xlabel(xlab)
|
||||
ax.set_ylabel(ylab)
|
||||
ax.set_title(title, pad = 20) #pad controls distance to plot
|
||||
ax.spines['top'].set_visible(False) # Controls non axis borders
|
||||
ax.spines['right'].set_visible(False)
|
||||
|
||||
x_min = -180 # Axis Limits and Ticks
|
||||
x_max = 180
|
||||
x_step_maj = 1 #steps not division
|
||||
x_step_min = 1
|
||||
|
||||
y_min = 0
|
||||
y_max = y_max_data
|
||||
y_step_maj = 5
|
||||
y_step_min = 1
|
||||
|
||||
ax.set_xlim(x_min,x_max) # X limits
|
||||
ax.set_xticks([-180,-90,0,90,180],['BDC\n-180°','Intake/Compression','TDC\n0°','Exhaust/Expansion','BDC\n180°']) # X Major Ticks
|
||||
ax.set_xticks([-180,-90,0,90,180], minor=True) # X Minor Ticks
|
||||
|
||||
ax.set_ylim(y_min,y_max) # Y limits
|
||||
ax.set_yticks(np.arange(y_min,y_max,y_step_maj),tickpad = 10) # Y Major Ticks
|
||||
# ax.set_yticks(np.arange(y_min,y_max,y_step_min),minor=True) # Y Minor Ticks
|
||||
|
||||
|
||||
ax.grid(True, which='major',alpha=0.5) # Turn On Major Grid
|
||||
ax.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()
|
||||
'''
|
||||
|
||||
###################### Multi Line ######################
|
||||
|
||||
x = [x_sim,x_meas,[0,0]] # List of Lists
|
||||
y = [y_sim,y_meas,[0,36]] # List of Lists
|
||||
|
||||
#### Lists must be equal length ###
|
||||
|
||||
dl = ['Simulated','Measured',''] # Data Labels (list)
|
||||
lc = ['black','black','black'] # Line Color |
|
||||
ls = ['-','--','-'] # Line Style |
|
||||
lw = [2,2,1] # Line Width V
|
||||
a = [1,1,0.8] # Transparency
|
||||
s = [] # Marker Size, 20 is default
|
||||
m = [] # Marker Type, 'o' is default
|
||||
# Use color-hex.com for color pallets
|
||||
# Common ones: Shades of Teal, Ocean Breezes By,Ppt Cv
|
||||
|
||||
|
||||
|
||||
for i in range(len(x)):
|
||||
ax.plot(x[i],y[i],label=dl[i],color=lc[i],linestyle=ls[i],linewidth=lw[i], alpha=a[i])
|
||||
#ax.scatter(x[i],y[i],label=dl[i],color=lc[i],marker=m[i],size=s[i])
|
||||
|
||||
ax.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
|
||||
|
||||
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
@@ -0,0 +1,144 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
'''
|
||||
This file gives the pressure trace for 2 traces (Nominally measured and simulated)
|
||||
but can be modified to do 1 or more if needed.
|
||||
|
||||
It will automatically scale from -180 to 180 for a 2-Stroke
|
||||
|
||||
It needs .txt files copied from the data of GT-Power with the format of:
|
||||
|
||||
title line
|
||||
pressure CAD
|
||||
pressure CAD
|
||||
. .
|
||||
. .
|
||||
. .
|
||||
|
||||
Other needed info: Max y value for the y axis
|
||||
|
||||
**Will need to adjust colors, line type, etc.**
|
||||
'''
|
||||
|
||||
|
||||
def get_data(filename):
|
||||
file = open(filename)
|
||||
title = file.readline()
|
||||
lines = file.readlines()
|
||||
x = []
|
||||
y = []
|
||||
x_shift = []
|
||||
y_shift = []
|
||||
for line in lines:
|
||||
line.strip()
|
||||
data = line.split()
|
||||
if float(data[0])<=180:
|
||||
x.append(float(data[0]))
|
||||
y.append(float(data[1]))
|
||||
else:
|
||||
x_shift.append(float(data[0])-360)
|
||||
y_shift.append(float(data[1]))
|
||||
|
||||
return x_shift+x, y_shift+y
|
||||
|
||||
x_meas, y_meas = get_data('Python/Plotting/Base/Measured_P.txt') #Files go here
|
||||
x_sim, y_sim = get_data("Python/Plotting/Base/Simulated_P.txt")
|
||||
y_max_data = 36
|
||||
|
||||
################################# BASIC PLOT CODE #################################
|
||||
|
||||
# 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,5] # Figure Size
|
||||
})
|
||||
|
||||
# Figure Setup
|
||||
fig, ax = plt.subplots()
|
||||
title = 'Cylinder Pressure Trace' # Title
|
||||
xlab = 'Crank Angle [degrees]' # X Label
|
||||
ylab = 'Pressure [Bar]' # Y Label
|
||||
ax.set_xlabel(xlab)
|
||||
ax.set_ylabel(ylab)
|
||||
ax.set_title(title, pad = 20) #pad controls distance to plot
|
||||
ax.spines['top'].set_visible(False) # Controls non axis borders
|
||||
ax.spines['right'].set_visible(False)
|
||||
|
||||
x_min = -180 # Axis Limits and Ticks
|
||||
x_max = 180
|
||||
x_step_maj = 1 #steps not division
|
||||
x_step_min = 1
|
||||
|
||||
y_min = 0
|
||||
y_max = y_max_data
|
||||
y_step_maj = 5
|
||||
y_step_min = 1
|
||||
|
||||
ax.set_xlim(x_min,x_max) # X limits
|
||||
ax.set_xticks([-180,-90,0,90,180],['BDC\n-180°','Intake/Compression','TDC\n0°','Exhaust/Expansion','BDC\n180°']) # X Major Ticks
|
||||
# ax.set_xticks([-180,-90,0,90,180], minor=True) # X Minor Ticks
|
||||
|
||||
ax.set_ylim(y_min,y_max) # Y limits
|
||||
ax.set_yticks(np.arange(y_min,y_max,y_step_maj),tickpad = 10) # Y Major Ticks
|
||||
# ax.set_yticks(np.arange(y_min,y_max,y_step_min),minor=True) # Y Minor Ticks
|
||||
|
||||
|
||||
ax.grid(True, which='major',alpha=0.5) # Turn On Major Grid
|
||||
ax.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()
|
||||
'''
|
||||
|
||||
###################### Multi Line ######################
|
||||
|
||||
x = [x_sim,x_meas,[0,0]] # List of Lists
|
||||
y = [y_sim,y_meas,[0,36]] # List of Lists
|
||||
|
||||
#### Lists must be equal length ###
|
||||
|
||||
dl = ['Simulated','Measured',''] # Data Labels (list)
|
||||
lc = ['black','black','black'] # Line Color |
|
||||
ls = ['-','--','-'] # Line Style |
|
||||
lw = [2,2,1] # Line Width V
|
||||
a = [1,1,0.8] # Transparency
|
||||
s = [] # Marker Size, 20 is default
|
||||
m = [] # Marker Type, 'o' is default
|
||||
# Use color-hex.com for color pallets
|
||||
# Common ones: Shades of Teal, Ocean Breezes By,Ppt Cv
|
||||
|
||||
|
||||
|
||||
for i in range(len(x)):
|
||||
ax.plot(x[i],y[i],label=dl[i],color=lc[i],linestyle=ls[i],linewidth=lw[i], alpha=a[i])
|
||||
#ax.scatter(x[i],y[i],label=dl[i],color=lc[i],marker=m[i],size=s[i])
|
||||
|
||||
ax.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
|
||||
|
||||
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
@@ -0,0 +1,144 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
'''
|
||||
This file gives the trace for 2 data sets (Nominally measured and simulated)
|
||||
but can be modified to do 1 or more if needed.
|
||||
|
||||
It will automatically scale from -180 to 540 for a 4-Stroke
|
||||
|
||||
It needs .txt files copied from the data of GT-Power with the format of:
|
||||
|
||||
(no headers)
|
||||
data CAD
|
||||
data CAD
|
||||
. .
|
||||
. .
|
||||
. .
|
||||
|
||||
Other needed info: Max y value for the y axis
|
||||
|
||||
**Will need to adjust colors, step scaling, line type, etc.**
|
||||
'''
|
||||
|
||||
|
||||
def get_data(filename):
|
||||
file = open(filename)
|
||||
# title = file.readline()
|
||||
lines = file.readlines()
|
||||
x = []
|
||||
y = []
|
||||
x_shift = []
|
||||
y_shift = []
|
||||
for line in lines:
|
||||
line.strip()
|
||||
data = line.split()
|
||||
if float(data[0])<=540:
|
||||
x.append(float(data[0]))
|
||||
y.append(float(data[1]))
|
||||
else:
|
||||
x_shift.append(float(data[0])-720)
|
||||
y_shift.append(float(data[1]))
|
||||
|
||||
return x_shift+x, y_shift+y
|
||||
|
||||
x1, y1 = get_data('Python/Plotting/Base/mass_atm.txt') #Files go here
|
||||
x2, y2 = get_data("Python/Plotting/Base/mass_2bar.txt")
|
||||
y_max_data = 1.8
|
||||
|
||||
################################# BASIC PLOT CODE #################################
|
||||
|
||||
# Basic Styling
|
||||
plt.rcParams.update({
|
||||
'font.family': 'Courier New', # monospace font
|
||||
'font.size': 20, # Fonts
|
||||
'axes.titlesize': 20, # |
|
||||
'axes.labelsize': 20, # V
|
||||
'xtick.labelsize': 15,
|
||||
'ytick.labelsize': 15,
|
||||
'legend.fontsize': 15,
|
||||
'figure.titlesize': 20,
|
||||
'figure.figsize': [10,5] # Figure Size
|
||||
})
|
||||
|
||||
# Figure Setup
|
||||
fig, ax = plt.subplots()
|
||||
title = 'Trapped Mass' # Title
|
||||
xlab = 'Crank Angle [degrees]' # X Label
|
||||
ylab = 'Pressure [Bar]' # Y Label
|
||||
# ax.set_xlabel(xlab)
|
||||
ax.set_ylabel(ylab)
|
||||
ax.set_title(title, pad = 20) #pad controls distance to plot
|
||||
ax.spines['top'].set_visible(False) # Controls non axis borders
|
||||
ax.spines['right'].set_visible(False)
|
||||
|
||||
x_min = -180 # Axis Limits and Ticks
|
||||
x_max = 540
|
||||
x_step_maj = 1 #steps not division
|
||||
x_step_min = 1
|
||||
|
||||
y_min = 0
|
||||
y_max = y_max_data
|
||||
y_step_maj = 0.2
|
||||
y_step_min = 0.1
|
||||
|
||||
ax.set_xlim(x_min,x_max) # X limits
|
||||
ax.set_xticks([-180,-90,0,90,180,270,360,450,540],['BDC\n-180°','Compression','TDCF\n0°','Power','BDC\n180°','Exhaust','TDC\n360°','Intake','BDC\n540°']) # X Major Ticks
|
||||
# ax.set_xticks([-180,-90,0,90,180], minor=True) # X Minor Ticks
|
||||
|
||||
ax.set_ylim(y_min,y_max) # Y limits
|
||||
ax.set_yticks(np.arange(y_min,y_max,y_step_maj),tickpad = 10) # Y Major Ticks
|
||||
# ax.set_yticks(np.arange(y_min,y_max,y_step_min),minor=True) # Y Minor Ticks
|
||||
|
||||
|
||||
ax.grid(True, which='major',alpha=0.5) # Turn On Major Grid
|
||||
ax.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()
|
||||
'''
|
||||
|
||||
###################### Multi Line ######################
|
||||
|
||||
x = [x1,x2,[0,0]] # List of Lists
|
||||
y = [y1,y2,[0,y_max_data]] # List of Lists
|
||||
|
||||
#### Lists must be equal length ###
|
||||
|
||||
dl = ['No Boost','2 Bar Boost',''] # Data Labels (list)
|
||||
lc = ['black','black','black'] # Line Color |
|
||||
ls = ['-','--','-'] # Line Style |
|
||||
lw = [2,2,1] # Line Width V
|
||||
a = [1,1,0.8] # Transparency
|
||||
s = [] # Marker Size, 20 is default
|
||||
m = [] # Marker Type, 'o' is default
|
||||
# Use color-hex.com for color pallets
|
||||
# Common ones: Shades of Teal, Ocean Breezes By,Ppt Cv
|
||||
|
||||
|
||||
|
||||
for i in range(len(x)):
|
||||
ax.plot(x[i],y[i],label=dl[i],color=lc[i],linestyle=ls[i],linewidth=lw[i], alpha=a[i])
|
||||
#ax.scatter(x[i],y[i],label=dl[i],color=lc[i],marker=m[i],size=s[i])
|
||||
|
||||
ax.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
|
||||
|
||||
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
@@ -0,0 +1,143 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
'''
|
||||
This file gives the PV Diagram for 2 traces (Nominally measured and simulated)
|
||||
but can be modified to do 1 or more if needed.
|
||||
|
||||
It needs .txt files copied from the data of GT-Power with the format of:
|
||||
|
||||
(no headers)
|
||||
pressure volume fraction
|
||||
pressure volume fraction
|
||||
. .
|
||||
. .
|
||||
. .
|
||||
|
||||
Other needed info: Max y value for the y axis
|
||||
|
||||
**Will need to adjust how far out min/max lines go, as well as
|
||||
colors, line type, etc.**
|
||||
'''
|
||||
|
||||
|
||||
def get_data(filename):
|
||||
file = open(filename)
|
||||
title = file.readline()
|
||||
lines = file.readlines()
|
||||
x = []
|
||||
y = []
|
||||
for line in lines:
|
||||
line.strip()
|
||||
data = line.split()
|
||||
x.append(float(data[0]))
|
||||
y.append(float(data[1]))
|
||||
|
||||
return x, y, round(min(x),3), round(max(y),2)
|
||||
|
||||
x_meas, y_meas, x_meas_min, y_meas_max = get_data('Python/Plotting/Base/Measured.txt') #Files here
|
||||
x_sim, y_sim, x_sim_min, y_sim_max = get_data("Python/Plotting/Base/Simulated.txt")
|
||||
|
||||
x_min_data = min(x_meas_min, x_meas_min)
|
||||
|
||||
#print(min(x_meas),min(x_sim))
|
||||
|
||||
################################# BASIC PLOT CODE #################################
|
||||
|
||||
# Basic Styling
|
||||
plt.rcParams.update({
|
||||
'font.family': 'Courier New', # monospace font
|
||||
'font.size': 20, # Fonts
|
||||
'axes.titlesize': 30, # |
|
||||
'axes.labelsize': 20, # V
|
||||
'xtick.labelsize': 15,
|
||||
'ytick.labelsize': 15,
|
||||
'legend.fontsize': 20,
|
||||
'figure.titlesize': 20,
|
||||
'figure.figsize': [10,10] # Figure Size
|
||||
})
|
||||
|
||||
# Figure Setup
|
||||
fig, ax = plt.subplots()
|
||||
title = 'PV Diagram' # Title
|
||||
xlab = '% of Volume' # X Label
|
||||
ylab = 'Cyinder Pressure [Bar]' # Y Label
|
||||
ax.set_xlabel(xlab)
|
||||
ax.set_ylabel(ylab, labelpad=0)
|
||||
ax.set_title(title, pad = 0) #pad controls distance to plot
|
||||
ax.spines['top'].set_visible(False) # Controls non axis borders
|
||||
ax.spines['right'].set_visible(False)
|
||||
# ax.set_xscale('log')
|
||||
# ax.set_yscale('log')
|
||||
|
||||
x_min = 0 # Axis Limits and Ticks
|
||||
x_max = 1.1
|
||||
x_step_maj = 1 #steps not division
|
||||
x_step_min = 1
|
||||
|
||||
y_min = 0
|
||||
y_max = 25
|
||||
y_step_maj = 25
|
||||
y_step_min = 1
|
||||
|
||||
ax.set_xlim(x_min,x_max) # X limits
|
||||
ax.set_xticks([x_min_data,1]) # X Major Ticks
|
||||
# ax.set_xticks(np.arange(x_min,x_max,x_step_min), minor=True) # X Minor Ticks
|
||||
|
||||
ax.set_ylim(y_min,y_max) # Y limits
|
||||
ax.set_yticks([y_meas_max,y_sim_max]) # Y Major Ticks
|
||||
# ax.set_yticks(np.arange(y_min,y_max,y_step_min),minor=True) # Y Minor Ticks
|
||||
|
||||
|
||||
# ax.grid(True, which='major',alpha=1, lw=1, ls='--', color='black') # Turn On Major Grid
|
||||
# ax.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()
|
||||
'''
|
||||
|
||||
###################### Multi Line ######################
|
||||
|
||||
x = [x_meas,x_sim,[1,1],[x_min_data,x_min_data],[0,.125],[0,.125]] # List of Lists
|
||||
y = [y_meas,y_sim,[0,1.1],[0,12.5],[y_meas_max,y_meas_max],[y_sim_max,y_sim_max]] # List of Lists
|
||||
|
||||
#### Lists must be equal length ###
|
||||
|
||||
dl = ['Measured', 'Simulated','','','',''] # Data Labels (list)
|
||||
lc = ['black', 'black','black','black','black','black'] # Line Color |
|
||||
ls = ['-','--','--','--', '--','--'] # Line Style |
|
||||
lw = [1.5,2,1,1,1,1] # Line Width V
|
||||
a = [1,1,1,1,1,1]
|
||||
s = [] # Marker Size, 20 is default
|
||||
m = [] # Marker Type, 'o' is default
|
||||
# Use color-hex.com for color pallets
|
||||
# Common ones: Shades of Teal, Ocean Breezes By,Ppt Cv
|
||||
|
||||
|
||||
|
||||
for i in range(len(x)):
|
||||
ax.plot(x[i],y[i],label=dl[i],color=lc[i],linestyle=ls[i],linewidth=lw[i],alpha=a[i])
|
||||
#ax.scatter(x[i],y[i],label=dl[i],color=lc[i],marker=m[i],size=s[i])
|
||||
|
||||
ax.legend(loc='upper right', bbox_to_anchor=(0.85, 0.85), ncol=1, frameon=False, labelspacing=0.2, columnspacing=0.75,
|
||||
handlelength=1, 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
|
||||
|
||||
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
@@ -0,0 +1,114 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def get_data(filename):
|
||||
file = open(filename)
|
||||
lines = file.readlines()
|
||||
x = []
|
||||
y = []
|
||||
for line in lines:
|
||||
line.strip()
|
||||
data = line.split()
|
||||
x.append(float(data[0]))
|
||||
y.append(float(data[1]))
|
||||
return x, y
|
||||
|
||||
|
||||
x, y = get_data('Python/Plotting/Base/10k_rpm.txt')
|
||||
|
||||
|
||||
|
||||
################################# BASIC PLOT CODE #################################
|
||||
|
||||
# Basic Styling
|
||||
plt.rcParams.update({
|
||||
'font.family': 'Courier New', # monospace font
|
||||
'font.size': 20, # Fonts
|
||||
'axes.titlesize': 20, # |
|
||||
'axes.labelsize': 20, # V
|
||||
'xtick.labelsize': 20,
|
||||
'ytick.labelsize': 20,
|
||||
'legend.fontsize': 20,
|
||||
'figure.titlesize': 20,
|
||||
'figure.figsize': [10,5] # Figure Size
|
||||
})
|
||||
|
||||
# Figure Setup
|
||||
fig, ax = plt.subplots()
|
||||
title = '10,000 rpm Jetfire' # Title
|
||||
xlab = 'Power [kW]' # X Label
|
||||
ylab = 'BSFC [g/kW-h]' # Y Label
|
||||
ax.set_xlabel(xlab)
|
||||
ax.set_ylabel(ylab)
|
||||
ax.set_title(title, pad = 20) #pad controls distance to plot
|
||||
ax.spines['top'].set_visible(False) # Controls non axis borders
|
||||
ax.spines['right'].set_visible(False)
|
||||
|
||||
x_min = 2.5 # Axis Limits and Ticks
|
||||
x_max = 10
|
||||
x_step_maj = 1 #steps not division
|
||||
x_step_min = .25
|
||||
|
||||
y_min = 340
|
||||
y_max = 550
|
||||
y_step_maj = 25
|
||||
y_step_min = 5
|
||||
|
||||
ax.set_xlim(x_min,x_max) # X limits
|
||||
ax.set_xticks([3,4,5,6,7,8,9,10]) # X Major Ticks
|
||||
# ax.set_xticks(np.arange(x_min,x_max,x_step_min), minor=True) # X Minor Ticks
|
||||
|
||||
ax.set_ylim(y_min,y_max) # Y limits
|
||||
ax.set_yticks(np.arange(y_min,y_max,y_step_maj)) # Y Major Ticks
|
||||
# ax.set_yticks(np.arange(y_min,y_max,y_step_min),minor=True) # Y Minor Ticks
|
||||
|
||||
|
||||
ax.grid(True, which='major',alpha=0.5) # Turn On Major Grid
|
||||
ax.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='2')
|
||||
# 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.tight_layout()
|
||||
plt.show()
|
||||
|
||||
###################### Multi Line ######################
|
||||
# x = [[],[]] # List of Lists
|
||||
# y = [[],[]] # List of Lists
|
||||
|
||||
# #### Lists must be equal length ###
|
||||
|
||||
# dl = [] # Data Labels (list)
|
||||
# lc = [] # Line Color |
|
||||
# ls = [] # Line Style |
|
||||
# lw = [] # Line Width V
|
||||
# a = [] # Transparency
|
||||
# s = [] # Marker Size, 20 is default
|
||||
# m = [] # Marker Type, 'o' is default
|
||||
# # Use color-hex.com for color pallets
|
||||
# # Common ones: Shades of Teal, Ocean Breezes By,Ppt Cv
|
||||
|
||||
|
||||
|
||||
# for i in range(len(x)):
|
||||
# ax.plot(x[i],y[i],label=dl[i],color=lc[i],linestyle=ls[i],linewidth=lw[i], alpha=a[i])
|
||||
# #ax.scatter(x[i],y[i],label=dl[i],color=lc[i],marker=m[i],size=s[i])
|
||||
|
||||
# ax.legend(loc='center', bbox_to_anchor=(0.5, 1.01), ncol=len(x), frameon=False, labelspacing=0.2, columnspacing=0.75,
|
||||
# handlelength=0.75, 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
|
||||
|
||||
|
||||
# plt.tight_layout()
|
||||
# plt.show()
|
||||
@@ -0,0 +1,185 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
'''
|
||||
This file gives 2 stacked graphs, both with the options to have multiple data sets (Nominally measured and simulated for the top graph and temperature for the bottom)
|
||||
|
||||
It will automatically scale from -180 to 180 for a 2-Stroke
|
||||
|
||||
It needs .txt files copied from the data of GT-Power with the format of:
|
||||
|
||||
title
|
||||
data CAD
|
||||
data CAD
|
||||
. .
|
||||
. .
|
||||
. .
|
||||
|
||||
Other needed info: Max y value for the y axis
|
||||
|
||||
**Will need to adjust colors, line type, etc.**
|
||||
'''
|
||||
|
||||
|
||||
def get_data(filename):
|
||||
file = open(filename)
|
||||
title = file.readline()
|
||||
lines = file.readlines()
|
||||
x = []
|
||||
y = []
|
||||
x_shift = []
|
||||
y_shift = []
|
||||
for line in lines:
|
||||
line.strip()
|
||||
data = line.split()
|
||||
if float(data[0])<=180:
|
||||
x.append(float(data[0]))
|
||||
y.append(float(data[1]))
|
||||
else:
|
||||
x_shift.append(float(data[0])-360)
|
||||
y_shift.append(float(data[1]))
|
||||
|
||||
return x_shift+x, y_shift+y
|
||||
|
||||
x_meas, y_meas = get_data('Python/Plotting/Base/Measured_P.txt') #Files go here
|
||||
x_sim, y_sim = get_data("Python/Plotting/Base/Simulated_P.txt")
|
||||
|
||||
x_temp, y_temp = get_data("Python/Plotting/Base/temperature.txt")
|
||||
|
||||
################################# BASIC PLOT CODE #################################
|
||||
|
||||
# Basic Styling
|
||||
plt.rcParams.update({
|
||||
'font.family': 'Courier New', # monospace font
|
||||
'font.size': 20, # Fonts
|
||||
'axes.titlesize': 20, # |
|
||||
'axes.labelsize': 20, # 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(2)
|
||||
title = 'Cylinder Pressure Trace' # Title
|
||||
ax[0].set_title(title, pad = 20) #pad controls distance to plot
|
||||
|
||||
### Figure 1 (top) ###
|
||||
x_1_lab = '' # X Label
|
||||
y_1_lab = 'Pressure [Bar]' # 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)
|
||||
|
||||
### Figure 2 (bottom) ###
|
||||
x_2_lab = '' # X Label
|
||||
y_2_lab = 'Temperature [K]' # 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)
|
||||
|
||||
### axis is the same for both graphs ###
|
||||
### x displays on bottom graph only ###
|
||||
x_min = -180 # Axis Limits and Ticks
|
||||
x_max = 180
|
||||
x_step_maj = 1 #steps not division
|
||||
x_step_min = 1
|
||||
|
||||
ax[1].set_xlim(x_min,x_max) # X limits
|
||||
ax[1].set_xticks([-180,-90,0,90,180],['BDC\n-180°','Intake/Compression','TDC\n0°','Exhaust/Expansion','BDC\n180°']) # X Major Ticks
|
||||
ax[1].set_xticks([-180,-90,0,90,180], minor=True) # X Minor Ticks
|
||||
|
||||
ax[0].set_xlim(x_min,x_max) # X limits
|
||||
ax[0].set_xticks([-180,-90,0,90,180],[]) # X Major Ticks
|
||||
ax[0].set_xticks([-180,-90,0,90,180], minor=True) # X Minor Ticks
|
||||
|
||||
### Figure 1 (top) ###
|
||||
y_1_min = 0
|
||||
y_1_max = 36
|
||||
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),tickpad = 10) # 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 = 500
|
||||
y_2_max = 2150
|
||||
y_2_step_maj = 200
|
||||
y_2_step_min = 100
|
||||
|
||||
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),tickpad = 10) # 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
|
||||
|
||||
###################### 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 = [x_meas,x_sim,[0,0]] # List of Lists
|
||||
y1 = [y_meas,y_sim,[0,36]] # List of Lists
|
||||
|
||||
dl1 = ['Measured','Simulated',''] # Data Labels (list)
|
||||
lc1 = ['black','black','black'] # Line Color |
|
||||
ls1 = ['--','-','-'] # Line Style |
|
||||
lw1 = [2,2,1] # Line Width V
|
||||
a1 = [1,1,0.8] # 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.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
|
||||
|
||||
x2 = [x_temp,[0,0]] # List of Lists
|
||||
y2 = [y_temp,[0,2150]] # List of Lists
|
||||
|
||||
dl2 = ['',''] # Data Labels (list)
|
||||
lc2 = ['black','black'] # Line Color |
|
||||
ls2 = ['-','-'] # Line Style |
|
||||
lw2 = [2,1] # Line Width V
|
||||
a2 = [1,0.8] # 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
|
||||
|
||||
|
||||
|
||||
plt.tight_layout()
|
||||
plt.show()
|
||||
Reference in New Issue
Block a user