Second y-axis label getting cut off

前端 未结 2 698
再見小時候
再見小時候 2021-01-30 21:13

I\'m trying to plot two sets of data in a bar graph with matplotlib, so I\'m using two axes with the twinx() method. However, the second y-axis label gets cut off.

相关标签:
2条回答
  • 2021-01-30 21:26

    I just figured it out: the trick is to use bbox_inches='tight' in savefig.

    E.G. plt.savefig("test.png",bbox_inches='tight')

    fixed now

    0 讨论(0)
  • 2021-01-30 21:39

    I encountered the same issue which plt.tight_layout() did not automatically solve.
    Instead, I used the labelpad argument in ylabel/set_ylabel as such:

    ax.set_ylabel('label here', rotation=270, color='k', labelpad=15)

    I guess this was not implemented when you asked this question, but as it's the top result on google, hopefully it can help users of the current matplotlib version.

    0 讨论(0)
提交回复
热议问题