简体   繁体   English

matplotlib:y标注在辅助y轴上,带有手动刻度线放置

[英]matplotlib: ylabel on the secondary y-axis with manual tick placing

I want to have a y-label on the secondary y-axis in matplotlib. 我想在matplotlib的辅助y轴上有一个y标签。 I'm aware, that twinx() almost does the trick like so: 我知道, twinx()几乎可以完成以下操作:

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

However, my ax1 has a non-standard tick placing and the duplicate ax2 does not copy that property, so that I would have to explicitly adjust the ticks again. 但是,我的ax1具有非标准的刻度线放置,并且重复的ax2不会复制该属性,因此我将不得不再次显式调整刻度线。

Is there a better way to do this? 有一个更好的方法吗?

Although I haven't found, how to label both axes on a single subplot, I found a solution for an axes matrix: 尽管我还没有找到如何在单个子图上标注两个轴的方法,但是我找到了一个轴矩阵的解决方案:

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

Hope this helps other people, too. 希望这对其他人也有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM