1

I am trying to change the font weight in matplotlib with the following code:

from matplotlib import pyplot as plt
import numpy as np

plt.rcParams.update({"font.size":16})
plt.rcParams["axes.labelweight"] = "light"
plt.rcParams["font.weight"] = "light"

t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)

plt.figure(4)
plt.plot(t,s)
plt.ylabel("y label")
plt.xlabel("x label")
plt.savefig("test.pdf",bbox_inches="tight",format="pdf",transparent=True)

However, only the bold and normal weights seem to work. Despite of the fact "light" or "ultralight" are listed as possible options in the doc, I don't see any difference between them and the "normal" font weight.

Kyraz99
  • 23
  • 3
  • 1
    Not all fonts come with all the weights. Try to [change matplotlib's font](https://stackoverflow.com/questions/21321670/how-to-change-fonts-in-matplotlib-python) and see whether you can find one that supports the `light` and `ultralight` values. It would be impossible to list all possible font<-> weights combinations in the documentation. – Bakuriu Apr 04 '20 at 09:06
  • I see no explicitly named font in your code so you may have to [find out what font you have now](https://stackoverflow.com/questions/27817912/find-out-which-font-matplotlib-uses). If it indeed does not come with a Light style, change it to one that has. – Jongware Apr 04 '20 at 10:27
  • 1
    I managed to add a light font `DejaVuSans-Light.ttf` in `\site-packages\matplotlib\mpl-data\fonts\ttf`, next to `DejaVuSans-Bold.ttf` and `DejaVuSans.ttf`, I can precise `plt.rcParams["font.family"] = "DejaVu Sans"`and `plt.rcParams["axes.labelweight"] = "bold"` in the code to have this bold version, but the light seems to be still inactive. – Kyraz99 Apr 04 '20 at 11:01

0 Answers0