Skip to content

Instantly share code, notes, and snippets.

@alisatl
Created June 4, 2020 00:04
Show Gist options
  • Save alisatl/d47e8b31d1d42f6b7a7758ec7d56d65a to your computer and use it in GitHub Desktop.
Save alisatl/d47e8b31d1d42f6b7a7758ec7d56d65a to your computer and use it in GitHub Desktop.
Pandas Pie Plots
import pandas as pd
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
ordered_groups = merch_group_metrics_pdf_retail.index
query_metrics_pdf_retail['query_group'] = pd.Categorical(query_metrics_pdf_retail['query_group'], categories=ordered_groups, ordered=True)
query_metrics_pdf_retail.dtypes
fig, ax = plt.subplots(1, 2, figsize=(18, 10))
pie_wedge_collection0 = ax[0].pie(merch_group_metrics_pdf_retail['lownull_count'],
labels=merch_group_metrics_pdf_retail.index, autopct='%1.1f%%')#, startangle=90)#, textprops={'size':10})
ax[0].axis('equal')
ax[0].set_title('Merch Groups by NLR SEARCHES')
colordict = {}
for pie_wedge in pie_wedge_collection0[0]:
colordict[pie_wedge.get_label()] = pie_wedge.get_facecolor()
pie_wedge_collection1 = ax[1].pie(query_metrics_pdf_retail['query_group'].value_counts().sort_index(),
#labels=query_metrics_pdf_retail['query_group'].value_counts().index,
labels=merch_group_metrics_pdf_retail.index,
autopct='%1.1f%%')#, startangle=90)#, textprops={'size':10})
for pie_wedge in pie_wedge_collection1[0]:
pie_wedge.set_facecolor(colordict[pie_wedge.get_label()])
ax[1].axis('equal')
ax[1].set_title('Merch Groups by unique NLR QUERIES')
fig.suptitle('NLR searches and unique queries by Merch Groups', fontsize=16)
#fig.tight_layout(pad=8.0)
#fig.tight_layout()
plt.subplots_adjust(wspace=.4)
plt.show()
fig.savefig('./figures/NLR_by_merch_groups_pie.png', dpi=300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment