I am doing a series of bar charts of data with two categorical variables and one numerical. What I have is below, but what I would like to do is a facet of one of the categorical variables, as facet_wrapin ggplot. I have a somewhat working example, but I get the wrong type of chart (rows, not bars), and I'm a subset of the data in the loop - this is not the best way.
import pandas as pd
import numpy as np
N = 100
ind = np.random.choice(['a','b','c'], N)
cty = np.random.choice(['x','y','z'], N)
jobs = np.random.randint(low=1,high=250,size=N)
df_city = pd.DataFrame({'industry':ind,'city':cty,'jobs':jobs})
df_city_grouped = df_city.groupby(['city','industry']).jobs.sum().unstack()
df_city_grouped.plot(kind='bar',stacked=True,figsize=(9, 6))
This gives something like this:
city industry jobs
0 z b 180
1 z c 121
2 x a 33
3 z a 121
4 z c 236

However, what I would like to see looks something like this:
library(plyr)
df_city<-read.csv('/home/aksel/Downloads/mockcity.csv',sep='\t')
df_city_grouped <- ddply(df_city, .(city,industry), summarise, jobstot = sum(jobs))
ggplot(df_city_grouped, aes(x=industry, y=jobstot)) +
geom_bar(stat='identity') +
facet_wrap(~city)

The closest I get with matplotlib, something like this:
cols =df_city.city.value_counts().shape[0]
fig, axes = plt.subplots(1, cols, figsize=(8, 8))
for x, city in enumerate(df_city.city.value_counts().index.values):
data = df_city[(df_city['city'] == city)]
data = data.groupby(['industry']).jobs.sum()
axes[x].plot(data)

So, two questions:
- Can I make line art (they plot lines as shown here) using the AxesSubplot object, and I end up with something along the lines of the example facet_wrap from the example
ggplot; - , , , . , "" ?