0

I am trying to plot some data using a custom font for the axis of my matplotlib plot. This font does not have unicodes. Thus the error I have is:

Font 'default' does not have a glyph for '-' [U+2212], substituting with a dummy symbol.

I set, as suggested in the official documentation, this:

matplotlib.rcParams['axes.unicode_minus'] = False

However, I still get the warning above.

import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.font_manager
%matplotlib inline

# Font set
path = 'bahnschrift_reg.ttf'
prop = matplotlib.font_manager.FontProperties(fname=path)
mpl.rcParams['axes.unicode_minus'] = False

# Plot
f, ax = plt.subplots(1,1)
ax.set_xscale('symlog', linthresh=0.001)
ax.set_xlim(-0.0001, 100) 
ax.set_ylim(0, 1.02)

# Set the font
for label in ax.get_xticklabels():
    label.set_fontproperties(prop)
    
plt.show()

enter image description here

The font I am using is here. Could you help me, please?

marcodena
  • 550
  • 2
  • 5
  • 15
  • Maybe [edit .ttf font file to add in missing symbol](https://stackoverflow.com/questions/10892693/edit-ttf-font-file-to-add-in-missing-symbol) helps? Or changing the tick formatting ([Matplotlib log-scale tick labels, minus sign too long in latex font](https://stackoverflow.com/questions/25210898/matplotlib-log-scale-tick-labels-minus-sign-too-long-in-latex-font))? – JohanC Oct 08 '21 at 12:10
  • The first one is a very good suggestion and I indeed followed that trick to do the plot ;D thx – marcodena Oct 09 '21 at 22:29

0 Answers0