Skip to content

Instantly share code, notes, and snippets.

@arnaldorusso
Created January 20, 2015 15:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnaldorusso/bd954144ad6150c9a64c to your computer and use it in GitHub Desktop.
Save arnaldorusso/bd954144ad6150c9a64c to your computer and use it in GitHub Desktop.
Help Arial font Seaborn using Tex
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
import seaborn as sns
# This line is a patch to Seaborn deal with mpl last version.
# sns.set_context(rc={'lines.markeredgewidth': 0.1}) # deal with mpl markers
xs = np.arange(200)
sns.set_style("whitegrid")
sea_color = sns.dark_palette("skyblue", 8, reverse=True)
sns.axes_style({'font.family': ['sans-serif'],
'font.sans-serif': ['Arial']
})
fig = plt.figure(figsize=(5.5, 3.4))
ax = fig.add_subplot(111)
rc('text', usetex=True)
rc('font',**{'family':'sans-serif','sans-serif':['Arial']})
plt.rcParams.update({
'font.family' : 'sans-serif',
'font.sans-serif' : 'Arial',
'font.style' : 'normal',
'xtick.labelsize' : 9,
'ytick.labelsize' : 9,
'axes.labelsize' : 9,
'mathtext.fontset' : 'stixsans',
'mathtext.default': 'regular',
'text.usetex' : True,
'text.latex.unicode' : True
})
plt.subplots_adjust(left=0.12, right=0.97, top=0.95, bottom=0.1)
xvals = [0, 30, 60, 90, 120, 150, 180]
ax.set_xticks(xvals)
ax.set_xticklabels(['tick 0', '1', '2','3', '4', '5', 'tick 6'])
ax.set_ylabel('('+u'μ'+r'units $\cdot$ m$^{-2}$ s$^{-1}$)', size=10)
ax.set_yticklabels(['0', '30', '60', '90', '120', '150', '180'])
ax.plot(xs, '*', color=sea_color[-2])
ax.fill_between(np.arange(0, len(xs)),xs, 0, color=sea_color[-2])
table = r'''\begin{tabular}{lccccccc}\hline&tick 0& 1 & 2 & 3 & 4 & 5 & tick 6 \\\hline Text I & 05 & 28 & 80 & 72 & 28 & 5 & 7 \\\hline\end{tabular}'''
plt.text(20,150,table,size=9)
plt.savefig('help_arial.pdf', dpi=300)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment