-1

I want to make a graph based on a data frame that has a column with Chinese characters. But the characters won't show on the graph, and I received this error.

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.

Thanks in advance!

Betty Gandhi
  • 453
  • 1
  • 4
  • 7
  • Does this answer your question? [How to display Chinese in matplotlib plot](https://stackoverflow.com/questions/21307832/how-to-display-chinese-in-pandas-plot) – Trenton McKinney Jul 22 '21 at 18:46
  • Does this answer your question? [How to plot a figure with Chinese Characters in label](https://stackoverflow.com/q/39630928/7758804) – Trenton McKinney Jul 22 '21 at 18:47
  • [matplotlib show chinese characters site:stackoverflow.com](https://www.google.com/search?q=matplotlib+show+chinese+characters+site:stackoverflow.com&sxsrf=ALeKk03UadVxnfL_qFeILJbYTEjSVfAwuw:1626979529280&sa=X&ved=2ahUKEwj-2ZiHq_fxAhVJsp4KHbvuCrwQrQIoBHoECAkQBQ&biw=1920&bih=975) – Trenton McKinney Jul 22 '21 at 18:56

1 Answers1

0

You will need to ensure that you are using a font that has the glyphs you want to use. Take a look at text with non-latin glyphs

From the above link:

As of v2.0 the default font, DejaVu, contains glyphs for many western alphabets, but not other scripts, such as Chinese, Korean, or Japanese.
To set the default font to be one that supports the code points you need, prepend the font name to 'font.family' or the desired alias lists

import matplotlib
matplotlib.rcParams['font.sans-serif'] = ['Source Han Sans TW', 'sans-serif']
Alex
  • 6,610
  • 3
  • 20
  • 38