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?
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.
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.
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.
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! )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With