Seaborn FacetGrid PointPlot 添加 1 条网格线 [英] Seaborn FacetGrid PointPlot Add 1 Grid Line

查看:60
本文介绍了Seaborn FacetGrid PointPlot 添加 1 条网格线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于以下内容:

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)

如您所见,我已删除所有网格线.我现在只想添加一条水平网格线:每个图的 y 轴值为 5.这是可能的吗?我查看了 set_style 字典选项此处,但没有发现任何帮助.

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.

提前致谢!

推荐答案

获得网格线作为绘图中的眼睛助手的最简单方法是在每个绘图上画一条线.

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.

您可能可以对单个 tick 对象做一些事情来产生类似的效果---它们可以通过 a.yaxis.get_major_ticks() 访问---但我无法使用他们的任何方法产生任何效果.

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.

这篇关于Seaborn FacetGrid PointPlot 添加 1 条网格线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