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

Skip to content

Deprecate MathTextParser("bitmap") and associated APIs. #18591

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

Merged
merged 1 commit into from
Oct 2, 2020

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Sep 26, 2020

MathTextParser("bitmap") is rather low-level APIs to convert text
strings to images. Instead, one can use a much more generic method,
namely directly drawing to a new Figure() and saving with
bbox_inches="tight". Alternatively, if one really wants a single
function call, there's still mathtext.math_to_image.

Also fix the wx example to use light text colors when so directed by the
system theme.

PR Summary

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and pydocstyle<4 and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

self._mathtext_parser = mathtext.MathTextParser('bitmap')
img, _ = self._mathtext_parser.parse(lev, dpi=72,
prop=self.labelFontProps)
self._mathtext_parser = mathtext.MathTextParser('agg')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this specific use is going away via #16171.

@anntzer anntzer force-pushed the unmathtextbitmapbackend branch 4 times, most recently from 8e370a2 to 0bc633b Compare September 27, 2020 20:54
@QuLogic
Copy link
Member

QuLogic commented Sep 29, 2020

It appears that math_to_image doesn't accept a colour like the deprecated methods do?

@anntzer
Copy link
Contributor Author

anntzer commented Sep 30, 2020

You could wrap the call to math_to_image in a rc_context({"text.color": ...}): block. Do you want me to document that?

@QuLogic
Copy link
Member

QuLogic commented Sep 30, 2020

Yes, that should go in the deprecation note, maybe as a longer example.

@anntzer
Copy link
Contributor Author

anntzer commented Sep 30, 2020

done

@anntzer anntzer force-pushed the unmathtextbitmapbackend branch from 0bc633b to ef15c5a Compare September 30, 2020 21:41
`MathTextParser("bitmap")` is rather low-level APIs to convert text
strings to images.  Instead, one can use a much more generic method,
namely directly drawing to a new Figure() and saving with
`bbox_inches="tight"`.  Alternatively, if one really wants a single
function call, there's still `mathtext.math_to_image`.

Also fix the wx example to use light text colors when so directed by the
system theme.
@anntzer anntzer force-pushed the unmathtextbitmapbackend branch from ef15c5a to 5ce4ff2 Compare October 1, 2020 10:08
@tacaswell tacaswell added this to the v3.4.0 milestone Oct 1, 2020
from matplotlib.transforms import IdentityTransform


def text_to_rgba(s, *, dpi, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use math_to_image here?

Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Why not use math_to_image in both of the examples?

@anntzer
Copy link
Contributor Author

anntzer commented Oct 1, 2020

Because it's a super-specialized API which I don't think is particularly interesting to demonstrate (or even to expose), whereas drawing on a figure and saving with tight bbox works for basically anything you may want to draw -- including text, but not only that!

@tacaswell tacaswell merged commit 7303d81 into matplotlib:master Oct 2, 2020
@anntzer anntzer deleted the unmathtextbitmapbackend branch October 2, 2020 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants