Skip to content Skip to sidebar Skip to footer

How To Flip Axes On Seaborn Tsplot Plot?

I have data with various measurements and depth associated with those measurements. I am able to plot the data with the shaded error bounds as the y axis and depth as the x axis. H

Solution 1:

The tsplot expects time on the horizontal axes. It's therefore not straight forward to transpose it. However we can get the respective data from a horizontal plot and use it to generate a vertical plot from the same data.

enter image description here

import numpy as np; np.random.seed(22)
import seaborn as sns
import matplotlib.pyplot as plt

X = np.linspace(0, 15, 31)
data = np.sin(X) + np.random.rand(10, 31) + np.random.randn(10, 1)

plt.figure(figsize=(4,6))
ax = sns.tsplot(time=X, data=data)
#get the line and the shape from the tsplot
x,y =ax.lines[0].get_data()
c = ax.collections[0].get_paths()[0].vertices
# discart the tsplot
ax.clear()

# create new plot on the axes, inverting x and y
ax.fill_between(c[:,1], c[:,0], alpha=0.5)
ax.plot(y,x)

plt.show()

Post a Comment for "How To Flip Axes On Seaborn Tsplot Plot?"