更改 seaborn factorplot 中一条线的 alpha
Changing alpha of a line in seaborn factorplot
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?
使用 get_children()
方法找到 FacetGrid
轴的合适对象,并为线和标记设置 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()
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?
使用 get_children()
方法找到 FacetGrid
轴的合适对象,并为线和标记设置 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()