我的代码:
import matplotlib
matplotlib.rcParams['font.family'] = ['Source Han Sans TW', 'sans-serif']
matplotlib.__version__ # 3.5.3
import math
from matplotlib import pyplot as plt
size = math.ceil(len(df_attr)** (1/2))
fig = plt.figure()
for i, col in enumerate(df_attr):
fig.add_subplot(size, size, i + 1)
df_template_income_tax[col].value_counts().plot(kind="bar", ax=plt.gca(), title=df_attr_eng[i], rot=0)
fig.tight_layout()
出现错误:
findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans.
findfont: Generic family 'sans-serif' not found because none of the following families were found: SimHei
/opt/microsoft/mlserver/9.4.7/runtime/python/lib/python3.7/site-packages/ipykernel_launcher.py:13: UserWarning: Glyph 25293 (\N{CJK UNIFIED IDEOGRAPH-62CD}) missing from current font.
尝试了一些解决方案:
- Glyph 23130 missing from current font
- How to show Chinese characters in Matplotlib graphs?
1.官方解决方案:https://matplotlib.org/stable/tutorials/text/text_props.html#text-with-non-latin-glyphs
有什么需要安装或其他显示汉字?
1条答案
按热度按时间bqjvbblv1#
检查可用的字体代码如下。
如果你找不到你的字体,尝试一些解决方案,如here。