Skip to content

Instantly share code, notes, and snippets.

@cobalamin
Created September 3, 2020 12:39
Show Gist options
  • Save cobalamin/10ed5fd87ab8257e6a57e44bd66a2529 to your computer and use it in GitHub Desktop.
Save cobalamin/10ed5fd87ab8257e6a57e44bd66a2529 to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
class Paper(object):
def __init__(self, force_inline=True):
from copy import copy
self.orig_rc = copy(plt.rcParams)
self.force_inline = force_inline
def __enter__(self):
if self.force_inline:
get_ipython().magic('matplotlib inline')
plt.rcParams['text.usetex'] = True
plt.rcParams['text.latex.preamble'] = '\DeclareUnicodeCharacter{2212}{-}'
plt.rcParams['font.family'] = 'serif'
plt.rcParams['font.size'] = 16
def __exit__(self, type, value, traceback):
plt.rcParams.update(self.orig_rc)
if self.force_inline:
get_ipython().magic('matplotlib notebook')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment