2
votes

I'm using seaborn to create a factorplot. Some entries in my data are missing, so it is hard to understand which bar belongs to which group.

In this example, the factorplot analyzes the answers in a survey. People are grouped by the answer they gave to a first question. Then for each of these groups, the distribution for a second question is plotted.

Sometimes the data is rather sparse. That means some bars are missing, and the boundaries between the groups are unclear. Can you tell wether the black bar in the middle belongs to group 2 or 3 ?

enter image description here

I would like to add separators between the groups. A vertical line for example would be nice. In the pandas docs, I can't find anything like this. Is there a way to add a visual separation between the factorplot groups ?

1
Yes, an axvline at positions [1.5,2.5, ...].ImportanceOfBeingErnest
@ImportanceOfBeingErnest, perfect. thanks. If you convert this to an answer, I'll accept itlhk

1 Answers

2
votes

You may use an axvline to create a vertical line spanning over the complete height of the axes. You would position that line in between the categories, i.e. at positions [1.5, 2.5, ...] in terms of axes labels. In case your plot is categorical, those would rather be [0.5, 1.5, ...]

E.g.

ax = df.plot(...)
for i in range(len(categories)-1):
    ax.axvline(i+0.5, color="grey")