3

Given the following:

import seaborn as sns
attend = sns.load_dataset("attention")
sns.set_style("whitegrid", {'axes.grid' : False,'axes.edgecolor':'none'})
g = sns.FacetGrid(attend, col="subject", col_wrap=5,
size=1.5, ylim=(0, 10))
ax = g.map(sns.pointplot, "solutions", "score", scale=.7)

As you can see, I have removed all grid lines. I would now like to add just one horizontal grid line: at the value of 5 on the y-axis for each plot. Is this possible to do? I looked into the set_style dictionary options here but found nothing helpful.

Thanks in advance!

Community
  • 1
  • 1
Dance Party2
  • 7,214
  • 17
  • 59
  • 106

1 Answers1

4

The easiest way to get a grid line as an aide to the eye in the plot is to just draw a line onto every plot.

for a in g.axes:
    a.axhline(5, alpha=0.5, color='grey')

The upshot is that it's basically one line of code and the plot will have the feature you want. The downshot is that you have to manually specify where each line goes. (I assume that you want something a little more complicated in the production code). Something a little better would be

for a in g.axes:
    a.axhline(a.get_yticks()[1], alpha=0.5, color='grey')

which would grab a single tick and draw a line for it.

You could probably do something with the individual tick objects to give a similar effect---they can be accessed with a.yaxis.get_major_ticks()---but I wasn't able to use any of their methods to any effect.

Elliot
  • 2,541
  • 17
  • 27
  • Thanks, @Elliot I ended up using this in my actual code (for future reference, adapted from your solution): for i in ax.axes: i[0].axhline(50, alpha=0.25, color='grey') for i[0] through i[3] – Dance Party2 Aug 23 '17 at 20:38
  • 1
    Related question here: https://stackoverflow.com/questions/45849028/seaborn-facetgrid-pointplot-label-data-points – Dance Party2 Aug 23 '17 at 20:49