Skip to content

Instantly share code, notes, and snippets.

@randyzwitch
Last active August 29, 2015 14:04
Show Gist options
  • Save randyzwitch/b638d61569a7f747a6eb to your computer and use it in GitHub Desktop.
Save randyzwitch/b638d61569a7f747a6eb to your computer and use it in GitHub Desktop.
Re-creating WordPress chart
import seaborn as sns
import matplotlib.pyplot as plt
#Set theme and size, remove axis titles
sns.set_style("whitegrid")
sns.set_context({"figure.figsize": (17, 6)}) #Passing in matplotlib commands directly
#Plot data
#Use dataset.index as my x_order, to ensure proper ordering by using numeric series
sns_views = sns.barplot(dataset.Month, "Views", data = dataset, color = "#278DBC", dropna = False, ci=None, x_order=dataset.Month)
#Hack to use matplotlib directly to set bar width, since Seaborn doesn't currently allow for setting bar width
plotvisitors2= dataset.Visitors.plot(kind='bar', width = .5, color = '#000099', clip_on=False, grid=False)
plotvisitors2.yaxis.grid(color='gray', linestyle='solid')
plotvisitors2.set_axisbelow(True)
#Remove borders around graph, remove axis labels
#Needs to be called after plot generated or it doesn't work
sns.despine(left=True)
sns.axlabel("", "")
#Set custom labels for chart
sns_views.set_xticklabels(dataset.Month_, rotation=0)
#Create legend using same matplotlib code from above
sns_views.legend([views, visitors], ['Views', 'Visitors'], loc=1, ncol = 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment