scikit-hep / mplhep

Extended histogram plotting on top of matplotlib and HEP collaboration compatible styling
https://mplhep.readthedocs.io
MIT License
185 stars 64 forks source link

LHCb2 style problems #273

Closed Emix26 closed 3 years ago

Emix26 commented 3 years ago

I see two problems with the LHCb2 style :

ryuwd commented 3 years ago

2 different fonts are used for the text in italics and the text not in italics. Is it possible to only use the one from the text not in italics ?

I'm not sure what you mean by 'text in italics' + vice-versa, but I have been using the LHCb2 style for a while now and this helped me fix the mathtext:

At first the font would fall back to DejaVu Sans by default for mathtext enclosed in $. I noticed I could force the fonts this way:

import matplotlib
matplotlib.rcParams["font.family"] = "serif"
matplotlib.rcParams["font.serif"] = "Times New Roman"
matplotlib.rcParams["font.cursive"] = "Times New Roman"
matplotlib.rcParams["mathtext.fontset"] = "custom"
matplotlib.rcParams["mathtext.rm"] = "Times New Roman"
matplotlib.rcParams["mathtext.it"] = "Times New Roman:italic"
matplotlib.rcParams["mathtext.bf"] = "Times New Roman:bold"

Also sometimes deleting the matplotlib font cache helps (rm ~/.cache/matplotlib for linux) if matplotlib can't find the font.

If Times New Roman is not installed, you can install it through conda

conda install -c conda-forge mscorefonts
rm ~/.cache/matplotlib # matplotlib can have trouble finding the fonts otherwise
andrzejnovak commented 3 years ago

@mayou36 thoughts on setting "Times New Roman" for mathtext? The equivalent is done for other styles/fonts.

ryuwd commented 3 years ago

Small addition, I also ran into buggy minus signs in some environments, and fixed the problem by setting:

import matplotlib.pyplot as plt

plt.rc("axes", unicode_minus=False)
jonas-eschle commented 3 years ago

@mayou36 thoughts on setting "Times New Roman" for mathtext? The equivalent is done for other styles/fonts.

Sorry for the long silence, indeed that seems reasonable to me. I would even do it with LHCb2 as a fix as it does not really change the style. I'll make a PR

Small addition, I also ran into buggy minus signs in some environments, and fixed the problem by setting:

import matplotlib.pyplot as plt

plt.rc("axes", unicode_minus=False)

The problem is that this will use a dash, not a minus. This is shorter, it looks different. Did you install the Times New Roman? If that is missing, then the minus sign does not work.

ryuwd commented 3 years ago

Did you install the Times New Roman? If that is missing, then the minus sign does not work.

Yes, with conda-forge mscorefonts, which includes Times New Roman.

The problem is that this will use a dash, not a minus. This is shorter, it looks different.

I agree this is not optimal. BTW by buggy I mean the fonts will try to render a minus as a box instead

jonas-eschle commented 3 years ago

@andrzejnovak an idea how to go about this? Technically it's not a mplhep problem, but practically users will use it and if they don't have Times New Roman installed, they will have problems rendering it.

We could make a warning if the font is missing? Or do you know of a good replacement font with all unicode characters in there that is more available?

andrzejnovak commented 3 years ago

I am not sure what the desirable behaviour is here. IIUC you want Times New Roman as default with unicode minus, the issue being that fallback fonts usually don't have it, giving the empty char.

If you don't want to use dash by default, you could create sth similar to https://github.com/scikit-hep/mplhep/blob/master/src/mplhep/_deprecate.py#L72 with a check to the matplotlib font cache if Times New Roman is present and if not, emit a warning along the lines of install mscorefonts or use dash.

Alternatively, if you find a lookalike with unicode minus and open license, we could package it in mplhep_data https://learnui.design/blog/times-new-roman-similar-fonts.html

jonas-eschle commented 3 years ago

Alright, I don't have strong feelings about this.

As Atlas also uses the "Tex Gyre Termes" for serif fonts, which is similar to Times New Roman, I would suggest to use this and add it to the mplhep-data. It's also the same family as the sans-serif fonts used by the other experiments.

(I would also suggest to change the default size of the plots in the lhcb style to better match the other styles).

What do you think, LHCb3 or updating the LHCb2? I would tend to go with updating the 2 as nothing is really a large change.