python - seaborn barplot() output figure is overwritten -


i using following lines of code plot couple of seaborn bar graphs in jupyter notebooks

sns.set(style="darkgrid") rcparams['figure.figsize'] = (12, 8) bar_plot = sns.barplot(x='country',y='average rate',data=pddf1, palette="muted", x_order=pddf1["country"].tolist()) abc = bar_plot.set_xticklabels(pddf1["country"],rotation=90)  sns.set(style="darkgrid") rcparams['figure.figsize'] = (12, 4) bar_plot = sns.barplot(x='country',y='% jobs completed',data=pddf2,     palette="muted", x_order=pddf2["country"].tolist()) abc = bar_plot.set_xticklabels(pddf2["country"],rotation=90) 

where pddf variables panda dataframes constructed lists.

if comment out 1 set of statements, other graph plotted correctly. however, if both of them run together, both graphs drawn @ same axes. in other words, first 1 overwritten second one. sure because see longer bars first graph shown in final figure.

any idea, how can draw them 1 after other? doing wrong?

since seaborn developed on top of matplotlib, searched well. in matplotlib, draw changing figure numbers. not sure if can achieved using rcparams in seaborn.

have tried subplots?

sns.set(style="darkgrid")   # need call once  fig, (ax1,ax2) = plt.subplots(1,2, figsize=(12,8))  # plots on same row sns.barplot(x='country',y='average rate',data=pddf1, palette="muted", x_order=pddf1["country"].tolist(), ax=ax1) ax1.set_xticklabels(pddf1["country"],rotation=90)  sns.barplot(x='country',y='% jobs completed',data=pddf2,     palette="muted", x_order=pddf2["country"].tolist(), ax=ax2) abc = bar_plot.set_xticklabels(pddf2["country"],rotation=90) 

this yields 2 figures same size; there other options gridspec allow more customization of positions , sizes.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -