matplotlib:使用append_axes时,如何指示我想要添加子面板的轴?

发布于 2024-12-14 03:29:50 字数 942 浏览 0 评论 0原文

我一直在 Matplotlib 库中查看示例 "scatter hist"

目前,x/y 子图分别位于顶部和右侧,即:

divider = make_axes_locatable(axScatter)
axHistx = divider.append_axes("top", 1.2, pad=0.1, sharex=axScatter)
axHisty = divider.append_axes("right", 1.2, pad=0.1, sharey=axScatter)

但是,如果我将子图位置更改为:

divider = make_axes_locatable(axScatter)
axHistx = divider.append_axes("bottom", 1.2, pad=0.1, sharex=axScatter)
axHisty = divider.append_axes("right", 1.2, pad=0.1, sharey=axScatter)

即将 x 子面板移动到底部,则append_axes 将 y 子图添加到右侧x 子图,而不是散点图的右侧。 (我会上传图像,但我还没有足够高的声誉来发布图像...... grrr)!

我如何告诉append_axes我想将y子图附加到包含散点图的“主轴”的右侧?我猜测我需要在某处再次指定对象 axScatter (尽管我认为这就是 divider = make_axes_locatable(axScatter) 的用途?!)或者我猜测divider已经设置了一个窗口面板中的网格,我需要告诉append_axes哪个单元格包含主轴。

谢谢,

亚历克斯

I've been looking at the example "scatter hist" in the Matplotlib gallery.

At the moment the x/y subplots are at the top and on the right respectively, i.e.:

divider = make_axes_locatable(axScatter)
axHistx = divider.append_axes("top", 1.2, pad=0.1, sharex=axScatter)
axHisty = divider.append_axes("right", 1.2, pad=0.1, sharey=axScatter)

However, if I change the subplot locations to:

divider = make_axes_locatable(axScatter)
axHistx = divider.append_axes("bottom", 1.2, pad=0.1, sharex=axScatter)
axHisty = divider.append_axes("right", 1.2, pad=0.1, sharey=axScatter)

i.e. move the x subpanel to the bottom, then append_axes adds the y subplot to the right of the x subplot, rather than the right of the scatter plot. (I'd upload the image but I don't have a high enough reputation yet to post images... grrr)!

How can I tell append_axes that I want to append the y subplot to the right of the "main axes" containing the scatter plot? I'm guessing that I need to either specify the object axScatter again somewhere (though I thought that's what divider = make_axes_locatable(axScatter) was for?!) or I'm guessing that divider has set up a grid in the window panel and I need to tell append_axes which cell contains the main axes.

Thanks,

Alex

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温馨耳语 2024-12-21 03:29:50

创建 axHistyaxHistx 的顺序似乎很重要。如果你交换最后两个语句的顺序,那么你可以获得所需的效果:

divider = make_axes_locatable(axScatter)
axHisty = divider.append_axes("right", 1.2, pad=0.1,  sharey=axScatter)
axHistx = divider.append_axes("bottom", 1.2, pad=0.1, sharex=axScatter)

这确实像一个错误一样臭。

The order in which you create axHisty and axHistx appears to matter. If you switch the order of the last two statements then you can get the desired effect:

divider = make_axes_locatable(axScatter)
axHisty = divider.append_axes("right", 1.2, pad=0.1,  sharey=axScatter)
axHistx = divider.append_axes("bottom", 1.2, pad=0.1, sharex=axScatter)

This sure stinks like a bug.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文