Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Public API to modify mathtext font constants #9165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
u55 opened this issue Sep 7, 2017 · 3 comments
Open

Public API to modify mathtext font constants #9165

u55 opened this issue Sep 7, 2017 · 3 comments
Labels
keep Items to be ignored by the “Stale” Github Action topic: text/mathtext

Comments

@u55
Copy link
Contributor

u55 commented Sep 7, 2017

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.

@u55
Copy link
Contributor Author

u55 commented Sep 9, 2017

@mdboom Michael, git blame tells me that you changed the API back in baa2b6e. Did you have a particular reason in mind for keeping _font_constant_mapping private?

@anntzer
Copy link
Contributor

anntzer commented Sep 10, 2017

It's probably private because no one asked for it to be public, and we are actively trying to keep the public API as small as possible (and if it goes public it should be properly documented). Of course the funny thing is that the various constant classes are themselves public.

FWIW having spent ~10s looking at it I'd guess the various classes should just be namedtuples (using ._replace if we want to be able to inherit from another font constant), but otherwise have no strong opinion as to making the dictionary public (if documented).

@github-actions
Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Apr 18, 2023
@anntzer anntzer added the keep Items to be ignored by the “Stale” Github Action label Apr 18, 2023
@rcomer rcomer removed the status: inactive Marked by the “Stale” Github Action label Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep Items to be ignored by the “Stale” Github Action topic: text/mathtext
Projects
None yet
Development

No branches or pull requests

4 participants