This week I had to make a “burn chart”, essentially a chart showing amount of work per week. Since the weeks are discrete time steps I need a step function. I started playing with horizontal and vertical lines but luckily I quickly found that matplotlib has a step function. Unfortunately, it didn’t quite act as I thought.
There are there options for the drawstyle:
Assume the x-vector and y-vector for plotting is
X = [x1, x2, x3, x4] Y = [y1, y2, y3, y4]
For me, ‘steps-post’ makes the most sense to understand. Below is code to illustrate the options.
%matplotlib inline from matplotlib import pylab as plt
# make some date x = [0, 10, 20, 30, 40] y = [0, 10, 20, 30, 40] # disregard, this is my personal "make pretty" function fig, ax = myfig() # plot out the options plt.plot(x, y, drawstyle='steps', linestyle='-', label='steps-pre aka steps', alpha=0.5,) plt.plot(x, y, drawstyle='steps-mid', linestyle='--', label='steps-mid', alpha=0.5,) plt.plot(x, y, drawstyle='steps-post', linestyle=':', label='steps-post', alpha=0.5,) plt.xlim([0,45]) plt.legend(loc='upper left') plt.show()
%reload_ext version_information %version_information ipython, pandas, matplotlib
|Python||2.7.5+ (default, Feb 27 2014, 19:39:55) [GCC 4.8.1]|
|Tue Nov 11 22:08:24 2014 PST|