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.
I just figured it out: the trick is to use bbox_inches='tight'
in savefig
.
E.G. plt.savefig("test.png",bbox_inches='tight')
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.