Matplotlib 2.0 subscript outside of baseline when super and subscript are both used

萝らか妹 提交于 2019-11-29 18:10:48

There seems to be no API to change this but you can monkey-patch the apropiate class instead of editing mathtext.py.

Using the default mathtext font the position of the subscript changes if there is a superscript (not totally under the baseline but you can see the effect):

def test_plot():
    plt.figure()
    plt.plot(1,1, label='$A_x^b$')
    plt.plot(2,2,label='$A^b_x$')
    plt.plot(3,3,label='$A_x$')
    plt.plot(4,4,label='$A_x^*$')
    plt.plot(4,4,label='$A^*_x$')
    plt.plot(5,5,label='$A^*$')
    plt.legend(fontsize='xx-large')

# default mathtext font in matplotlib 2.0.0 is 'dejavusans'
# set explicitly for reproducibility
plt.rcParams['mathtext.fontset'] = 'dejavusans'
test_plot()

Monkey-patching mathtext.DejaVuSansFontConstants you can make the effect disappear:

import matplotlib.mathtext as mathtext
mathtext.DejaVuSansFontConstants.sub2 = 0.3  # default 0.5
test_plot()

I can't see any issue with the asterisk.

I don't have Times New Roman installed so I can't test your exact use case but probably you need to patch FontConstantsBase instead of DejaVuSansFontConstants. It worked for me using Liberation Serif.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!