如何翻转seaborn tsplot图上的轴? [英] How to flip axes on seaborn tsplot plot?

查看:141
本文介绍了如何翻转seaborn tsplot图上的轴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拥有具有各种测量值的数据以及与这些测量值相关的深度.我能够使用阴影误差范围作为y轴和深度作为x轴来绘制数据.但是,我希望带有误差范围的数据在x轴上,深度在y上.有没有办法告诉tsplot将data参数用作x轴,将深度参数用作y或翻转轴?基本上我想把它转过来

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. However, I want the data with the error bounds to be on the x axis and depth on the y. Is there a way to tell tsplot to use the data parameter as the x axis and depth as the y or to flip the axes? Basically I want to turn this

进入此

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

with all the proper axes formatting as it would if you simply transposed an array in matplotlib.

推荐答案

tsplot期望水平轴上有时间.因此,转置它不是直接的.但是,我们可以从水平图中获取相应的数据,并使用它从同一数据中生成垂直图.

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.

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

这篇关于如何翻转seaborn tsplot图上的轴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