From https://courses.edx.org/c4x/MITx/6.00.2x/asset/lectureCode_plotting-seg1.py