Skip to content

Instantly share code, notes, and snippets.

@aminnj
Last active September 30, 2018 22:28
Show Gist options
  • Save aminnj/98563f84ca393302a3a5e28abfe956ca to your computer and use it in GitHub Desktop.
Save aminnj/98563f84ca393302a3a5e28abfe956ca to your computer and use it in GitHub Desktop.
excel-themed matplotlib plots
import os
import numpy as np
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
# matplotlib.font_manager._rebuild() # after installing calibri
from matplotlib import rcParams
from cycler import cycler
rcParams['axes.edgecolor'] = "#b0b0b0"
rcParams['axes.grid'] = True
rcParams['axes.grid.axis'] = "y"
rcParams['axes.labelsize'] = 'x-large'
rcParams['axes.prop_cycle'] = cycler( color = ["#4572A7", "#AA4643", "#89A54E", "#71588F", "#4198AF", "#DB843D", "#93A9CF", "#D19392", "#B9CD96", "#A99BBD"], marker = ["D","s","^","x","*","o","|","-","v","."],)
rcParams['axes.spines.right'] = False
rcParams['axes.spines.top'] = False
rcParams['axes.titlesize'] = 20
rcParams['axes.titleweight'] = "bold"
rcParams['axes.xmargin'] = 0.02
rcParams['axes.ymargin'] = 0.02
rcParams['font.family'] = 'Calibri'
rcParams['grid.color'] = "#808080"
rcParams['grid.alpha'] = 0.5
rcParams['hist.bins'] = "auto"
rcParams['legend.borderaxespad'] = 0.
rcParams['legend.fancybox'] = False
rcParams['legend.fontsize'] = 'large'
rcParams['legend.framealpha'] = 0.
rcParams['legend.loc'] = "best"
rcParams['legend.shadow'] = False
rcParams['lines.linewidth'] = 2.0
rcParams['patch.linewidth'] = 2.0
rcParams['lines.markersize'] = 7
rcParams['xtick.labelsize'] = 'large'
rcParams['ytick.labelsize'] = 'large'
data = [
[0.0,11,14,17],
[1.0,12,14,17],
[2.0,13,14,17],
[2.0,13,15,18],
[3.0,14,15,18],
[4.0,15,15,18],
[5.0,14,16,19],
[5.0,15,17,20],
[5.0,16,19,22],
[6.0,16,20,23],
[7.0,17,23,26],
[9.0,18,24,27],
]
data = np.array(data)
fig, ax = plt.subplots(nrows=1, ncols=1)
ax.plot(data[:,0],data[:,1], label="foo")
ax.plot(data[:,0],data[:,2], label="bar")
ax.plot(data[:,0],data[:,3], label="baz")
ax.hist(9*np.random.random(150),bins=15,label="hist2",rwidth=0.6)
ax.set_xlabel("lumi [ifb]")
ax.set_ylabel("sigma")
ax.set_title("random excel plot title")
ax.legend()
fig.savefig("plot.png")
@aminnj
Copy link
Author

aminnj commented Sep 30, 2018

Example plot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment