Last active
August 29, 2015 14:04
-
-
Save randyzwitch/6067453ec0d704ac7c80 to your computer and use it in GitHub Desktop.
Re-creating WordPress chart using Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
#Read data into Python | |
dataset= pd.read_csv("visits_visitors.csv") | |
#Create every fifth month label | |
dataset["Month_"]= [value if (position+1) % 5 == 0 else "" for position, value in enumerate(dataset.Month)] | |
#Plot 1 | |
plotviews= dataset.Views.plot(kind='bar', figsize=(17, 6), width = .9, color = '#278DBC', edgecolor= 'none', grid = False, clip_on=False) | |
#Plot 2 - All options here control the result plot | |
plotvisitors= dataset.Visitors.plot(kind='bar', figsize=(17, 6), width = .65, color = '#000099', edgecolor= 'none', grid = False, clip_on=False) | |
plotvisitors.set_xticklabels(dataset.Month_, rotation=0) | |
#Remove plot borders | |
for location in ['right', 'left', 'top', 'bottom']: | |
plotvisitors.spines[location].set_visible(False) | |
#Fix grid to be horizontal lines only and behind the plots | |
plotvisitors.yaxis.grid(color='gray', linestyle='solid') | |
plotvisitors.set_axisbelow(True) | |
#Turn off x-axis ticks | |
plotvisitors.tick_params(axis='x',which='both', bottom='off', top='off', labelbottom='on') | |
plotvisitors.tick_params(axis='y',which='both', left='off', right='off', labelbottom='on') | |
#Create proxy artist to generate legend | |
views= plt.Rectangle((0,0),1,1,fc="#278DBC", edgecolor = 'none') | |
visitors= plt.Rectangle((0,0),1,1,fc='#000099', edgecolor = 'none') | |
l= plt.legend([views, visitors], ['Views', 'Visitors'], loc=1, ncol = 2) | |
l.draw_frame(False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment