Vivek
Vivek

Reputation: 569

Using different axis scales in seaborn replot

I used this example from the Seaborn documentation to produce the figure below.

import seaborn as sns
tips = sns.load_dataset("tips")
g = sns.relplot(x="total_bill", y="tip", hue="day", col="time", data=tips)

enter image description here

How can I force either the x- or y-axis to use different scales (for example have x range from (0, 100) in the right subplot)?

I tried passing sharex=False to the replot function, but that is not a valid keyword.

Upvotes: 6

Views: 5859

Answers (1)

Diziet Asahi
Diziet Asahi

Reputation: 40707

You need to use facet_kws= to pass the argument to the FacetGrid object. You can then change the limits by referencing each Axes using g.axes which is a 2D array of Axes objects.

import seaborn as sns
tips = sns.load_dataset("tips")
g = sns.relplot(x="total_bill", y="tip", hue="day", col="time", data=tips, facet_kws=dict(sharex=False))
g.axes[0,0].set_xlim(0,100)
g.axes[0,1].set_xlim(20,30)

enter image description here

Upvotes: 13

Related Questions