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

Incorrect selection of Times New Roman Bold #5574

Closed
chernals opened this issue Nov 27, 2015 · 12 comments · Fixed by #14483
Closed

Incorrect selection of Times New Roman Bold #5574

chernals opened this issue Nov 27, 2015 · 12 comments · Fixed by #14483

Comments

@chernals
Copy link

On both my Mac and Linux setup (mpl 1.5.0) is appears that the bold version is selected over the regular one, as both are understood to have the same weight.

See this question on StackOverflow where I described the problem and the "solution".

http://stackoverflow.com/questions/33955900/matplotlib-times-new-roman-appears-bold/33962423#33962423

Please close this issue if this is an actual font problem unrelated to mpl.

@mdboom
Copy link
Member

mdboom commented Nov 27, 2015

#5414, while not ready immediately, should address this by using font-config rather than our own homegrown code for font lookup. That's our long term solution to these sorts of problems, but won't be ready until at least matplotlib 2.1, maybe later.

As for the actual problem at hand, I'm having trouble reproducing it. With the Times New Roman Bold that ships with Win8 (which has the filename timesbd.ttf and has the md5 hash 43a1861fb747438005fa1615b70798a4), the "style_flags" metadata is set correctly to indicate that it is bold. In the linked SO question the filename appears to be "Times New Roman Bold.ttf", so maybe that's a different font from a different source?

@tacaswell tacaswell added this to the proposed next point release (2.1) milestone Nov 30, 2015
@ferdinandvanwyk
Copy link

I recently started seeing this problem on OSX as well. The default Times fonts are named: Time New Roman.ttf, Time New Roman Bold.ttf, etc. The answer in the linked SO post seems to work, however, is there a better temporary solution to this?

@steffen-micdev
Copy link

I experienced the same problem. In font_manager.py the weight is set by scanning the font properties from sfnt4 = sfnt.get((1,0,0,4)) in the weight_dict.
Since the sfnt4 is "Times New Roman Bold" and the weight dict contains also "roman" as a valid weight, all Fonts containing "Roman" in this string will be set to a weight of 500, regardless of the "bold".

On simple solution is to remove "roman" from the weight_dict. Ideally would be a more sophisticated method to scan.

@jhrmnn
Copy link

jhrmnn commented May 5, 2017

Just encountered this problem as well. It can be fixed locally with

del matplotlib.font_manager.weight_dict['roman']
matplotlib.font_manager._rebuild()

@perwin
Copy link

perwin commented Jun 20, 2017

I started seeing this same problem recently, when I upgraded from matplotlib 1.5 to 2.0
(MacBook Pro 2012 with macOS 10.12.5, python.org's framework installation of Python 3.6.1)
(azag0's fix works for me)

@tacaswell tacaswell modified the milestones: 2.1 (next point release), 2.2 (next next feature release) Oct 3, 2017
@Datseris
Copy link

Datseris commented Oct 10, 2017

Just chiming in to say that this is happening also to me, in Windows 10, with matplotlib 2.0 and anaconda, python 3.6

Edit: I confirm that the answer by azag0 works, i.e.

del matplotlib.font_manager.weight_dict['roman']
matplotlib.font_manager._rebuild()

@xchank
Copy link

xchank commented Apr 2, 2018

Windows 10 with matplotlib 2.1.2 and anaconda
The answer by azag0 works like a charm

@austindowney
Copy link

austindowney commented Aug 23, 2018

This is happening for me with Matplotlib 2.2.2 on a Windows 10 machine. I assume there is no global fix to this solution other than the adding the local code provided by azag0.

This code returns "KeyError: 'roman'"every time I run it and I would like to find a way to fit it without the error showing up.

@tcanders
Copy link

I upgraded from Python 3.5.4 with matplotlib 2.0.2 to Python 3.7.1 with matplotlib 3.0.2 and this was suddenly a problem. The local fix works. I'm on Windows 7.

@perwin
Copy link

perwin commented Mar 1, 2019

This problem re-appeared when I upgraded to matplotlib 3.0.2 (macOS 10.13.6, Python.org's Python 3.7.2); azag0's fix worked again.

@JoElfner
Copy link

JoElfner commented Jun 7, 2019

Same here when upgrading from 3.0.3 to 3.10.0.
The answer

del matplotlib.font_manager.weight_dict['roman']
matplotlib.font_manager._rebuild()

did NOT solve the problem. Instead it completely crashed my fontmanager, raising several errors. Unluckily I had a deadline pressuring me to get back to work asap, thus I did not have the time to write down everything.
I had to re-install my whole anaconda dist, clearing all users/.matplotlib, users/.conda etc folders to make it work again. Additionally since then, the 'Times' font can't be found and instead of using 'Times New Roman', it is falling back to sans-serif DejaVu Sans...

@iTomxy
Copy link

iTomxy commented Jan 11, 2021

I fixed this by changing importing :

import matplotlib.font_manager
del matplotlib.font_manager.weight_dict['roman']
matplotlib.font_manager._rebuild()

and it works


when using jhrmnn's method, I got error :

AttributeError: module 'matplotlib' has no attribute 'font_manager'
  • OS: win 10
  • matplotlib 3.1.1

my codes:

import matplotlib as mpl
print(dir(mpl))
del mpl.font_manager.weight_dict['roman']
mpl.font_manager._rebuild()
from matplotlib import rcParams
rcParams['font.family'] = 'Times New Roman'
# rcParams['font.sans-serif'] = ['Tahoma']
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot([1, 2, 3], label='test')

ax.legend()
plt.show()

any help ?

@story645 story645 removed this from the future releases milestone Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.