Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Seaborn Facetgrid change xlabels

I just can't figure out how to change the xlabels in a Seaborn Facetgrid. It offers a method for changing the x labels with set_xlabels() but unfortunately not individually for each subplot.

I have two subplots which share the y-axis but have a different x-axes and i want to label them with different texts.

Can anybody give me a hint. Thank you in advance.

like image 560
J-H Avatar asked Apr 12 '16 12:04

J-H


1 Answers

You can access the individual axes of the FacetGrid using the axes property, and then use set_xlabel() on each of them. For example:

import seaborn as sns
import matplotlib.pyplot as plt

sns.set(style="ticks", color_codes=True)

tips = sns.load_dataset("tips")

g = sns.FacetGrid(tips, col="time",  hue="smoker")
g = g.map(plt.scatter, "total_bill", "tip", edgecolor="w")

g.axes[0,0].set_xlabel('axes label 1')
g.axes[0,1].set_xlabel('axes label 2')

plt.show()

enter image description here

Note in this example, g.axes has a shape of (1,2) (one row, two columns).

like image 151
tmdavison Avatar answered Oct 20 '22 11:10

tmdavison