My code:
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()
Got errors:
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.
Tried some solutions from:
- Glyph 23130 missing from current font
- How to show Chinese characters in Matplotlib graphs?
- official solution: https://matplotlib.org/stable/tutorials/text/text_props.html#text-with-non-latin-glyphs
Is there anything need to install or another to show chinese characters?