Skip to content
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

Change of style in matplotlib #3514

Closed
neutrinoceros opened this issue Sep 15, 2021 · 8 comments · Fixed by #3520
Closed

Change of style in matplotlib #3514

neutrinoceros opened this issue Sep 15, 2021 · 8 comments · Fixed by #3520
Labels
Milestone

Comments

@neutrinoceros
Copy link
Member

Bug report

Bug summary

Matplotlib 3.4 came with a change in default math text font that affects how yt plots look by default. IMO the "classic" yt look is much nicer so I'd love that it stayed the default style as far as yt is concerned, with no regards to what matplotlib version is installed.

Code for reproduction

Here's a simple demo using yt 4.0 and matplotlib 3.4

import yt
import matplotlib.pyplot as plt

def myplot():
    ds = yt.load_sample("IsolatedGalaxy")
    sp = yt.SlicePlot(ds, "z", ("gas", "density"))
    return sp

# default options with matplotlib 3.4
myplot().save("/tmp/defaults")

Actual outcome

defaults_Slice_z_density

Expected outcome
This is the "classic yt" look that required no tweaking before Matplotlib 3.4
classic_yt_Slice_z_density

now it can be reproduced with any version of matplotlib with some additional effort on the user side.

plt.rcParams["mathtext.fontset"] = "cm"
myplot().save("/tmp/classic_yt")

this is the simplest way to do it, but unfortunately it has side effects, as it won't just change the settings for that one yt plot, but globally change how matplotlib looks through out the session.

Side effects can be avoided using a context manager

# with temporary settings (no side effects)
with plt.rc_context({"mathtext.fontset": "cm"}):
    myplot().save("/tmp/classic_yt")

but this technique is IMO too disruptive.

I suggest we could use such context manager internally to restore yt's default look with no tweaking on the user side. In order to preserve flexibility (users should still be able to set a different font), some design decisions would be needed.
What do other users and developers think ?

Version Information

  • Operating System: OsX
  • Python Version: 3.9.5
  • yt version: 4.0.1
  • Other Libraries (if applicable): Matplotlib 3.4.2
@matthewturk
Copy link
Member

I do like the old look, and the context manager approach seems right.

@chummels
Copy link
Member

Agreed. I like the old look as well. Good job in spotting these changes!

@neutrinoceros
Copy link
Member Author

Note: I want to research the exact PR that changed that upstream.

@neutrinoceros
Copy link
Member Author

What a nice surprise this turned out to be (look who wrote issue 6518 !)

So apparently the change of default math font actually dates back to MPL 2.0, see https://matplotlib.org/2.0.0/users/whats_new.html#change-in-default-font

It is not clear why it only popped up in yt 5 years latter with MPL 3.4, but here is an issue that was closed on MPL 3.4.0

So maybe there's what we need to know there, and it's possible that the change of behaviour wasn't intentional after all and could be considered a MPL bug. I'll investigate this further another time.

@neutrinoceros neutrinoceros added this to the 4.1.0 milestone Sep 16, 2021
@neutrinoceros
Copy link
Member Author

The change bisects to matplotlib/matplotlib#18862

@chummels
Copy link
Member

Interesting. I don't understand why we're only just seeing it when it was merged almost a year ago. Is it because that only made it into a recent MPL release that we started using?

@neutrinoceros
Copy link
Member Author

neutrinoceros commented Sep 17, 2021

The first release to contain the changing patch was 3.4.0, which wasn't released as long ago. At the time there were a couple worse incompatibilities to handle, so I set this one up aside. It was indeed more work to track it down and I'm a clearly not done yet.
Hopefully future releases will be less disruptive for us since we've started testing against the dev version of MPL

@neutrinoceros
Copy link
Member Author

Follow up answer : turns out Nathan implemented custom parametrization inside yt to ensure style consistency without regards for matplotlib's defaults. Now because matplotlib introduced a new parameter with their 3.4 release, Nathan's implementation on the yt side needed a slight adjustment, but it turned out to be pretty easy once I figured out where it was. See #3520

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants