# Today's goal is to reproduce this (without the headlines, I'll leave that for later): from IPython.core.display import HTML HTML('') # Ready, set, go! # imports, from the docs: "The pyplot interface is generally preferred for # non-interactive plotting (i.e., scripting). The pylab interface is convenient # for interactive calculations and plotting" import matplotlib.pyplot as plt %matplotlib inline # Seems that need some space fig = plt.figure(figsize=(5.21, 2.6), dpi=120) # got the (in x in)dpi equivalent of 500px x 300px # The image is divided in two and the first part is roughly 1/6 of the image. # To understand the subplots I went to http://matplotlib.org/users/gridspec.html bars = plt.subplot2grid((1,3), (0,0), colspan=1) plot = plt.subplot2grid((1,3), (0,1), colspan=2, axisbelow=True) # This has the underlying structure # Cleaning and removing lines and ticks bars.set_yticks([]) bars.set_xlabel("Average") bars.set_xticks([]) bars.axes.set_ylim((0, 100)) bars.spines['top'].set_visible(False) bars.spines['left'].set_visible(False) bars.spines['right'].set_visible(False) plot.set_xticklabels(["Apr 2012", "Jul 2012", "Oct 2012"]) plot.set_xticks([4*4, 4*7, 4*10]) # setting the months where they begin (in weeks) plot.set_yticklabels([]) plot.set_ylim((0, 120)) plot.spines['top'].set_visible(False) plot.spines['left'].set_visible(False) plot.spines['right'].set_visible(False) # I don't know yet how many point I will have, so I will set the xticks later. # and the same for the bars in the other subplot. import pandas as pd report = pd.read_csv('0_data.csv', na_values=' ') # na_values tells pandas, in the data, what is a null value. # Now using the attributes 'cat', 'dog' and 'fish' I can access each column of the CSV file report.fish.tolist() # plot each column with their color. plot.plot(report.cat.tolist(), color='blue', label='cat') plot.plot(report.dog.tolist(), color='red', label='dog') plot.plot(report.fish.tolist(), color='orange', label='fish') # and the same for the bars in the other subplot. bars.axes.set_xlim((0, 5)) bars.bar(1, report.cat.mean(), color='blue', edgecolor='none', width=0.9, label='cat') bars.bar(2, report.dog.mean(), color='red', edgecolor='none', width=0.92, label='dog') bars.bar(3, report.fish.mean(), color='orange', edgecolor='none', width=0.92, label='fish') # The legend plot.legend(frameon=False, loc=2, fontsize='xx-small', ncol=3, mode='none') # Almost there... # A few adjustments to fonts and colors plot.xaxis.set_ticks_position('none') plot.yaxis.set_ticks_position('none') for tk in plot.axes.get_xmajorticklabels(): plt.setp(tk, color='gray', fontsize='xx-small') plt.setp(bars.xaxis.label, color='gray', fontsize='xx-small') plot.grid(which='major', axis='y', linewidth=.8, linestyle='-', color='lightgray') plot.spines['bottom'].set_color('gray') bars.spines['bottom'].set_color('gray') plt.subplots_adjust(wspace=-0.1) # The entire code # imports, from the docs: "The pyplot interface is generally preferred for # non-interactive plotting (i.e., scripting). The pylab interface is convenient # for interactive calculations and plotting" import matplotlib.pyplot as plt # Seems that need some space fig = plt.figure(figsize=(5.21, 2.6), dpi=120) # got the (in x in)dpi equivalent of 500px x 300px # The image is divided in two and the first part is roughly 1/6 of the image. # To understand the subplots I went to http://matplotlib.org/users/gridspec.html bars = plt.subplot2grid((1,3), (0,0), colspan=1) plot = plt.subplot2grid((1,3), (0,1), colspan=2, axisbelow=True) # This has the underlying structure # Cleaning and removing lines and ticks bars.set_yticks([]) bars.set_xlabel("Average") bars.set_xticks([]) bars.axes.set_ylim((0, 100)) bars.spines['top'].set_visible(False) bars.spines['left'].set_visible(False) bars.spines['right'].set_visible(False) plot.set_xticklabels(["Apr 2012", "Jul 2012", "Oct 2012"]) plot.set_xticks([4*4, 4*7, 4*10]) # setting the months where they begin (in weeks) plot.set_yticklabels([]) plot.set_ylim((0, 120)) plot.spines['top'].set_visible(False) plot.spines['left'].set_visible(False) plot.spines['right'].set_visible(False) # I don't know yet how many point I will have, so I will set the xticks later. # and the same for the bars in the other subplot. import pandas as pd report = pd.read_csv('0_data.csv', na_values=' ') # plot each column with their color. plot.plot(report.cat.tolist(), color='blue', label='cat') plot.plot(report.dog.tolist(), color='red', label='dog') plot.plot(report.fish.tolist(), color='orange', label='fish') # and the same for the bars in the other subplot. bars.axes.set_xlim((0, 5)) bars.bar(1, report.cat.mean(), color='blue', edgecolor='none', width=0.9, label='cat') bars.bar(2, report.dog.mean(), color='red', edgecolor='none', width=0.92, label='dog') bars.bar(3, report.fish.mean(), color='orange', edgecolor='none', width=0.92, label='fish') # The legend plot.legend(frameon=False, loc=2, fontsize='xx-small', ncol=3, mode='none') # A few adjustments to fonts and colors plot.xaxis.set_ticks_position('none') plot.yaxis.set_ticks_position('none') for tk in plot.axes.get_xmajorticklabels(): plt.setp(tk, color='gray', fontsize='xx-small') plt.setp(bars.xaxis.label, color='gray', fontsize='xx-small') plot.grid(which='major', axis='y', linewidth=.8, linestyle='-', color='lightgray') plot.spines['bottom'].set_color('gray') bars.spines['bottom'].set_color('gray') plt.subplots_adjust(wspace=-0.1)