Code Monkey home page Code Monkey logo

Comments (9)

matthewfeickert avatar matthewfeickert commented on September 4, 2024

cc @kratsg as he might have thoughts here too.

from mplhep.

andrzejnovak avatar andrzejnovak commented on September 4, 2024

Yup. @matthewfeickert what mpl version are you on. matplotlib/matplotlib#16509 might have changed the behaviour because I can't replicate it on master and it should be available in 3.3.

Otherwise, you should try setting axes.unicode_minus=False to replace the minus glyph by a hyphen, which is in most fonts.

from mplhep.

matthewfeickert avatar matthewfeickert commented on September 4, 2024

what mpl version are you on. matplotlib/matplotlib#16509 might have changed the behaviour because I can't replicate it on master and it should be available in 3.3.

Hm, that's strange as I'm on

$ pip list | grep matplotlib
matplotlib         3.3.1

and still seeing this (I'm on Ubuntu FWIW). Though thanks for contributing upstream to matplotlib! That's so great to see in general. :)

Otherwise, you should try setting axes.unicode_minus=False to replace the minus glyph by a hyphen, which is in most fonts.

Hm. This doesn't seem to help things. In the original script if I append that immediately after the ATLAS style

    plt.style.use(mplhep.style.ATLAS)
    matplotlib.rcParams["axes.unicode_minus"] = False

I still get the same result.

However, I understand why you're having trouble repliating as this is the result of the fonts on my system. We can see this by looking at the following Dockerfile:

FROM python:3.8

RUN python -m pip install --upgrade pip setuptools wheel && \
    python -m pip install --no-cache-dir numpy mplhep && \
    python -c "import matplotlib"

ENTRYPOINT ["/bin/bash"]

which can be built with

docker build . -f Dockerfile -t mplhepissue-178:latest

and then with the script (named issue_178.py) in the same working directory run

$ docker run --rm -v $PWD:$PWD -w $PWD mplhepissue-178:latest -c "python issue_178.py"

resulting in

findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans.
findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans.
findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans.
findfont: Font family ['cursive'] not found. Falling back to DejaVu Sans.
'texgyreheros-regular.otf' can not be subsetted into a Type 3 font. The entire font will be embedded in the output.

So apparently the fonts exist on the version of Debian

$ docker run --rm mplhepissue-178:latest -c "cat /etc/os-release"
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

but not on Ubuntu 19.10. So I'll try to figure out what fonts are missing and then post a fix here so that we can close this Issue and other Ubuntu users lagging behind the 20.04 LTS release can get help.

from mplhep.

andrzejnovak avatar andrzejnovak commented on September 4, 2024

Hmm, thanks for the thorough report! One naive way to check which font is causing trouble would be to cycle through the font list you pass in one at a time.

On a side note, can you check what happens if you also append Tex Gyre Heros which ships with mplhep and should have a reasonable char set.

I have suggested appending this to the list in the past, but @kratsg has a preference for not having Helvetica failing loudly.

from mplhep.

kratsg avatar kratsg commented on September 4, 2024

I have suggested appending this to the list in the past, but @kratsg has a preference for not having Helvetica failing loudly.

Not sure what you mean by this. But we should really adhere to the ATLAS styleguide. Nobody's going to know that the font is different so obviously unless they're a font designer, but I don't think it's right to force a font that is not recommended by the official pubcom.

from mplhep.

andrzejnovak avatar andrzejnovak commented on September 4, 2024

@matthewfeickert are you planning to come back to this or can I close it?

from mplhep.

matthewfeickert avatar matthewfeickert commented on September 4, 2024

@matthewfeickert are you planning to come back to this or can I close it?

I am planning on coming back to it, but this can be closed for now as it isn't a mplhep bug.

from mplhep.

matthewfeickert avatar matthewfeickert commented on September 4, 2024

For the record, the fix was incredibly easy and just total oversight on my part. I had forgotten that matplotlib has a font cache and matplotlib.font_manager. So all that is needed is

import matplotlib.font_manager
matplotlib.font_manager._rebuild()

as I apparently had the correct fonts (I think all that is needed is the dejavu font).

from mplhep.

matthewfeickert avatar matthewfeickert commented on September 4, 2024

Actually, the fix ended up being more subtle than just the font list cache. For the Stack Ovreflow question "matplotlib mathtext font warning: Font 'default' does not have a glyph" I had more than just fontlist-v330.json in the matplotlib cache

$ ls -htra ~/.cache/matplotlib/
..  tex.cache  fontlist-v330.json  .

so rebuilding the font list cache with

import matplotlib.font_manager
matplotlib.font_manager._rebuild()

or

rm ~/.cache/matplotlib/fontlist-v330.json

wasn't sufficient. Instead the entire matplotlib cache needs to be updated, which is most easily done with

rm ~/.cache/matplotlib/*

from mplhep.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.