【问题标题】:Changing alpha of a line in seaborn factorplot改变seaborn factorplot中一条线的alpha
【发布时间】:2018-01-15 07:49:13
【问题描述】:
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?

【问题讨论】:

    标签: python pandas matplotlib seaborn


    【解决方案1】:

    使用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()
    

    【讨论】:

      猜你喜欢
      • 2018-08-05
      • 1970-01-01
      • 2017-01-02
      • 2014-10-05
      • 1970-01-01
      • 2016-11-17
      • 1970-01-01
      • 2014-11-27
      相关资源
      最近更新 更多