Skip to content

Instantly share code, notes, and snippets.

@kperry2215
Created July 15, 2019 00:09
Show Gist options
  • Save kperry2215/e651d935d8d382da519210e6488084c8 to your computer and use it in GitHub Desktop.
Save kperry2215/e651d935d8d382da519210e6488084c8 to your computer and use it in GitHub Desktop.
def generate_bar_graph(df, title):
"""
This function creates a bar graph from pandas dataframe columns.
Arguments:
df: Pandas dataframe. Index will be x-axis. Categories and
associated amounts are from columns
title: String. Name of the bar graph
Outputs:
Bar graph in console.
"""
df.plot.bar(rot=0)
plt.title(title, color='black')
plt.legend(loc='center left', bbox_to_anchor=(1.0, 0.5))
plt.show()
...
#Execution in main script
generate_bar_graph(vendor_data_stacked_bar_graph_pivoted,
title='Number of Times Vendor Was Purchased From Over Quarter')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment