How can I solve the problem that Anaconda cannot display Chinese Characters in Python,

Source: Internet
Author: User

How can I solve the problem that Anaconda cannot display Chinese Characters in Python,

When we use Anaconda in Python as a chart, we often encounter problems in labels that cannot be displayed.

Df_clean.boxplot (column = 'avgsalary ', by = 'city', figsize = (9, 7 ))

The result is as follows:

The labels of the chart are incorrect. A white box is displayed. The default English font is used for the chart. However, the labels are all Chinese, leading to a conflict. So you need to use matplotlib.

From matplotlib. font_manager import FontPropertiesfont_zh = FontProperties (fname = "C: \ Windows \ Fonts \ simsun. ttc ") ax = df_clean.boxplot (column = 'avgsalary ', by = 'city', figsize = (9, 7) for label in ax. get_xticklabels (): label. set_fontproperties (font_zh)

First, load the font management package and set a variable for loading Chinese fonts. Different system paths are different. Boxplot is the box plot function we call. column selects the value of the box plot, by is the classification variable, and figsize is the size.

Ax. get_xticklabels gets the axis scale, which means that the white box of the city name cannot be correctly displayed. Use set_fontpeoperties to change the font. So we obtained the box plot we wanted. There are other ways to change the font. You can search for the keyword matplotlib Chinese font online.

The result is as follows:

View comments

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.