Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the font name without changing the default font python

I have tried to use New Times New Roman font instead of Bitstream vera sans font which is a default for matplotlib in the school network server.

I get the following error with Times or Helvetica, or Arial.

not found error

To resolve this, I inquired to technical help to upload those fonts to server. I verified that they were uploaded.

Now after I removed fontList.cache and re-run the code as below:

import matplotlib.pyplot as plt
import numpy as np
x= np.arange(0,100)
y= 3*x-1
plt.plot(x,y)
plt.xlabel('x',fontdict={"name": "Times New Roman"})
plt.ylabel('y',fontdict={"name": "Times New Roman"})
plt.show()

The good thing is that I don't see the error message anymore, but bad thing is that after adding fontdict={"name": "Times New Roman"}, the label has disappeared.

I can't find the reason of this without any error.

like image 865
Isaac Avatar asked Oct 31 '22 19:10

Isaac


1 Answers

I believe that you can just use:

    plt.xlabel('x', fontname = 'Times New Roman')
    plt.ylabel('y', fontname = 'Times New Roman')

I think that your error is coming from an incorrect use of fontdict.

like image 84
Burgan Avatar answered Nov 13 '22 04:11

Burgan