90 lines
2.6 KiB
Python
90 lines
2.6 KiB
Python
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
x_data = np.linspace(0,10,150)
|
|
y1 = np.sin(3*x_data+(3.14159/2))
|
|
y2 = 1.5*np.e**(-0.7*x_data)
|
|
y3 = 1.5*np.e**(-0.7*x_data)*np.sin(3*x_data+(3.14159/2))
|
|
|
|
|
|
################################# BASIC PLOT CODE #################################
|
|
|
|
# Basic Styling
|
|
plt.rcParams.update({
|
|
'font.family': 'Courier New', # monospace font
|
|
'font.size': 20, # Fonts
|
|
'axes.titlesize': 30, # |
|
|
'axes.labelsize': 25, # V
|
|
'xtick.labelsize': 20,
|
|
'ytick.labelsize': 20,
|
|
'legend.fontsize': 20,
|
|
'figure.titlesize': 30,
|
|
'figure.figsize': [9,6] # Figure Size
|
|
})
|
|
|
|
# Figure Setup
|
|
fig, ax = plt.subplots()
|
|
title = 'Damped Oscillation' # Title
|
|
xlab = 'Time' # X Label
|
|
ylab = 'Force' # Y Label
|
|
ax.set_xlabel(xlab)
|
|
ax.set_ylabel(ylab)
|
|
ax.set_title(title, pad=40)
|
|
#fig.suptitle(title)
|
|
|
|
x_min = 0 # Axis Limits and Ticks
|
|
x_max = 10
|
|
x_step = 1
|
|
|
|
y_min = -1.5
|
|
y_max = 1.6
|
|
y_step = 1
|
|
|
|
ax.set_xlim(x_min,x_max)
|
|
ax.set_xticks(np.arange(x_min,x_max,x_step))
|
|
ax.set_xticks(np.arange(x_min,x_max,0.5), minor=True)
|
|
|
|
ax.set_ylim(y_min,y_max)
|
|
ax.set_yticks(np.arange(y_min,y_max,y_step))
|
|
ax.set_yticks(np.arange(y_min,y_max,0.5),minor=True)
|
|
|
|
#ax.minorticks_on()
|
|
|
|
ax.grid(True, which='major',alpha=0.5)
|
|
ax.grid(True, which='minor',alpha=0.2)
|
|
|
|
|
|
###################### 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
|
|
|
|
# plt.show()
|
|
|
|
###################### Multi Line ######################
|
|
x = [x_data,x_data,x_data] # List of Lists
|
|
y = [y1,y2,y3] # List of Lists
|
|
|
|
#### Lists must be equal length ###
|
|
|
|
dl = ['Sine Part', 'Exponential Part','Result'] # Data Labels (list)
|
|
lc = ['#ae5a41', '#559e83','#5a5255'] # Line Color |
|
|
ls = ['--','--','-'] # Line Style |
|
|
lw = ['1','1','2'] # Line Width V
|
|
|
|
for i in range(len(x)):
|
|
ax.plot(x[i],y[i],label=dl[i],color=lc[i],linestyle=ls[i],linewidth=lw[i])
|
|
|
|
ax.legend(loc='center', bbox_to_anchor=(0.5, 1.04), ncol=len(x), frameon=False, columnspacing=1, handlelength=0.75,
|
|
handletextpad=0.2)
|
|
# anchor loc is based on the plot area, 0.5 is half the width, 1.01 is just above the top
|
|
|
|
|
|
plt.tight_layout()
|
|
plt.show()
|
|
|