【问题标题】:How to flip axes on seaborn tsplot plot?如何在 seaborn tsplot 图上翻转轴?
【发布时间】:2017-03-09 16:18:45
【问题描述】:

我有与这些测量相关的各种测量和深度的数据。我能够以阴影误差范围为 y 轴,深度为 x 轴来绘制数据。但是,我希望具有误差范围的数据位于 x 轴上,深度位于 y 轴上。有没有办法告诉 tsplot 使用数据参数作为 x 轴和深度作为 y 或翻转轴?基本上我想转这个

进入这个

使用所有正确的轴格式,就像您在 matplotlib 中简单地转置数组一样。

【问题讨论】:

  • 是的,抱歉,tsplot 要求“时间”维度位于 x 轴上(这将是大多数查看您的情节的人所期望的)。

标签: python matplotlib plot graphics seaborn


【解决方案1】:

tsplot 预计水平轴上的时间。因此,转置它并不简单。但是,我们可以从水平图中获取相应的数据,并使用它从相同的数据生成垂直图。

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

【讨论】:

    猜你喜欢
    • 2017-05-11
    • 2015-02-10
    • 2015-09-24
    • 2015-08-10
    • 1970-01-01
    • 2016-09-21
    • 2014-06-23
    • 2017-08-14
    相关资源
    最近更新 更多