python - 如何使用两个重新排列的轴设置 matplotlib 的背景?

标签 python matplotlib

我的表单 (ui) 上有来自 Qt 设计器的 matplotlib 小部件 (mpl)。然后我用双轴绘制一些数据:

ui.mpl.axes.plot(x, y1))
ax2 = ui.mpl.axes.twinx()
ax2.plot(x, y2)

enter image description here

现在我希望我的左轴绘图位于右轴绘图上,所以我更改轴的 z 顺序:

ui.mpl.axes.set_zorder(ui.mpl.axes.get_zorder()+1)

更改 z-order 后,我的第二个图消失了,所以我必须添加:

ui.mpl.axes.patch.set_visible(False)

我明白了:

enter image description here

问题是如何返回白色背景?或者也许还有其他方法可以更改轴的顺序?

这没有帮助:

ax2.set_axis_bgcolor('white')

最佳答案

是的!看起来第二轴的 Canvas 在默认情况下是不可见的。这解决了它:

ax2.patch.set_visible(True)

关于python - 如何使用两个重新排列的轴设置 matplotlib 的背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26975032/

相关文章:

Python 函数正好接受 2 个参数(给定 1 个)

python - 使用 mutagen mac 与 pc 分配专辑封面

python - Matplotlib 循环中的图形没有响应

python - 如何搜索我的时间数据列表

python - 为什么 matplotlib 用这么多颜色为我的图着色?

python - 如何增加列表中每个项目/元素的值?

python - 从毫秒获取时间对象

python - 在不保存图像的情况下使用 matplotlib 时删除图像周围的白色边框

python - 哪个 cmap(颜色映射)与 matplotlib imshow() 一起使用以将 MNIST 数据集图像显示为白色背景上的黑色字符

python - 如何使用 asyncpg(pgsql) 获取 "returning id"