Changing the alpha line in the marine factor

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 above code, how can I change the string rest

to alpha 0.5 ±

+3


source to share


1 answer


Find suitable axis objects FacetGrid

using the method get_children()

and set alpha for lines and markers. To change the marker property in the legend (object g._legend

), find the appropriate element legendHandles

and apply the method 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()

      



enter image description here

+3


source







All Articles