【问题标题】:How to show Chinese characters in Matplotlib graphs?如何在 Matplotlib 图中显示汉字?
【发布时间】:2021-09-29 20:34:39
【问题描述】:

我想根据一个数据框制作一个图表,该数据框有一列包含汉字。但是字符不会显示在图表上,我收到了这个错误。

C:\Users\march\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:238: RuntimeWarning: Glyph 19996 missing from current font.
  font.set_text(s, 0.0, flags=flags

this is the picture of the graph.

提前致谢!

【问题讨论】:

标签: python-3.x dataframe matplotlib


【解决方案1】:

您需要确保您使用的字体具有您要使用的字形。看看text with non-latin glyphs

从上面的链接:

从 v2.0 开始,默认字体 DejaVu 包含许多西方字母的字形,但不包含其他脚本,例如中文、韩文或日文。
要将默认字体设置为支持所需代码点的字体,请将字体名称添加到“font.family”或所需的别名列表

import matplotlib
matplotlib.rcParams['font.sans-serif'] = ['Source Han Sans TW', 'sans-serif']

【讨论】:

    猜你喜欢
    • 2014-01-07
    • 2011-11-20
    • 2020-01-26
    • 1970-01-01
    • 2012-01-24
    • 2011-12-09
    • 1970-01-01
    • 2019-03-03
    • 2017-07-30
    相关资源
    最近更新 更多