简体   繁体   中英

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. I'm aware, that twinx() almost does the trick like so:

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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