Matplotlib 2.0 Subscript Outside Of Baseline When Super And Subscript Are Both Used
Solution 1:
There seems to be no API to change this but you can monkey-patch the appropriate 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):
deftest_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()
(For more recent versions of matplotlib, like 3.4.2, this class appears to have been moved to a _mathtext
submodule. You may need to do something like the following:)
# Later versions of matplotlib (e.g., 3.4.2)from matplotlib.mathtext import _mathtext as mathtext
mathtext.FontConstantsBase.sup1 = 0.5
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.
Post a Comment for "Matplotlib 2.0 Subscript Outside Of Baseline When Super And Subscript Are Both Used"