Skip to content

Instantly share code, notes, and snippets.

@k3kaimu
Created March 1, 2023 08:29
Show Gist options
  • Save k3kaimu/087564df1993f1a4c5b4f23e121eccdc to your computer and use it in GitHub Desktop.
Save k3kaimu/087564df1993f1a4c5b4f23e121eccdc to your computer and use it in GitHub Desktop.
import matplotlib as mpl
mpl.use("pgf")
pgf_with_pdflatex = {
"pgf.texsystem": "pdflatex",
# "font.family": "serif", # use serif/main font for text elements
# "text.usetex": True, # use inline math for ticks
"pgf.rcfonts": False, # don't setup fonts from rc parameters
"pgf.preamble": r"""
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage[scaled]{helvet}
\usepackage[T1]{sansmath}"""
}
mpl.rcParams.update(pgf_with_pdflatex)
import matplotlib.pyplot as plt
import json
import numpy as np
import math
from matplotlib import rc
import re
import os
import zipfile
import msgpack
# rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
## for Palatino and other serif fonts use:
# rc('font',**{'family':'serif','serif':['Palatino']})
# rc('text', usetex=True)
# plt.rcParams['text.latex.preamble'] = [r'\usepackage{amsmath}']
plt.rcParams['figure.figsize'] = (8*0.87, 6*0.87)
plt.rcParams['xtick.direction'] = 'in'
plt.rcParams['ytick.direction'] = 'in'
plt.rcParams['xtick.major.width'] = 1.2
plt.rcParams['ytick.major.width'] = 1.2
plt.rcParams['font.size'] = 14
# plt.rcParams['font.size'] = 16
plt.rcParams['axes.linewidth'] = 1.2
plt.rcParams['lines.markersize'] = 8
plt.gca().yaxis.set_major_formatter(plt.FormatStrFormatter('%.1f'))
plt.locator_params(axis='y',nbins=6)
plt.gca().yaxis.set_tick_params(which='both', direction='in',bottom=True, top=True, left=True, right=True)
def sansmathFormatter(x, pos):
return r'{\sansmath $%.0f$}' % x
def sansmathFormatterExp10(x, pos):
s = math.log10(x)
return r'{\sansmath $10^{%.0f}$}' % s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment