-def plot_datehist(ax, data, bins, suites, title=None, ymax=None):
- colors=['#ff0088', '#20435C', '#45902C', '#E08720']
- linestyle=['-', '--']
- global_x_max = None
- global_x_min = None
- global_y_max = None
- for i, suite in enumerate(suites):
- dates = data['date'][data['suite'] == suite]
- # history in days
- history_length = dates.max() - dates.min()
- # make approx monthly bins, smaller bins yield spiky curves
- # needs new=True to work with oldish numpy
- (hist, bin_edges) = np.histogram(dates, np.ceil(history_length/30.))
- if False:
- # debug output ;-)
- print dates.min(), num2date(dates.min()), dates.max(), \
- num2date(dates.max()), history_length
- print bin_edges
- if len(bin_edges) < 2:
- # protect against single data point entries by ignoring them
- # wouldn't be able to draw a line anyway ;-)
- continue
- width = bin_edges[1] - bin_edges[0]
- # think lines
- y = hist / width
- global_y_max = max(max(y), global_y_max)
- ax.plot(bin_edges[:-1]+(width/2), y,
- label=suite, color=colors[i%4], linestyle=linestyle[i//4], lw=2)
- # transparent curve shading
- ax.fill_between(bin_edges[:-1]+(width/2), 0, hist / width, alpha=0.2,
- label=suite, color=colors[i%4])
- # figure out axis limits to avoid whitespace in plots
- x_max = bin_edges[-2] + width/2
- x_min = bin_edges[0] + width/2
-
- global_x_max = max(x_max, global_x_max)
- if global_x_min is None or x_min < global_x_min:
- global_x_min = x_min
-
- ax.set_xlim(global_x_min, global_x_max)
- ax.set_ylabel('New subscriptions [1/day]')
- if title:
- ax.set_title(title)
- if not ymax:
- # Always leave significant 5% for improvement ;-)
- ymax = global_y_max * 1.05
- ax.set_ylim(0, ymax)