有没有办法在 python/seaborn 中旋转图例框

发布于 2025-01-10 00:21:02 字数 1051 浏览 3 评论 0原文

我根据深度剖面(我是地质学家)和 y 轴位置上的深度来计算速度。所以我遇到的第一个问题是,对于一个“x”(此处的速度),我可能有多个“y”(深度)。因此,我切换轮廓(y 轴的速度和 x 轴的深度)并旋转其他所有内容(标签、刻度线..),请参见下图,当我完毕。除了图例框之外,我尝试了很多东西但没有成功。我不知道如何旋转它。 您知道如何做吗?

这是我的绘图代码示例 d = 带有 ["z", "Domains", "x", "vel"] 的数据框

ax=plt.subplots(figsize=(10,5))
sns.lineplot(data=d, y='vel', x='z', hue="Domains", units='x', estimator=None, lw=1)
plt.ylabel("Velocity (km/s)", labelpad=8.0)
plt.xlabel("Depth below seafloor (km)", rotation=180)
plt.xlim(0,16)
plt.ylim(1,9)
plt.tick_params(direction='out', length=5, width=1, colors='k', labelbottom=True, labeltop=False, labelleft=False, labelright=True, right=True, left=False, grid_color='k', rotation=90)
plt.grid(alpha=0.3, color='k', ls=':')
plt.savefig(Fig_path + 'Comp_domains_tomo2d_ligne.png')
plt.savefig(Fig_path + 'Comp_domains_tomo2d_ligne.ps')
plt.show()

1

如果我不这样做不要切换轴,z 不会不断增加,因为我可以进行速度反转(参见第二张图)。

在此处输入图像描述

抱歉,我无法添加部分数据...

I'm making velocity according to depth profiles (i'm a geologist) with the depth on the y-axis position. So the first problem I encounter was that for one 'x' (velocity here) I have multiple 'y' (depth) possible. Thus I switch the profile (vel in y-axis and depth in x-axis) and I rotated everything else (labels, ticks..), see picture below and I would just need to rotate of 90° the picture when I'm done. Except the legend box, I've tried many thing without success. I don't know how to rotate it.
Do you have an idea on how to do it ?

Here an example of my code for plot with
d = a dataframe with ["z", "Domains", "x", "vel"]

ax=plt.subplots(figsize=(10,5))
sns.lineplot(data=d, y='vel', x='z', hue="Domains", units='x', estimator=None, lw=1)
plt.ylabel("Velocity (km/s)", labelpad=8.0)
plt.xlabel("Depth below seafloor (km)", rotation=180)
plt.xlim(0,16)
plt.ylim(1,9)
plt.tick_params(direction='out', length=5, width=1, colors='k', labelbottom=True, labeltop=False, labelleft=False, labelright=True, right=True, left=False, grid_color='k', rotation=90)
plt.grid(alpha=0.3, color='k', ls=':')
plt.savefig(Fig_path + 'Comp_domains_tomo2d_ligne.png')
plt.savefig(Fig_path + 'Comp_domains_tomo2d_ligne.ps')
plt.show()

1

If I don't switch the axis, the z is not constantly increasing as I can have velocity inversion (see the 2nd picture).

enter image description here

Sorry I can't add portion of my data...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文