2017-03-09 330 views
0

我有與這些測量相關的各種測量和深度的數據。我可以繪製陰影誤差範圍爲y軸,深度爲x軸的數據。但是,我希望誤差範圍的數據位於x軸上,深度位於y上。有沒有辦法告訴tsplot使用數據參數作爲x軸和深度作爲y或翻轉軸?基本上,我想要把這個如何翻轉seaborn tsplot圖上的座標軸?

enter image description here

這個

enter image description here

與所有適當的軸格式,因爲它會如果你只是調換在matplotlib的數組。

+0

是的,對不起,'tsplot'需要「時間」維度的那張X軸(這將是大多數人在看你的情節會希望)。 – mwaskom

回答

1

tsplot預計時間在水平軸上。因此,轉移它並不是直接的。但是,我們可以從水平圖中獲取相應的數據,並使用它從相同的數據生成垂直圖。

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()