Pablo Pablo - 5 months ago 32
Python Question

Color underplot of tsplot

I'd like to color the lower part of a

tsplot
in Seaborn. I have the following code:

sns.tsplot(time=time,data=data)


Is it possible to color the lower area of the plot? I tried using
barplot
, but my data is too large so it just doesn't look right. Any advice?

Answer

Try to use fill_between from matplotlib, like here:

import numpy as np; np.random.seed(22)
import seaborn as sns; sns.set(color_codes=True)
import matplotlib.pylab as plt
x = np.arange(31)
data = np.sin(x) + np.random.rand(10, 31) + np.random.randn(10, 1)
sns.tsplot(data=data)
ax = plt.gca()
ax.fill_between(x, np.sin(x), ax.get_ylim()[0], color='r')
plt.show()

enter image description here

Comments