Skip to content

Instantly share code, notes, and snippets.

View ebressert's full-sized avatar

Eli Bressert ebressert

View GitHub Profile
@ebressert
ebressert / dist_plot.py
Created March 6, 2018 16:47
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)
def column_cleaner(df, inplace=False):
"""
Clean up column names where white spaces are trimmed and replaced.
All column names are lowercased for sanity.
"""
orig_cols = df.columns
new_cols = []
for col in orig_cols:
new_cols.append("".join([c if c.isalnum() else "_" for c in col.strip()]).lower())
import seaborn as sns
from scipy.optimize import curve_fit
# Function for linear fit
def func(x, a, b):
return a + b * x
# Seaborn conveniently provides the data for
# Anscombe's quartet.
df = sns.load_dataset("anscombe")
@ebressert
ebressert / colormap_editor.py
Last active September 28, 2020 14:57
Advanced color editing for Matplotlib and Seaborn
import colorsys
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
def alter(alist, col, factor=1.1):
tmp = np.array(alist)
tmp[:,col] = tmp[:,col] * factor
tmp[tmp > 1] = 1