in ggplot for python specify global xlim in facet_wrap

1.6k views Asked by At

I'm using ggplot for python (still only version 0.4 so that may be the issue). However I wish to plot create a facet-wrapped histogram, and have each facet share the same xlim. The command I use seems to apply the xlim only to the last of the facets. (Also you can see that the labels are applied to the last of the facets only). Is there a way to specificy a global xlim? (And global labels)?

This example looks at the number of intrawiki links on Wikipedia pages that are about a country, and the facets are which Wikipedia we are inspecting, English, French, or Swahili. The data inf_df is a pandas dataframe.

inf_df = metric_df_dict['completeness']

plotinfo = ggplot(aes(x='val', colour='lang'), data=inf_df)  + geom_histogram() + labs("Score", "Frequency") \
+ facet_wrap('lang') + xlim(0,1500)


print plotinfo

I would show my output inline here but I don't have 10 reputation yet, but here's the output png

enter image description here

1

There are 1 answers

0
Jan Katins On
p = ggplot(aes(x="price"), data=diamonds) + geom_histogram()
p + facet_wrap("cut", scales="free_y")
print(p)

I suspect that setting a different limit than the one which is automatically computed is currently not possible, as the limit is only applied to the last plot (Bug: https://github.com/yhat/ggplot/issues/147)