-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Font "DejaVu Sans" can only be used through fallback #11077
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
Comments
Does Probably related to #10245 (due to the presence of a conda env, I guess). |
Nope, the problem is still here. The problem is also present using a fresh virtualenv created with:
|
Can you provide the contents of your fontList.json? (perhaps via gist.github.com or other gist service, as it can be quite long) |
I can't reproduce this locally, even though I forced the use of your font cache. |
I do not know exactly what would be interesting to print, but this is what I tried. I added this at line 1215: print(best_font.fname)
print("Score:", best_score)
print("Family:", self.score_family(prop.get_family(), best_font.name))
print("Style:", self.score_style(prop.get_style(), best_font.style))
print("Variant:", self.score_variant(prop.get_variant(), best_font.variant))
print("Weight:", self.score_weight(prop.get_weight(), best_font.weight))
print("Stretch:", self.score_stretch(prop.get_stretch(), best_font.stretch))
print("Size:", self.score_size(prop.get_size(), best_font.size))
print('findfont: Matching %s to %s (%s) with score of %f' %
(prop, best_font.name, repr(best_font.fname), best_score)) Then I ran the following code: import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams['font.family'] = 'DejaVu Sans'
fig, ax = plt.subplots(figsize=(2,2))
ax.set_title('serif here as not expected', fontsize=20)
plt.show() Output
But the displayed font is not correct: It seems to me that the font is correctly chosen at this step, so the problem is probably elsewhere. |
What happens if you edit backend_agg.py as follows:
? |
>>> import matplotlib as mpl
>>> import matplotlib.pyplot as plt
>>>
>>> mpl.rcParams['font.family'] = 'DejaVu Sans'
>>> fig, ax = plt.subplots(figsize=(2,2))
>>> ax.set_title('serif here as not expected', fontsize=20)
Text(0.5,1,'serif here as not expected')
>>> plt.show() Output
|
I noticed that if I set Inputimport matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams['font.family'] = 'sans-serif'
mpl.rcParams['font.sans-serif'] = 'DejaVu Sans'
fig, ax = plt.subplots(figsize=(1,1))
ax.set_title('no serif here as expected')
plt.show()
print(ax.title.get_font_properties().get_fontconfig_pattern()) OutputIt makes me think that "DejaVu Sans" is not a valid If "DejaVu Sans" is truly not acceptable as a |
Well, as I mentioned earlier specifying "DejaVu Sans" for font.family does work for me and should work. |
Ok I think I got it, truly sorry if you lost time on this. The font I have been actually seeing this whole time was the default LateX font. With Example: import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rcParams['text.usetex'] = False
mpl.rcParams['font.family'] = 'DejaVu Sans'
fig, ax = plt.subplots(figsize=(1,1))
ax.set_title('sans serif here')
plt.show()
print(ax.title.get_font_properties().get_fontconfig_pattern()) With According to the comment in matplotlibrc, only a subset of fonts are supported with
|
OK, glad its working for you... |
Bug report
Bug summary
When
rcParams['font.family']
is set to 'sans-serif', matplotlib correctly fallback to 'DejaVu Sans' (a warning is displayed and the "DejaVu Sans" font is plotted). However whenrcParams['font.family']
is directly set to 'DejaVu Sans', matplotlib seems to use another font without warning.Code for reproduction
Actual outcome
Expected outcome
I would expect the font to be "DejaVu Sans" in both cases (i.e. without serif in both cases). It is possible that the warning message is, in fact, incorrect. But I can't find a way to display the font that is currently displayed on the graph.
Matplotlib version
print(matplotlib.get_backend())
): TkAggMatplotlib was installed through conda (conda-forge channel).
Thank you.
The text was updated successfully, but these errors were encountered: