Repeating x axis labels for all facets using FacetGrid in seaborn
Asked Answered
E

3

20

I am working with the FacetGrid example presented here that results in the plot below. In my data set, there is quite a lot of plots, and it would be convenient to have the x axis labels repeated for each facet, not only at the bottom.

For this example, the values 62, ..., 76 should be repeated for each of the A-J facets.

enter image description here

Eucaine answered 5/9, 2018 at 9:58 Comment(0)
F
24

The answer by Bazingaa works for matplotlib version 2.0.2. For newer versions of matplotlib, using ax.tick_params() and setting labelbottom=True seems to work:

for ax in g.axes.flatten():
    ax.tick_params(labelbottom=True)
Felicity answered 5/9, 2018 at 11:59 Comment(0)
T
5

Just add the following lines after your def label(): function. Although the plot doesn't look that good with the modification you want.

for ax in g.axes.flat:
    _ = plt.setp(ax.get_xticklabels(), visible=True)

Output

enter image description here

Troubadour answered 5/9, 2018 at 10:14 Comment(5)
What doesn't work for you? Could you provide the error you encounter? I just used the example link you gave and added the above linesTroubadour
I do not get an error, but the labels are not showed. I am using seaborn 0.9.0Symposium
I am using 0.9.0 too and matplotlib version is 2.0.2Troubadour
This is a matplotlib issue I think. Your solution works for matplotlib 2.0.2, but does not for 2.2.3Felicity
Yes, I think so too. I will try it with a higher version and update my answerTroubadour
D
0

The simplest way is to operate on the FacetGrid directly, rather than looping through the axes.

g.tick_params(axis='x', labelbottom=True)

Adding this line produces the expected output:

enter image description here

Dehumanize answered 4/7, 2024 at 11:57 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.