Issue
FacetGrid
from seaborn
creates a grid of subpots allowing you to explore conditional relationships in your dataset.
Two of the keyword arguments the function accepts are sharex
and sharey
, which according to the docs:
share{x,y} : bool, optional
If true, the facets will share y axes across columns and/or x axes across rows.
But I don't see any other way to control the way facets/subplots share axes. And so here comes the...
Question:
Is there any way to share the x axis across columns and/or the y axes across rows?
I'm trying to obtain density plots of different quantities (in rows) for different conditions (in columns and hue). Thus, I would my subplots to share both the x and y axis across rows, but no linkage across columns.
Solution
It's not properly documented, but those parameters are passed straight to plt.subplots
, which allows you to set the values for those parameters to "row"
or "col"
so that axes are only shared within rows or columns, and not across the whole grid.
I'm not sure I understand exactly how you want your plot to look, but I think you can do something like:
tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col="smoker", row="time", sharey="col")
g.map(plt.hist, "total_bill")
That said, in general I would try to share axes across the grid (i.e., structure the plot to share y axes across the rows, not across the columns) to ease visual comparisons.
Answered By - mwaskom
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.