Matplotlib 2.0 index beyond baseline when super and index are used

With matplotlib 2.0, I had weird behavior when I use both the index and superscript of the same character. When they are combined, the index drops completely below the baseline. This did not happen with MPL 1.5. Here is a complete example:

import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rc("font", family="Times New Roman",weight='normal')
plt.rcParams.update({'mathtext.default':  'regular' })
plt.plot(1,1, label='$A_x^{b}$')
plt.plot(2,2,label='$A_x$')
plt.plot(3,3,label='$A^b$')
plt.plot(4,4,label='$A_x^{*}$')
plt.plot(5,5,label='$A^*$')
plt.legend(fontsize='xx-large')
plt.show()

I took this plot and approached the legend and drew some horizontal lines to show the relative positions of super and indexes.

enter image description here

I found these parameters in the mathtext.py file in the FontConstantBase class:

# Percentage of x-height of additional horiz. space after sub/superscripts
script_space = 0.05

# Percentage of x-height that sub/superscripts drop below the baseline
subdrop = 0.4

# Percentage of x-height that superscripts are raised from the baseline
sup1 = 0.7

# Percentage of x-height that subscripts drop below the baseline
sub1 = 0.3

# Percentage of x-height that subscripts drop below the baseline when a
# superscript is present
sub2 = 0.5

# Percentage of x-height that sub/supercripts are offset relative to the
# nucleus edge for non-slanted nuclei
delta = 0.025

# Additional percentage of last character height above 2/3 of the
# x-height that supercripts are offset relative to the subscript
# for slanted nuclei
delta_slanted = 0.2

# Percentage of x-height that supercripts and subscripts are offset for
# integrals
delta_integral = 0.1

2 ? 0,3 0,5 , ? , , , mathtext.py. , , , mpl 2.0. , ? .

0
1

, API, , apropiate mathtext.py.

mathtext , , ( , ):

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()

enter image description here

mathtext.DejaVuSansFontConstants :

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

enter image description here

.

Times New Roman, , , , FontConstantsBase DejaVuSansFontConstants. Serial Liberation.

+2

Source: https://habr.com/ru/post/1547975/


All Articles