Initial commit

This commit is contained in:
2025-11-25 23:05:11 -05:00
commit ca8a84a9ad
40 changed files with 33850 additions and 0 deletions

View File

@@ -0,0 +1,216 @@
import numpy as np
import matplotlib.pyplot as plt
import random
import ast
# Getting Random Data for Examples
random.seed(10)
x = np.linspace(1,20,50)
y1 = np.sin(x)
y2 = np.e**(-0.5*x)
num= np.random.random
def make_basic_single_plot(x:list, y:list, xlabel:str = 'X-Axis', ylabel:str ='Y-Axis', title:str = '', lcolor = ['black'],lstyle: list = ['solid']):
plt.rcParams.update({
'font.family': 'Courier New', # monospace font
'font.size': 20,
'axes.titlesize': 20,
'axes.labelsize': 20,
'xtick.labelsize': 20,
'ytick.labelsize': 20,
'legend.fontsize': 20,
'figure.titlesize': 20,
'figure.figsize': [10,10]
})
fig, ax = plt.subplots()
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
ax.set_title(title)
if type(y)==np.ndarray:
ax.plot(x,y, color=lcolor[0], linestyle=lstyle[0])
if type(y[0])==np.ndarray:
for i in range(len(y)):
ax.plot(x,y[i], color=lcolor[i], linestyle=lstyle[i])
#ax[i].set_color(lcolor[i])
#ax[i.set_linestyle(lstyle[i])]
plt.show()
print("Done")
def make_basic_single_plot_int(x,y):
#Set Base Styling
plt.rcParams.update({
'font.family': 'Courier New', # monospace font
'font.size': 20,
'axes.titlesize': 20,
'axes.labelsize': 20,
'xtick.labelsize': 20,
'ytick.labelsize': 20,
'legend.fontsize': 20,
'figure.titlesize': 20,
'figure.figsize': [10,10]
})
#Basic Inputs
fig, ax = plt.subplots()
title = input("Title: ")
xlab = input("X-axis Label: ")
ylab = input("Y-axis Label: ")
size = input("Figure Size [w, h]: ")
#Set Labels
if size!="def":
plt.rcParams.update({'figure.figsize': ast.literal_eval(size)})
ax.set_xlabel(xlab)
ax.set_ylabel(ylab)
ax.set_title(title)
#Ask for data and add to plot
num = int(input("Number of Datasets: "))
if num==1:
lc = input("Line Color: ")
if lc=='def':
lc='black'
ls = input("Line Style (-,--,:,-.): ")
lw = input("Line Width (def=1): ")
if lw=='def':
lw=1
else:
lw=float(lw)
ax.plot(x,y,color=lc,linestyle=ls,linewidth=lw)
if num>1:
for i in range(num):
dl = input("Data Label: ")
#data = input("First Data Set ([[x],[y]]): ")
#data = ast.literal_eval(data)
lc = input("Line Color: ")
if lc=='def':
lc='black'
ls = input("Line Style (-,--,:,-.): ")
lw = input("Line Width (def=1): ")
if lw=='def':
lw=1
else:
lw=float(lw)
ax.plot(x[i],y[i],label=dl,color=lc,linestyle=ls,linewidth=lw)
ax.legend(loc='center', bbox_to_anchor=(0.5, 1.01), ncol=num, frameon=False)
plt.tight_layout()
plt.show()
################################# 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,10] # Figure Size
})
# Figure Setup
fig, ax = plt.subplots()
title = '' # Title
xlab = '' # X Label
ylab = '' # 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 = 0 # Axis Limits and Ticks
x_max = 1
x_step_maj = 1 #steps not division
x_step_min = 1
y_min = 0
y_max = 1
y_step_maj = 1
y_step_min = 1
ax.set_xlim(x_min,x_max) # X limits
ax.set_xticks(np.arange(x_min,x_max,x_step_maj)) # 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='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 = [[],[]] # 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
# Green Palette:
'#002005'
'#164f29'
'#3b7639'
'#638d66'
'#b5c5b4'
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()