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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With