Matplotlib绘图py:151: UserWarning: Glyph 27773 missing from current font.

Matplotlib drawing - Chinese garbled problem

In jupyter notebook, Chinese characters are involved in the drawing process using Matplotlib, and a warning appears

E:\Anaconda\lib\site-packages\IPython\core\pylabtools.py:151: UserWarning: Glyph 20215 (\N{CJK UNIFIED IDEOGRAPH-4EF7}) missing from current font.
  fig.canvas.print_figure(bytes_io, **kw)

matplotlib does not support Chinese by default

Example: Draw a histogram and set parameters using matplotlib

import matplotlib.pyplot as plt 
# 绘制价格分布直方图
(
    price_explode[price_explode!= '0'] 
    .value_counts() 
    .sort_index()
    .plot(figsize=(12, 6),title="价格分布", kind="hist", rot=15, ylabel="弹幕数")  # 绘图
#        -- plot()对结果绘图,
#        -- figsize即调整图的大小,
#        -- title即图的标题,
#        -- kind="hist"以直方图进行绘图,
#        -- rot=15将x坐标旋转15度,
#        -- ylabel用来设置y轴标签
)

result

Solution

Add the following codes on Mac and Windows respectively

#plt.rcParams['font.sans-serif'] = ['Arial Unicode MS']  # Mac中使得图标的中文能够正常显示
plt.rcParams['font.sans-serif'] = ['SimHei']  # Windows中使得图标的中文能够正常显示

Result: Drawing succeeded

Guess you like

Origin blog.csdn.net/qq_63195700/article/details/128537022