更改seaborn因子图中的线的alpha [英] Changing alpha of a line in seaborn factorplot
本文介绍了更改seaborn因子图中的线的alpha的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
import seaborn as sns
sns.set(style="ticks")
exercise = sns.load_dataset("exercise")
g = sns.factorplot(x="time", y="pulse", hue="kind", data=exercise)
在上面的代码中,如何将 rest
行更改为 0.5 的 alpha?
In the code above, how can I change the rest
line to an alpha of 0.5?
推荐答案
使用 get_children()
方法找到 FacetGrid
轴的合适对象,并为线条和标记设置 alpha.要更改图例( g._legend
对象)中的标记属性,请找到 legendHandles
的合适元素,然后应用 set_alpha()
方法:
Find proper objects of FacetGrid
axes with get_children()
method and set alpha for lines and markers. To change marker property in legend (g._legend
object) find suitable element of legendHandles
and apply set_alpha()
method:
import seaborn as sns
import matplotlib.pylab as plt
sns.set(style="ticks")
exercise = sns.load_dataset("exercise")
g = sns.factorplot(x="time", y="pulse", hue="kind", data=exercise)
# set alpha for marker (index 0) and for the rest line (indeces 3-6)
plt.setp([g.ax.get_children()[0],g.ax.get_children()[3:7]],alpha=.5)
# modify marker in legend box
g._legend.legendHandles[0].set_alpha(.5)
plt.show()
这篇关于更改seaborn因子图中的线的alpha的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文