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) In the code above, how can
Solution 1:
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()
Post a Comment for "Changing Alpha Of A Line In Seaborn Factorplot"