Skip to content Skip to sidebar Skip to footer

Seaborn Facetgrid Pointplot Add 1 Grid Line

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

Solution 1:

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.

Post a Comment for "Seaborn Facetgrid Pointplot Add 1 Grid Line"