Python Pandas Stacked Bar Chart x-axis labels -


i've got below dataframe:

months  region  open case id    closed case id april   apac    648888          648888 april        157790   april   uk      221456          221456 april   apac    425700   april        634156          634156 april   uk      109445   april   apac    442459          442459 may          218526   may     uk      317079          317079 may     apac    458098   may          726342          726342 may     uk      354155   may     apac    463582          463582 may          511059   june    uk      97186           97186 june    apac    681548   june         799169          799169 june    uk      210129   june    apac    935887          935887 june         518106   june    uk      69279           69279 

and getting counts of open case id , closed case id with:

df = df.groupby(['months','region']).count() 

i trying replicate below chart generated excel, looks this:

and getting below with:

df[['months','region']].plot.bar(stacked=true, rot=0, alpha=0.5, legend=false) 

enter image description here

is there way chart generated python closer chart generated excel in terms of how x-axis , labels broken down?

theres great solution similar question design multi index labels here. can use same parameters of plot ax=fig.gca() in solution i.e

import matplotlib.pyplot plt  # add_line,label_len,label_group_bar_table https://stackoverflow.com/a/39502106/4800652  fig = plt.figure() ax = fig.add_subplot(111) #your df.plot code ax parameter here df.plot.bar(stacked=true, rot=0, alpha=0.5, legend=false, ax=fig.gca())  labels = ['' item in ax.get_xticklabels()] ax.set_xticklabels(labels) ax.set_xlabel('') label_group_bar_table(ax, df) fig.subplots_adjust(bottom=.1*df.index.nlevels) plt.show() 

output based on sample data:

enter image description here


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -