Python: matplotlib drawing can not display Chinese or negative sign, displayed as a frame

1. Problem: Chinese cannot be displayed, it is displayed as a frame.

solve:

  1. Run the code to find the path of matplotlib configuration file

    import matplotlib
    matplotlib.matplotlib_fname()
    
  2. Use a text editor to open matplotlibrcthe configuration file, find #font.family:, and #font.sans-serifthe two lines.

  3. Remove the comments on these two lines and font.sans-serif:add SimHei(Simplified Black) after

  4. Restart the console and run it.

2. Problem: The negative sign cannot be displayed, which is displayed as a frame

solve:

  1. Run the code to find the path of matplotlib configuration file

    import matplotlib
    matplotlib.matplotlib_fname()
    
  2. Open the matplotlibrcconfiguration file with a text editor , find #axes.unicode_minus:Truethis line, remove the comment, and change True to False.

  3. Restart the console and run it.

Published 47 original articles · Like 33 · Visit 310,000+

Guess you like

Origin blog.csdn.net/kaever/article/details/105255481