6

In a Seaborn FacetGrid, how can I get the y-axis tick labels to show up in all the subplots, regardless of whether or not sharey=True?

tips = sns.load_dataset("tips")
g = sns.FacetGrid(tips, col="time",  row="sex")
g.map(sns.scatterplot, "total_bill", "tip")

enter image description here

The following attempt returns the error AttributeError: 'FacetGrid' object has no attribute 'flatten'

for axis in g.flatten():
    for tick in axis.get_yticklabels():
        tick.set_visible(True)
a11
  • 3,122
  • 4
  • 27
  • 66

2 Answers2

4
for axis in g.axes.flat:
    axis.tick_params(labelleft=True)

This here worked for me.

Jim
  • 1,579
  • 1
  • 11
  • 18
  • 1
    It's essentially the same question as: https://stackoverflow.com/questions/52182322/repeating-x-axis-labels-for-all-facets-using-facetgrid-in-seaborn – Jim May 04 '21 at 19:43
  • After searching for 1 hour...this answer finally worked. Thank you. – igorkf May 23 '23 at 16:35
0
for axis in axes.flatten():
    for tick in axis.get_yticklabels():
        tick.set_visible(True)

Try looping through each axis of each plot and manually forcing the tick labels to be visible.

AlanSTACK
  • 5,525
  • 3
  • 40
  • 99