Fixed font configuration screwyness, and smith plotting size.
This commit is contained in:
		
							parent
							
								
									6c78fa6005
								
							
						
					
					
						commit
						0afd12eaed
					
				
					 4 changed files with 96 additions and 4 deletions
				
			
		| 
						 | 
					@ -7,15 +7,45 @@
 | 
				
			||||||
################################################################################
 | 
					################################################################################
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import matplotlib
 | 
					import matplotlib
 | 
				
			||||||
 | 
					import matplotlib.font_manager as FM
 | 
				
			||||||
 | 
					import re
 | 
				
			||||||
from matplotlib import rcParams, pyplot as pp
 | 
					from matplotlib import rcParams, pyplot as pp
 | 
				
			||||||
from cycler import cycler
 | 
					from cycler import cycler
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fcFontList = FM.get_fontconfig_fonts()
 | 
				
			||||||
 | 
					# Search only for fonts that have name matches similar to this
 | 
				
			||||||
 | 
					# note this is ALSO a priority list
 | 
				
			||||||
 | 
					fontsDesired = ['Times', 'Helvetica', 'Arial']
 | 
				
			||||||
 | 
					fontsDesiredRe = re.compile('|'.join(fontsDesired), flags=re.IGNORECASE)
 | 
				
			||||||
 | 
					# Create a unique set of the fonts selected out of all of the system fonts
 | 
				
			||||||
 | 
					fontsAvailable = frozenset([FM.FontProperties(fname=fcFont).get_name()\
 | 
				
			||||||
 | 
						for fcFont in fcFontList if fontsDesiredRe.search(fcFont) != None])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fontSelected=None
 | 
				
			||||||
 | 
					for fontSearch in fontsDesired:
 | 
				
			||||||
 | 
						for fontFound in fontsAvailable:
 | 
				
			||||||
 | 
							if re.search(fontSearch, fontFound, flags=re.IGNORECASE) != None:
 | 
				
			||||||
 | 
								fontSelected = fontFound
 | 
				
			||||||
 | 
								break
 | 
				
			||||||
 | 
						if fontSelected != None:
 | 
				
			||||||
 | 
							break
 | 
				
			||||||
 | 
					if fontSelected == None:
 | 
				
			||||||
 | 
						print("WARN: None of the requested fonts found on this system.")
 | 
				
			||||||
 | 
					else:
 | 
				
			||||||
 | 
						print("INFO: Using font '%s'" % (fontSelected))
 | 
				
			||||||
 | 
						newFontPriority = [fontSelected]
 | 
				
			||||||
 | 
						newFontPriority.extend(rcParams['font.serif'])
 | 
				
			||||||
 | 
						rcParams['font.serif'] = newFontPriority
 | 
				
			||||||
 | 
					
 | 
				
			||||||
rcParams['grid.alpha'] = 0.5
 | 
					rcParams['grid.alpha'] = 0.5
 | 
				
			||||||
rcParams['grid.linestyle'] = ':'
 | 
					rcParams['grid.linestyle'] = ':'
 | 
				
			||||||
rcParams['font.family'] = ['serif']
 | 
					rcParams['font.family'] = ['serif']
 | 
				
			||||||
rcParams['font.size'] = 6.5
 | 
					rcParams['font.size'] = 7
 | 
				
			||||||
rcParams['mathtext.fontset'] = 'dejavuserif'
 | 
					#rcParams['figure.titlesize'] = "medium"
 | 
				
			||||||
rcParams['mathtext.fontset'] = 'dejavuserif'
 | 
					rcParams['axes.titlesize'] = 9
 | 
				
			||||||
 | 
					rcParams['figure.titlesize'] = rcParams['axes.titlesize']
 | 
				
			||||||
 | 
					#rcParams['mathtext.fontset'] = 'dejavuserif'
 | 
				
			||||||
 | 
					#rcParams['mathtext.fontset'] = 'custom'
 | 
				
			||||||
rcParams['mathtext.it'] = 'serif:italic'
 | 
					rcParams['mathtext.it'] = 'serif:italic'
 | 
				
			||||||
rcParams['mathtext.bf'] = 'serif:bold'
 | 
					rcParams['mathtext.bf'] = 'serif:bold'
 | 
				
			||||||
