Chinese in matplotlib

I recently needed to display Chinese characters in a plot legend. I’ve only ever changed font size in the past so this was new to me.

Before adding a legend, you need to create a font properties object.

from matplotlib import font_manager
...
fontP = font_manager.FontProperties()
fontP.set_family('SimHei')
fontP.set_size(14)
plt.legend(prop=fontP)
plt.show()