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?
答案 0 :(得分:3)
使用FacetGrid
方法查找get_children()
轴的正确对象,并为线条和标记设置alpha。要更改图例(g._legend
对象)中的标记属性,请找到legendHandles
的合适元素并应用set_alpha()
方法:
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()