Skip to content

Instantly share code, notes, and snippets.

@msbc
msbc / cgs.py
Last active April 15, 2017 18:25
Physical constants in cgs units.
import numpy as np
import sympy as sp
from sympy.physics import units as u
import matplotlib.pyplot as plt
from sympy.core.symbol import Symbol
Q = sp.Rational
sqrt = sp.sqrt
pi = sp.pi
@msbc
msbc / erdc_iceFire.py
Created June 19, 2019 19:51
Colormaps
import numpy as np
from matplotlib.colors import LinearSegmentedColormap as LSC
from matplotlib.cm import register_cmap
def modulo_cmap(cmap, name=None):
colors = np.roll(cmap(np.arange(cmap.N)), cmap.N // 2, axis=0)
if name is None:
name = map.name + "_mod"
return LSC.from_list(name, colors, cmap.N)
@msbc
msbc / neutral_center_colormap.py
Created May 24, 2022 15:33
Defines a neutral center colormap
import numpy as np
from matplotlib.colors import LinearSegmentedColormap as LSC
from matplotlib.cm import register_cmap
def neut_cmap(s=0.5, n=256, name='NCcmap'):
"""Usage : neut_cmap(s=0.5, n=256)
Output a color-map that is neutral (gray) in the middle,
use reddish/warm colors at the upper end,
and use blueish/cool colors at the lower end.