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()