One 、 In the test matplotlib When I met X The problem of axis Chinese character not displaying , Refer to the Internet

The source code is as follows

from matplotlib import pyplot as plt
import random
import matplotlib
from matplotlib import font_manager # my_font = {'family' : 'MicroSoft YaHei',
# 'weight' : 'bold',
# 'size' : 'larger'}
# matplotlib.rc("font",**my_font)
# matplotlib.rc("font",)
my_font = font_manager.FontProperties(fname="C:\\Windows\\Fonts\\msyh.ttf") plt.figure(figsize=(,),dpi=) x = range(,)
y = [random.randint(,) for i in range()] _xticks_labels = ["10 spot {} branch ".format(i) for i in range()]
_xticks_labels += ["11 spot {} branch ".format(i) for i in range()]
# plt.xticks(list(x)[::])

Two 、 Refer to online play

Computer environment :Windows7-64bit,Anaconda3-4.2.0( Corresponding python 3.5.2 edition ),IDE yes Anaconda Self contained Spyder 3.

1、 find Windows The font library directory of the system , Default in C:\Windows\Fonts Under the table of contents .


2、 Choose the font you like , then “ Right click ”→“ attribute ”, You can see the name of the font .

This tutorial takes Microsoft YaHei font as an example , You can also choose other Fonts , If your own font library can't meet your needs , You can download other fonts online , Unzip the font to C:\Windows\Fonts directory .


3、 stay IDE In the tools , Import matplotlib library , Start defining the path of the font .

  • 1 Don't set parameters first , You can see that the Chinese font is displayed as a box ( What is used here is SVC Three classification model ).
  • 2 After setting the parameters , You can see that the Chinese font can be displayed normally .( The code has been tested , Safe to use )

Where need Chinese settings , Make sure the function has fontproperties = my_font Parameters can be . such as x The label of the shaft is : The calyx length of iris . Then you can use :

