Skip to content

Instantly share code, notes, and snippets.

@Alan-FGR
Created November 19, 2016 13:35
Show Gist options
  • Select an option

  • Save Alan-FGR/b4bfa652d74d55ba331269b9d99d910a to your computer and use it in GitHub Desktop.

Select an option

Save Alan-FGR/b4bfa652d74d55ba331269b9d99d910a to your computer and use it in GitHub Desktop.
Totally Fine Readable Descriptive High-Quality Code
def plot(titl,xvals,yvals,xl,yl,pxw=720,pxh=450,dpi=80,xts=4,yts=1,inv=False):
from matplotlib import pyplot as plt; import matplotlib as mpl;
plt.style.use('seaborn-bright');
fig = plt.figure(figsize=(pxw/dpi, pxh/dpi), dpi=dpi, facecolor='w')
fig.subplots_adjust(left=.08, bottom=.1, right=.95, top=.92)
ax = fig.add_subplot(111); ax.minorticks_on()
ax.get_xaxis().set_minor_locator(mpl.ticker.AutoMinorLocator(xts))
ax.get_yaxis().set_minor_locator(mpl.ticker.AutoMinorLocator(yts))
ax.grid(b=True, which='minor',alpha=0.07,linestyle='-')
ax.grid(b=True, which='major',alpha=0.21,linestyle='-')
plt.xlabel(yl if inv else xl); plt.ylabel(xl if inv else yl)
for v in map(lambda x: list(reversed(x)), xvals):
c = v[2] if len(v) > 2 else None;ls = v[3] if len(v) > 3 else None
y = yvals[:len(v[0])];xv=y if inv else v[0];yv=v[0] if inv else y
ax.plot(xv,yv,label=v[1],c=c,lw=2,ls=ls)
mpl.rcParams['savefig.dpi']=dpi;mpl.rcParams['savefig.directory']='.'
ax.legend();plt.title(titl);plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment