2

I'm learning Pandas and need some help in improving the aesthetics of my plot.

Problem I'm trying to plot a multi-column bar chart in pandas (either using Matplotlib or through Seaborn library). Two main columns in my data are

Pages - main column giving where the user has landed

action - once the user lands on this what action does he take. Count of action taken is given in action_view column.

So, Pages column should be outer covering inside which there should be 'action' column values. Here's the data below.

Data

import pandas as pd
import numpy as np
import seaborn as sns

sample_df = pd.DataFrame({
    'pages':('home','home','home','food','food','food','electronics','electronics','electronics','payment','payment','payment'),
    'action':('view ','added','checkout','cart viewed','added','bundled','added','product list viewed','checkout','checkout','view','removed'),
    'page_view':(100,100,100,40,40,40,70,70,70,500,500,500),
    'action_view':(30000,10000,5000,300,500,800,1500,1200,1800,1200,1400,1500)          
})

#Code for plot
sns.barplot(x='pages',y='action_view',hue='action',data=sample_df)
plt.xticks(rotation=90)
plt.xlabel('pages')
plt.ylabel('action_view')
plt.legend(loc='upper left', bbox_to_anchor=(1,1))

#Below is the image that I'm getting

enter image description here

Question

  1. In the original data, I have 10 different pages and 10 different set of actions so following this approach the bar plot looks very messy. How can I better visualize this?
  2. How can I increase the width (thickness) of each individual bars? Also, is there any way to border individual bars (showing distinction b/w each boundary of action bars)?
  3. How can I enclose legend in a box?
  4. Using seaborn package I was able to generate this plot but it couldn't work through using matplotlib.
  5. Also, one page like home has a very high action count which skews the bar chart. Any thoughts on what can be done to have better visibility on other pages action.
  6. Lastly, if I want to sort my bars using _page_view_ column will I use sortvalue function?

Greatly appreciate your help and suggestions in this. Clearing these doubts will help in future learning. FYI - I'm using Ipython notebook and Python 3.0.

Sidd_Terp
  • 59
  • 2
  • 9

1 Answers1

0

3) plt.legend(loc=1, bbox_to_anchor=(1,1))

fuwiak
  • 721
  • 1
  • 8
  • 25