Difference between revisions of "Fbs.py"
Jump to navigation
Jump to search
(Created page with "The `fbs` module is used to set up custom parameters for `matplotlib` to generate standard fonts, figure sizes, and formatting conventions corresponding to FBS conventions.") |
|||
| (4 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | The | + | {| class="wikitable" |
| + | |- | ||
| + | | align=center | '''GitHub URL''' | ||
| + | | https://github.com/murrayrm/fbs2e-python/blob/main/fbs.py | ||
| + | |} | ||
| + | |||
| + | The <TT>fbs</TT> module is used to set up custom parameters for <TT>matplotlib</TT> to generate standard fonts, figure sizes, and formatting conventions corresponding to FBS conventions. | ||
| + | |||
| + | <nowiki> | ||
| + | # fbs.py - FBS customization | ||
| + | # RMM, 8 Oct 2021 | ||
| + | |||
| + | import matplotlib.pyplot as plt | ||
| + | |||
| + | # Set the fonts to match the main text | ||
| + | plt.rc('font', family='Times New Roman', weight='normal', size=14) | ||
| + | plt.rcParams['mathtext.fontset'] = 'cm' | ||
| + | |||
| + | |||
| + | # Create a new figure of a specified size | ||
| + | def figure(size='mlh'): | ||
| + | if size == 'mlh' or size == '221': | ||
| + | plt.figure(figsize=[3.4, 2.55]) | ||
| + | else: | ||
| + | raise ValueError("unknown figure size") | ||
| + | |||
| + | |||
| + | # Print a figure | ||
| + | def savefig(name, pad=0.1, **kwargs): | ||
| + | plt.tight_layout(pad=pad) # clean up plots | ||
| + | plt.savefig(name) # save to file | ||
| + | </nowiki> | ||
Latest revision as of 05:38, 9 October 2021
| GitHub URL | https://github.com/murrayrm/fbs2e-python/blob/main/fbs.py |
The fbs module is used to set up custom parameters for matplotlib to generate standard fonts, figure sizes, and formatting conventions corresponding to FBS conventions.
# fbs.py - FBS customization
# RMM, 8 Oct 2021
import matplotlib.pyplot as plt
# Set the fonts to match the main text
plt.rc('font', family='Times New Roman', weight='normal', size=14)
plt.rcParams['mathtext.fontset'] = 'cm'
# Create a new figure of a specified size
def figure(size='mlh'):
if size == 'mlh' or size == '221':
plt.figure(figsize=[3.4, 2.55])
else:
raise ValueError("unknown figure size")
# Print a figure
def savefig(name, pad=0.1, **kwargs):
plt.tight_layout(pad=pad) # clean up plots
plt.savefig(name) # save to file