rcParams['mathtext.sf'] = 'serif'
 | 
					rcParams['mathtext.sf'] = 'serif'
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										52
									
								
								README.md
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								README.md
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,52 @@
 | 
				
			||||||
 | 
					# What is this?
 | 
				
			||||||
 | 
					This whole tool is a basic front end for using Python's `matplotlib` in a
 | 
				
			||||||
 | 
					moderately interactive and robust manner to do MATLAB-like number crunching and
 | 
				
			||||||
 | 
					(more critically) plot generation for papers.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## MATLAB Soapbox Explanation
 | 
				
			||||||
 | 
					While MATLAB has routines to save figures, the graphics back-end routinely runs
 | 
				
			||||||
 | 
					into issues with NVIDIA GPU based systems, and I'm sick and tired of being tied
 | 
				
			||||||
 | 
					to a tool that has a heavy resource footprint and only moderate documentation.
 | 
				
			||||||
 | 
					The licensing restrictions (though not fundamentally debilitating) are a
 | 
				
			||||||
 | 
					secondary reason I'm moving away from MATLAB. Finally, as I expect to graduate
 | 
				
			||||||
 | 
					soon, the $50 (or $130 for my toolboxes) annual cost is going to rise to a
 | 
				
			||||||
 | 
					debilitating point for things as mundane as personal projects. So I might as
 | 
				
			||||||
 | 
					well kick an expensive habit while it's easy to fall back when needed.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Resources
 | 
				
			||||||
 | 
					There are a few tricks to help configuring `matplotlib`. I'll update this
 | 
				
			||||||
 | 
					document to describe the commands and tools to help decipher the information
 | 
				
			||||||
 | 
					required to produce plots in a repeatable and tidy way.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 1. Plot Defaults
 | 
				
			||||||
 | 
					Plot defaults are managed by the `matplotlib`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 2. Font Selection
 | 
				
			||||||
 | 
					```python
 | 
				
			||||||
 | 
					import `matplotlib`.font_manager
 | 
				
			||||||
 | 
					print(matplotlib.font_manager.fontManager.afmlist)
 | 
				
			||||||
 | 
					print(matplotlib.font_manager.fontManager.ttflist)
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					I search for fonts using the following method:
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					import matplotlib.font_manager as FM
 | 
				
			||||||
 | 
					import re
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fcFontList = FM.get_fontconfig_fonts()
 | 
				
			||||||
 | 
					# Search only for fonts that have name matches similar to this
 | 
				
			||||||
 | 
					fontsDesired = ['Helvetica', 'Times', 'Arial']
 | 
				
			||||||
 | 
					fontsDesiredRe = re.compile('|'.join(fontsDesired), flags=re.IGNORECASE)
 | 
				
			||||||
 | 
					# Create a unique set of the fonts selected out of all of the system fonts
 | 
				
			||||||
 | 
					fontsAvailable = set([FM.FontProperties(fname=fcFont).get_name()\
 | 
				
			||||||
 | 
						for fcFont in fcFontList if fontsDesiredRe.search(fcFont) != None])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[matplotlib docs](https://matplotlib.org/api/font_manager_api.html)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 3. 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# TODO
 | 
				
			||||||
 | 
					* make pySmithPlot a git sub-module
 | 
				
			||||||
 | 
					* think of a smarter way to refactor things (this is an ever evolving goal)
 | 
				
			||||||
							
								
								
									
										0
									
								
								runAll.sh
									
										
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										0
									
								
								runAll.sh
									
										
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
								
								
									
										12
									
								
								tankPlot.py
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								tankPlot.py
									
										
									
									
									
								
							| 
						 | 
					@ -40,6 +40,8 @@ import sys
 | 
				
			||||||
sys.path.append("./pySmithPlot")
 | 
					sys.path.append("./pySmithPlot")
 | 
				
			||||||
import smithplot
 | 
					import smithplot
 | 
				
			||||||
from smithplot import SmithAxes
 | 
					from smithplot import SmithAxes
 | 
				
			||||||
 | 
					SmithAxes.update_scParams(axes_normalize=False,
 | 
				
			||||||
 | 
					 	grid_minor_fancy_threshold=50, axes_radius=0.5)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
plot_list = [args.n]
 | 
					plot_list = [args.n]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -66,6 +68,7 @@ from tankComputers import *
 | 
				
			||||||
freq_pts = 501
 | 
					freq_pts = 501
 | 
				
			||||||
 | 
					
 | 
				
			||||||
S=TankGlobals.ampSystem()
 | 
					S=TankGlobals.ampSystem()
 | 
				
			||||||
 | 
					Sgv=TankGlobals.ampSystem()
 | 
				
			||||||
B=TankGlobals.bufferSystem()
 | 
					B=TankGlobals.bufferSystem()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
S.q1_L = 15
 | 
					S.q1_L = 15
 | 
				
			||||||
| 
						 | 
					@ -219,7 +222,7 @@ if 1 in plot_list or 11 in plot_list:
 | 
				
			||||||
		[hT.show() for hT in h1]
 | 
							[hT.show() for hT in h1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if 4 in plot_list or 14 in plot_list:
 | 
					if 4 in plot_list or 14 in plot_list:
 | 
				
			||||||
	h4 = [pp.figure(figsize=(3.4,3.4)) for x in range(2)]
 | 
						h4 = [pp.figure(figsize=(3.4,3)) for x in range(2)]
 | 
				
			||||||
	ax4 = []
 | 
						ax4 = []
 | 
				
			||||||
	ax4.append(h4[0].add_subplot(1,1,1, projection='smith'))
 | 
						ax4.append(h4[0].add_subplot(1,1,1, projection='smith'))
 | 
				
			||||||
	ax4.append(h4[1].add_subplot(1,1,1, projection='polar'))
 | 
						ax4.append(h4[1].add_subplot(1,1,1, projection='polar'))
 | 
				
			||||||
| 
						 | 
					@ -230,6 +233,13 @@ if 4 in plot_list or 14 in plot_list:
 | 
				
			||||||
	ax4[0].set_title('Tank Impedance')
 | 
						ax4[0].set_title('Tank Impedance')
 | 
				
			||||||
	ax4[1].set_title('Transfer Function')
 | 
						ax4[1].set_title('Transfer Function')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						# Adjust placement of smith plot
 | 
				
			||||||
 | 
						old_pos = ax4[0].title.get_position()
 | 
				
			||||||
 | 
						ax4[0].title.set_position((old_pos[0], 1.06))
 | 
				
			||||||
 | 
						p = ax4[0].get_position()
 | 
				
			||||||
 | 
						p.set_points([[0, 0.07],[1, 0.86]])
 | 
				
			||||||
 | 
						ax4[0].set_position(p)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	old_pos = ax4[1].title.get_position()
 | 
						old_pos = ax4[1].title.get_position()
 | 
				
			||||||
	ax4[1].title.set_position((old_pos[0], 1.1))
 | 
						ax4[1].title.set_position((old_pos[0], 1.1))
 | 
				
			||||||
	h4[1].tight_layout()
 | 
						h4[1].tight_layout()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue