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

Skip to content

latex_to_png: avoid deprecated matplotlib functions #12889

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
Apr 8, 2021

Conversation

jakevdp
Copy link
Contributor

@jakevdp jakevdp commented Apr 4, 2021

Fixes #12882

The replacement function recommended by matplotlib, mathtext.math_to_image, does not provide sufficient control over the output (e.g. text color, transparent background, dpi), so this PR adds code that creates the image manually following the approach in that function.

Copy link
Member

@MrMino MrMino left a comment

Choose a reason for hiding this comment

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

Quick feedback - I don't feel qualified enough for approving this, but I hope it will help @Carreau with merging / reviewing it further:

Using the snippet provided in the original issue I created two PNGs, one from ipython:master and one from jakevdp:mathtext

  • I can confirm that this PR does indeed get rid of the deprecation messages
  • The two files I get differ in the image size: master gives me 74x23, the code from this PR - 71x21. Not sure if it's important, might be something to look into.

@jakevdp
Copy link
Contributor Author

jakevdp commented Apr 5, 2021

Thanks for checking on this – I've seen this difference in image size as well. I suspect that's the difference between the "path" parser and the "bitmap" parser, and it causes problems for some formulas (e.g. "\int_0^\infty f(x)dx" ends up slightly cut-off at the top).

I'm going to mark this as a draft for now and see if I can improve on that.

@jakevdp jakevdp marked this pull request as draft April 5, 2021 21:34
@Carreau
Copy link
Member

Carreau commented Apr 6, 2021

Thanks @jakevdp and @MrMino.

The test failures are unrelated, are are regular on those tests; so feel free to ignore those, I'll probably end up marking them as knowfail.

@jakevdp if you are a regular user of this feature and are happy with the result; we can trust you. Let us know if it should be backported on 7.x.

@jakevdp
Copy link
Contributor Author

jakevdp commented Apr 7, 2021

Thanks! I'm not yet happy with the result, but I'm hoping to dig-in again shortly 😁

@jakevdp jakevdp marked this pull request as ready for review April 7, 2021 04:00
@jakevdp
Copy link
Contributor Author

jakevdp commented Apr 7, 2021

OK - I adjusted the dpi in the width/height calculation and I think this is ready to go.

@Carreau Carreau added this to the 8.0 milestone Apr 8, 2021
@Carreau
Copy link
Member

Carreau commented Apr 8, 2021

Thanks Jake,

I've maker this as 8.0, if it become which I hope we can start to push forward and release in a coupl eof month, if this becomes too annoying we can still backport later.

Thanks.

@jondo
Copy link

jondo commented Jun 15, 2021

My students and I are working with Sympy and are severely influenced by this and similar warnings, see the following example screenshot:
image

and the contained warnings:

``` /home/robert/projects/teaching/MMech_Exercises_Robert/env/lib/python3.8/site-packages/IPython/lib/latextools.py:126: MatplotlibDeprecationWarning: The to_png function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use mathtext.math_to_image instead. mt.to_png(f, s, fontsize=12, dpi=dpi, color=color) /home/robert/projects/teaching/MMech_Exercises_Robert/env/lib/python3.8/site-packages/IPython/lib/latextools.py:126: MatplotlibDeprecationWarning: The to_rgba function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use mathtext.math_to_image instead. mt.to_png(f, s, fontsize=12, dpi=dpi, color=color) /home/robert/projects/teaching/MMech_Exercises_Robert/env/lib/python3.8/site-packages/IPython/lib/latextools.py:126: MatplotlibDeprecationWarning: The to_mask function was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use mathtext.math_to_image instead. mt.to_png(f, s, fontsize=12, dpi=dpi, color=color) /home/robert/projects/teaching/MMech_Exercises_Robert/env/lib/python3.8/site-packages/IPython/lib/latextools.py:126: MatplotlibDeprecationWarning: The MathtextBackendBitmap class was deprecated in Matplotlib 3.4 and will be removed two minor releases later. Use mathtext.math_to_image instead. mt.to_png(f, s, fontsize=12, dpi=dpi, color=color)```

Would it please be possible to get this into an earlier release?
Are all of these warnings fixed by this change?

@jondo
Copy link

jondo commented Jun 15, 2021

Temporary workaround (from computationalmodelling/nbval#167):

import warnings
from matplotlib import MatplotlibDeprecationWarning
warnings.filterwarnings('ignore', category=MatplotlibDeprecationWarning)

archlinux-github pushed a commit to archlinux/svntogit-community that referenced this pull request Aug 7, 2021
…cy and fix check()

What a mess in tests LOL!

Related tickets:

[1] computationalmodelling/nbval#162
[2] computationalmodelling/nbval#167
[3] ipython/ipython#12817
[4] ipython/ipython#12889
[5] ipython/ipykernel#591
[6] matplotlib/matplotlib#20046

git-svn-id: file:///srv/repos/svn-community/svn@994636 9fca08f4-af9d-4005-b8df-a31f2cc04f65
archlinux-github pushed a commit to archlinux/svntogit-community that referenced this pull request Aug 7, 2021
…cy and fix check()

What a mess in tests LOL!

Related tickets:

[1] computationalmodelling/nbval#162
[2] computationalmodelling/nbval#167
[3] ipython/ipython#12817
[4] ipython/ipython#12889
[5] ipython/ipykernel#591
[6] matplotlib/matplotlib#20046


git-svn-id: file:///srv/repos/svn-community/svn@994636 9fca08f4-af9d-4005-b8df-a31f2cc04f65
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.

latex_to_mpl_png relies on deprectated functionality in matplotlib 3.4
4 participants