Finally my first question on stackoverflow after years of finding help in questions which others have asked before me. But this time I found nothing regarding this question, neither here nor in the documentation.
I've a seaborn jointplot very similar to the figure I've attached (from the seaborn gallery). However, I wonder if it is possible to add e.g. a colored line to each of the marginal plots to mark the mean and a range marking for the interval of one standard deviation around it. I like the overall design of the seaplot figures but I kinda need that extra piece of information.
Thanks for your answers in advance!
CodePudding user response:
by matplotlib.pyplot.errorbar you can plot the interval around the line see the documentation
CodePudding user response:
To add a colored line to each of the marginal plots to mark the mean and a range marking for the interval of one standard deviation around it, you can use the seaborn.FacetGrid method
.
## First, let's generate some dummy data:
import numpy as np
x = np.random.randn(100)
y = np.random.randn(100)
#nNow, let's create the jointplot using seaborn:
import seaborn as sns
g = sns.jointplot(x=x, y=y)
# Now, we can use the FacetGrid method to add the colored line to each of the marginal plots to mark the mean and a range marking for the interval of one standard deviation around it:
g = sns.FacetGrid(data=g.data, hue='mean', palette='coolwarm', size=6)
g.map(sns.distplot, 'x', kde=False, bins=20)
g.map(sns.distplot, 'y', kde=False, bins=20)
# Finally, we can add the colored line to each of the marginal plots to mark the mean and a range marking for the interval of one standard deviation around it
g.map(plt.axhline, y=0, lw=2, c='black')
g.map(plt.axvline, x=0, lw=2, c='black')
# Finally, we can use the set() method to set the title of the plot:
g.set(title='Joint Plot with Mean and Standard Deviation Lines')
# Now, we can display the plot:
plt.show()