Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib Plots: Bold font face not working for Helvetica Neue but works fine with Arial

I am having trouble setting the bold face for 'Helvetica Neue' font while using matplotlib plot. It works file with 'Arial' but somehow bold face for 'Helvetica Neue' doesn't work. Any suggestion?

Here the python code I am using:

mpl.rcParams['xtick.labelsize'] = 14
mpl.rcParams['ytick.labelsize'] = 14

mpl.rcParams['font.family'] = 'sans-serif'
#mpl.rcParams['font.sans-serif'] = ['Arial Narrow']
#mpl.rcParams['font.sans-serif'] = ['Arial']
mpl.rcParams['font.sans-serif'] = ['Helvetica Neue']
mpl.rcParams["font.weight"] = "bold"
mpl.rcParams["axes.labelweight"] = "bold"
mpl.rcParams["axes.labelsize"] = 16

params = {'mathtext.default': 'regular'}
plt.rcParams.update(params)

.
.
.
.

axes.set_xlabel("hello world")
axes.set_ylabel('hello world  1x10$^{555}$ (unit)')

Here are the attached images: enter image description hereenter image description here

like image 281
Dhruv Patel Avatar asked Sep 15 '25 13:09

Dhruv Patel


1 Answers

Managed to get it working finally. Here are the steps I took.

  1. Convert the desired .ttc font files to .ttf using the online font converter.

  2. Then paste these .ttf converted files into >>

        <python install patl>/python3.9/site-packages/matplotlib/mpl-data/fonts/ttf
    
  3. Remove the matplotlib cache (important step to see the changes) using

    rm -rf ~/.matplotlib/fontlist.cache
    

    and

    rm -rf ~/.matplotlib/fontlist.json
    
  4. Re-run the same code as in the question. It worked all well!

like image 143
Dhruv Patel Avatar answered Sep 18 '25 11:09

Dhruv Patel