Matplotlib绘图坐标轴上下标和部分字体格式设置

在用matplotlib画图时经常要设置坐标轴的上下标,第一种方法是:

ax.set_ylabel(u'ab$^{cd}$,fontdict=font)#上标,font为提前设置好的字体样式
#or
ax.set_ylabel(u'ab$_{cd}$,fontdict=font)#下标

那么这种方法的问题是{}里面的内容无法设置成font的格式,因此尝试了第二种方法:

ax.set_ylabel(u'$\regularmath{ab^{cd}}$,fontdict=font)

这样可以解决字体设置的问题。另外如果需要设置部分的内容为斜体(例如设置ab为斜体),可以通过

ax.set_ylabel(u'$\regularmath{{\itab}^{cd}}$,fontdict=font)

但是,"ab"还是设置不了加粗。。。
效果类似于:
在这里插入图片描述

你可能感兴趣的:(##,Python遥感数据处理,python,matplotlib)