Skip to content

Instantly share code, notes, and snippets.

@ebressert
Created March 6, 2018 16:47
Show Gist options
  • Save ebressert/f8df1e6bf71f0eb6b36d6f9e4d6595f2 to your computer and use it in GitHub Desktop.
Save ebressert/f8df1e6bf71f0eb6b36d6f9e4d6595f2 to your computer and use it in GitHub Desktop.
Minimalist histogram/spark plot
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# Overwriting colab color scheme
sns.set_style("white")
def gen(n=40):
return np.random.normal(size=n)
rows, cols = 3, 5
fsize = 15
rownames = ['row a', 'row b', 'row c']
colnames = ['col a', 'col b', 'col c', 'col d', 'col e']
f, axs = plt.subplots(rows, cols, sharex='col', figsize=(15, 6))
for i in range(rows):
for j in range(cols):
_ = axs[i,j].hist(gen(), histtype='step', color='black')
axs[i,j].set_xticks([])
axs[i,j].set_yticks([])
left, right = _[1][0], _[1][-1]
axs[i,j].scatter(left, 0, c='black', s=15)
axs[i,j].scatter(right, 0, c='black', s=15)
axs[i,j].annotate(str(int(left)),
xy=(left, 0),
xytext=(-5, -20),
textcoords='offset points')
axs[i,j].annotate(str(int(right)),
xy=(right, 0),
xytext=(-5, -20),
textcoords='offset points')
if i == 0:
axs[i,j].set_xlabel(colnames[j], labelpad=15, size=fsize)
axs[i,j].xaxis.set_label_position('top')
if j == 0:
axs[i,j].set_ylabel(rownames[i], size=fsize)
f.subplots_adjust(hspace=1.5)
sns.despine(left=True, bottom=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment