8000 Public API to modify mathtext font constants · Issue #9165 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Public API to modify mathtext font constants #9165
Open
@u55

Description

@u55

Hi matplotlib developers,

I recently needed to modify the mathtext font constants (the superscript height) of a non-standard font (Arial) and found that there is no public API to accomplish this. I did, however, find that I could do what I wanted by accessing the private mathtext._font_constant_mapping dictionary. A minimal working example is below:

import matplotlib.pyplot as plt
from matplotlib import mathtext

plt.rcParams.update({
    'text.usetex':False,
    'font.family':'sans-serif',
    'font.sans-serif':['Arial'],
    'mathtext.default':'regular',
    })

class ArialFontConstants(mathtext.FontConstantsBase):
    # Percentage of x-height that superscripts are raised from the baseline
    sup1 = 0.4

# Register font constants for Arial
mathtext._font_constant_mapping['Arial'] = ArialFontConstants


text = r'$h = 6.62607004 \times 10^{-34}\; m^2\, kg\,/\,s$'

plt.figure(figsize=(3, 2))
plt.axis('off')
plt.text(0, 0.5, text)
plt.show()

This works great, but I think there should be a public and documented method to customize mathtext font constants. Perhaps we should just remove the leading underscore of _font_constant_mapping to make it permanent and public? Also, I think that an example of the new public API should be added to the mathtext tutorial documentation.

Thanks,

Tested with matplotlib 2.0.2 and python 3.6.2 running on Arch Linux.

Metadata

Metadata

Assignees

No one assigned

    Labels

    keepItems to be ignored by the “Stale” Github Actiontopic: text/mathtext

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0