0

我正在尝试使用自定义字体为我的 matplotlib 图的轴绘制一些数据。此字体没有 unicode。因此我的错误是:

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

按照官方文档中的建议,我设置了:

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

但是,我仍然收到上面的警告。

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()

在此处输入图像描述

我使用的字体在这里。请问你能帮帮我吗?

4

0 回答 0