Skip to content

Instantly share code, notes, and snippets.

View gilliss's full-sized avatar

Tom Gilliss gilliss

View GitHub Profile
@gilliss
gilliss / CustomColorList.py
Last active August 22, 2018 01:11
A custom list of colors in matplotlib.pyplot
"""
Create a custom list of colors for use in data visualization
"""
import matplotlib.pyplot as plt
import numpy as np
# create n data points
n = 20
xData = np.linspace(0,n,n)
@gilliss
gilliss / AxisBinLabelsROOT.cc
Last active June 12, 2018 13:44
Change axis bin labels in ROOT
/*
Code to change the strings used for TAxis bin labels in ROOT.
Ref:
https://root.cern.ch/doc/master/classTAxis.html
*/
#include <map>
#include <string>
#include <iostream>
@gilliss
gilliss / barh_left_right.py
Last active May 22, 2018 16:37
Plotting a vertical orientation histogram, from the right or left side of an axes object, using matplotlib.pyplot.barh
"""
Plotting a matplotlib.pyplot.barh from the left or right of axes
Ref:
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.barh.html
https://matplotlib.org/examples/lines_bars_and_markers/barh_demo.html
"""
import numpy as np
import matplotlib.pyplot as plt
@gilliss
gilliss / chstwo.py
Last active April 15, 2019 14:17
Chi-square test for the difference between two data sets
"""
A chi-square test for the difference between two data sets.
_count() method is from SciPy's https://github.com/scipy/scipy/blob/v0.14.0/scipy/stats/stats.py#L3467
A version of this function is in NRC, and related functions are in SciPy:
NRC: chstwo(bins1, bins2, nbins, knstrn, df, chsq, prob)
SciPy: power_divergence(f_obs, f_exp=None, ddof=0, axis=0, lambda_=None)
"""
import numpy as np
@gilliss
gilliss / MarginalizeMesh.py
Last active May 4, 2018 14:51
Marginalize a 2D distribution calculated over a np.meshgrid
"""
Marginalize a 2-dimensional distribution evaluated over a numpy meshgrid.
-The Distribution class holds the distribution, the marginalization method,
and the grid parameters to be used for the integration.
-The Marginalize() method allows specification of the axis you would like to marginalize.
The marginalization is done via simple grid integration, using rectangular Riemann
sum approximation of integral.
There is similar code in scipy's scipy/stats/tests/test_multivariate.py::test_marginalization()