This nice blog post by Randy Zwitch shows off the capabilities of a handful of plotting frameworks, with (surpsisingly?) good results for matplotlib. The post makes the correct point that it's not worth trying to wring this particular plot out of seaborn.barplot
, which sacrifices some control – specifically over the bar widths – to simplify the code that groups the bars by a third variable.
However, seaborn is meant to be mixed with direct calls to matplotlib functions, the real winner here should be a mixture of low-level matplotlib code to draw the bars themselves and seaborn utilities for controlling the aesthetics of the plot. I demonstrate that here.
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
dataset = pd.read_csv("http://badhessian.org/wp-content/uploads/2014/07/visits_visitors.csv")
sns.set_style("whitegrid")
f, ax = plt.subplots(figsize=(17, 6))
ax.bar(dataset.index, dataset.Views, width=.9, color="#278DBC", align="center", label="Views")
ax.bar(dataset.index, dataset.Visitors, width=.65, color="#000099", align="center", label="Visitors")
ax.set(xlim=(-1, 30), xticks=dataset.index[5::4], xticklabels=dataset.Month[5::4].values)
ax.xaxis.grid(False)
sns.despine(left=True)
ax.legend(ncol=2, loc=1);