pythonmatplotlibseabornpointplot

reduce line width of seaborn pointplot


import seaborn as sns
sns.set(style="ticks")
exercise = sns.load_dataset("exercise")
g = sns.factorplot(x="time", y="pulse", hue="kind", data=exercise)

In the plot above, if I specify scale as 0.5, it reduces line width but not width of confidence interval lines. Is there a way to reduce width of confidence interval lines?


Solution

  • You may get linewidth of first line and set it for all other lines of factor plot:

    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, scale=.5)
    lw = g.ax.lines[0].get_linewidth() # lw of first line
    plt.setp(g.ax.lines,linewidth=lw)  # set lw for all lines of g axes
    
    plt.show()
    

    enter image description here

    And you can set line width for every line in a cycle:

    for l in g.ax.lines:
        print(l.get_linewidth())
        plt.setp(l,linewidth=5)
    

    Output:

    1.575
    3.15
    3.15
    3.15
    1.575
    3.15
    3.15
    3.15
    1.575
    3.15
    3.15
    3.15
    

    Bold lines are according to confidential intervals.

    After set line width to 5 all lines became the same:

    enter image description here