Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set axis limits on individual facets of seaborn facetgrid

Tags:

I'm trying to set the x-axis limits to different values for each facet a Seaborn facetgrid distplot. I understand that I can get access to all the axes within the subplots through g.axes, so I've tried to iterate over them and set the xlim with:

g = sns.FacetGrid(     mapping,     col=options.facetCol,     row=options.facetRow,     col_order=sorted(cols),     hue=options.group, ) g = g.map(sns.distplot, options.axis)  for i, ax in enumerate(g.axes.flat):  # set every-other axis for testing purposes     if i % 2 == 0[enter link description here][1]:         ax.set_xlim(-400, 500)     else:         ax.set_xlim(-200, 200) 

However, when I do this, all axes get set to (-200, 200) not just every other facet.

What am I doing wrong?

like image 253
Constantino Avatar asked Jul 01 '15 19:07

Constantino


People also ask

What is facet grid in Seaborn?

The methods we are going to use are will plot on Seaborn's FaceGrid. A FacetGrid is a multi-axes grid with subplots visualizing the distribution of variables of a dataset and the relationship between multiple variables.

Which plots can be plotted using faceted grids?

The plots it produces are often called “lattice”, “trellis”, or “small-multiple” graphics. It can also represent levels of a third variable with the hue parameter, which plots different subsets of data in different colors.

What is FacetGrid and what is its use in visualization?

FacetGrid() : FacetGrid class helps in visualizing distribution of one variable as well as the relationship between multiple variables separately within subsets of your dataset using multiple panels. A FacetGrid can be drawn with up to three dimensions ? row, col, and hue.


1 Answers

mwaskom had the solution; posting here for completeness - just had to change the following line to:

g = sns.FacetGrid(     mapping,     col=options.facetCol,     row=options.facetRow,     col_order=sorted(cols),     hue=options.group,     sharex=False,  # <- This option solved the problem! ) 
like image 106
Constantino Avatar answered Sep 27 '22 19:09

Constantino