Useful python snippets

A quick handy reference to some python snippets Find path to a package or module import os print os.path.dirname(packagename.__file__) List all modules inside a package import pkgutils import os [name for _, name, _ in...
How to plot multicolored lines  in matplotlib?

How to plot multicolored lines in matplotlib?

Often times, we need to overlay colors on segments of a time-series or other line-plot. The colors could be indicative of some events or to highly particularly important time-spans of interest. Here’s a short function that can be used to generate such line...