Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve UserWarning: findfont: Could not match :family=Bitstream Vera Sans

Following this example:

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
for i, label in enumerate(('A', 'B', 'C', 'D')):
    ax = fig.add_subplot(2,2,i+1)
    ax.text(0.05, 0.95, label, transform=ax.transAxes,
      fontsize=16, fontweight='bold', va='top')

plt.show()

I get this output:

enter image description here

Why are my labels normal weight, while the documentation shows this should create bold letters A, B, C, D?

I also get this warning:

Warning (from warnings module):
File "C:\Python27\lib\site-packages\matplotlib\font_manager.py", line 1228
UserWarning)
UserWarning: findfont: Could not match :family=Bitstream Vera Sans:style=italic:variant=normal:weight=bold:stretch=normal:size=x-small. Returning C:\Python27\lib\site-packages\matplotlib\mpl-data\fonts\ttf\Vera.ttf

OP Resolution

  • From a deleted answer posted by the OP on Sep 15, 2013
    • Ok, it was a problem with the installation of matplotlib
like image 630
user1915817 Avatar asked Sep 15 '13 12:09

user1915817


4 Answers

Try using weight instead of fontweight.

like image 171
Safwan Avatar answered Nov 09 '22 01:11

Safwan


Maybe try using this -

plt.rcParams['axes.labelsize'] = 16
plt.rcParams['axes.labelweight'] = 'bold'

Do this at a global level in your program.

like image 7
Dinesh Avatar answered Nov 09 '22 03:11

Dinesh


The example from your question works on my machine. Hence you definately have a library problem. Have you considered using latex to make bold text? Here an example

enter image description here

Code

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(3, 1)
ax0, ax1, ax2 = axs

ax0.text(0.05, 0.95, 'example from question',
        transform=ax0.transAxes, fontsize=16, fontweight='bold', va='top')
ax1.text(0.05, 0.8, 'you can try \\textbf{this} using \\LaTeX', usetex=True,
        transform=ax1.transAxes, fontsize=16, va='top')
ax2.text(0.05, 0.95,
         'or $\\bf{this}$ (latex math mode with things like '
         '$x_\mathrm{test}^2$)',
        transform=ax2.transAxes, fontsize=10, va='top')

plt.show()
like image 5
Markus Dutschke Avatar answered Nov 09 '22 01:11

Markus Dutschke


Not sure if you're still having the issue. I tried your code in Anaconda/Spyder, Python 2.7. The plots appear with Bold labels (A,B,C,D). I agree the issue is probably with the library. Try replacing / updating font_manager.py or confirming font files are present:

Lib\site-packages\matplotlib\mpl-data\fonts\ttf\

like image 1
kibitzforu Avatar answered Nov 09 '22 02:11

kibitzforu