plt.xlabel(' The calyx length of iris ', fontproperties = my_font)
# coding:utf-8
import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm, datasets # The following two lines address other common problems
plt.rcParams['font.sans-serif'] = ['SimHei'] # Specify default font
plt.rcParams['axes.unicode_minus'] = False # Resolve save image is negative '-' Questions displayed as squares import matplotlib.font_manager as mf # Import font manager
my_font= mf.FontProperties(fname='C:\\Windows\\Fonts\\msyh.ttf') # Load Fonts iris = datasets.load_iris()
X =[:, :2]
Y = def my_kernel(X, Y):
M = np.array([[2, 0], [0, 1.0]])
return, M), Y.T) h = 0.02 clf = svm.SVC(kernel = my_kernel), Y) x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()]) Z = Z.reshape(xx.shape)
plt.pcolormesh(xx, yy, Z, plt.scatter(X[:, 0], X[:, 1], c=Y,
plt.title(' test !!!3-Class classification using SVM with custom kernel',
fontproperties = my_font)

Windows Under the matplotlib Draw more articles about Chinese display settings

  1. ubuntu Next matplotlib Garbled Chinese in drawing

    Recently, I'm learning machine learning because of my thesis , I read a book called < Machine learning practice > The book of , It's good to see , Because there are both principles and examples . Today I use matplotlib When drawing , Find Chinese will be displayed as a small box , That's a real question ...

  2. Python 3 Next Matplotlib The solution of Chinese display garbled in drawing

    terms of settlement : Because random code is Matplotlib Due to the lack of Chinese configuration , So we just need to use Chinese font in the program . Choose a font first . Find the font on the computer , Choose a Chinese font , For example, I use regular script here Right click to view its genus ...

  3. Python stay Windows Lower installation matplotlib

    windows It's a lot of trouble to install under the computer , Use easy_install Installation error   Tip the lack of freetype and png After many inquiries , Final installation successful Here is the installation process If your Python The environment has been set up 1. Prerequisite needs ...

  4. Windows Next Python Chinese path and Chinese output problems in

    There is a project that needs to write a little bit of script like little program these days , Just use Python Yes , It involves Chinese path and Chinese output , Sort it out . There is a problem that I think needs to be emphasized first , Writing Python When it comes to programming , Make sure the code is utf-8, then ...

  5. Sphinx stay windows Lower installation and use [ Support Chinese full text retrieval ]

    Original address : front I tried to use it for a while Sphinx, One can be used in all kinds of languages (PHP/Python/ ...

  6. windows Next SVN Log feedback Chinese garbled solution

    from : TortoiseSVN The problem of garbled Chinese has been bothering me for a long time , Especially every time you use it “ Show changes in standard difference file ” when , Open text ...

  7. windows Next git bash According to Chinese

    1.C:\Program Files\Git\etc\git-completion.bash: alias ls='ls --show-control-chars --color=auto' explain : send ...

  8. Windows Next Oracle Don't show Chinese [ resolved ]

    Follow the video to learn , Then when it comes to insertion, there is Chinese gender , Just GG 了 , When it's time to display Chinese, it's always a question mark , I think it's a coding problem . So I went online to find , The test works , The method is as follows 1, Inquire about Oracle Coded statements : [sql] SELECT ...

  9. python windows Get the path under the Chinese processing

    stay windows of use os,path.abspath(__file__) When there is a Chinese path , The default is to turn to No unicode Format This can lead to , When other modules use this path , Will be submitted to the utf8' codec can't dec ...

Random recommendation

  1. 【Android】 Know which activity is currently

    First you need to create a new BaseActivity Inherited from Activity, And then in BaseActivity Rewriting in onCreate() Method , As shown below :public class BaseActivity e ...

  2. c++ - fcgio.cpp:50: error: 'EOF' was not declared in this scope - Stack Overflow

    c++ - fcgio.cpp:50: error: 'EOF' was not declared in this scope - Stack Overflow fcgio.cpp:50: error ...

  3. MATLAB Vertical search for white segments in images

    function [ top, bottom, middle, len ] = classify_by_vertical_white_belt( img ) % Vertical search for white segments in images , Record specific information . ...

  4. Beta Phase project review

    The reviewer : Wang Lihuan Six fingers magic skill : wt.dll: Six walnuts :http://w ...

  5. CMake vs Make contrast

    Programmers now use CMake and Make For a long time . When you join a big company or start a large code base development project , You need to deal with all these builds . You have to see this “CMakeLists.txt” File floating . You should run it on the terminal “cma ...

  6. Wechat public platform to create custom menu PHP Code

    Teaching a man to fish is better than giving him a fish . I asked in fangbei studio , How much is the code to create a custom menu , One mouth is a hundred , ok , Then I'll save you one hundred yuan , How do you say thank me ? Explain in advance , Yours PHP The version is higher than 4.0.2 To support cU ...

  7. webapi From entry to abandonment ( One )OWIN Self boarding mode

     1. establish web Empty item 2. After creation, as shown in the figure 3. Install the following packages Microsoft.AspNet.WebApi.Core (5.2.4)Microsoft.Owin.Host.SystemWeb (4.0. ...

  8. Magic Stones CodeForces - 1110E ( thinking + Difference )

    E. Magic Stones time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  9. BZOJ.3720.Gty My sister tree ( The trees are divided into blocks )

    Topic link Why was Luogu destroyed .. In addition, the tree partitioning algorithm is false . /* Insertion and deletion involve only one number , So you can enumerate it every time , Not after refactoring sort */ #include<cmath> #inclu ...

  10. The empire cms The number of logins limited by the system should not exceed 5 Please wait for the next time 60 You can log in again in minutes

    My friend's website is empire cms Built , He hasn't logged in for a long time and has forgotten his password , After login, it will prompt that the number of login times limited by the system should not exceed 5 Please wait for the next time 60 You can log in again in minutes , How to solve this problem ? In fact, just modify the configuration file : modify e/class ...