python - matplotlib:辅助 y 轴上的 ylabel 带有手动刻度放置

标签 python matplotlib

我想在 matplotlib 的辅助 y 轴上有一个 y 标签。我知道, twinx() 几乎可以实现这样的效果:

ax2 = twinx(ax1)
ax2.set_ylabel('some thing')

但是,我的 ax1 具有非标准刻度放置,并且重复的 ax2 不会复制该属性,因此我必须再次显式调整刻度。

有更好的方法吗?

最佳答案

虽然我还没有找到如何在单个子图上标记两个轴,但我找到了轴矩阵的解决方案:

fig, axs = subplots(2, 2, sharex=True, sharey=True)
axs[0, 0].set_ylabel('on the left by default')
axs[0, 1].yaxis.set_label_position('right')
axs[0, 1].set_ylabel('...now on the right y-axis')

希望这对其他人也有帮助。

关于python - matplotlib:辅助 y 轴上的 ylabel 带有手动刻度放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31451619/

相关文章:

python - Python 中的 {!text!} 是什么?

python - 子图是重叠的轴标签

python - 从python中的txt文件中绘制选定的值

python - 导入seaborn包时matplotlib.pyplot.scatter()失去颜色?

python - 类型错误 : can't pickle NotImplementedType objects (in keras, python )

python - 根据索引和列将填充的 DataFrame 合并到掩码中

python - Mathml 到 python 中的数学符号

python - 如何从图像中找到各种颜色而不给出颜色范围

python - 值错误 : x and y must have same first dimension

python - 将地 block 外的点设置为上限