


python matplotlib Chinese display parameter setting analysis_python
This article mainly introduces the analysis of Chinese display parameter settings of python matplotlib, which has certain reference value. Friends who are interested in python can refer to it.
Recently, when I was learning Python's famous Drawing package matplotlib, I found that sometimes legends and other settings could not display Chinese properly, so I wanted to solve this problem.
PS: This article is only for Windows, other platforms are for reference only.
The reason
is roughly that there are no Chinese fonts in the matplotlib library.
I installed anaconda, which is the folder where the corresponding matplotlib font is located (how to find the matplotlibconfig file folder, the solution will be described below, easyman~).
C:\Anaconda64\Lib\site-packages\matplotlib\mpl-data\fonts\ttf
Solution
Now to sort me out I think a better solution is:
Set parameters every time you write code
#coding:utf-8 import matplotlib.pyplot as plt plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签 plt.rcParams['axes.unicode_minus']=False #用来正常显示负号 #有中文出现的情况,需要u'内容'
Once and for all (recommended)
import matplotlib matplotlib.matplotlib_fname() #将会获得matplotlib包所在文件夹
Then enter C:\Anaconda64\Lib\site-packages\matplotlib\mpl-data and you can see it in this folder to the matplotlibrc configuration file.
1) Open the configuration file and find the following line:
#font.serif : Bitstream Vera Serif, New Century Schoolbook, Century Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L, Times New Roman, Times, Palatino, Charter, serif
Then change the preceding NoteRemove!
2) Find Chinese fonts and put them in the matplotlib font library.
Copy the font under the Windows folder: C:\Windows\Fonts\MicrosoftYaHeiUI, and then paste it into the C:\Anaconda64\Lib\site-packages\matplotlib\mpl-data\fonts\ttf folder, And rename it Vera.ttf.
Note: The function of this step is actually to replace a default font in matplotlib with the Chinese font we copied, and change the Chinese font name to the font name in matplotlib.
Actually, there are other solutions, but they seem to have failed in my case.
Supplement
The negative sign of the coordinate axis is displayed normally
#去掉了注释符号,同时,改为False axes.unicode_minus : False
Example
#coding:utf-8 import matplotlib.pyplot as plt plt.plot((1,2,3),(4,3,-1)) plt.xlabel(u'横坐标') plt.ylabel(u'纵坐标') plt.show()
##Summary
Above This is the entire content of this article about the analysis of Chinese display parameter settings of python matplotlib. I hope it will be helpful to everyone. Interested friends can continue to refer to this site:Related recommendations:
Use regular expressions in python Example code of formula connector
Python implementation of outputting colored string case analysis
Python implementation of genetic algorithm code
The above is the detailed content of python matplotlib Chinese display parameter setting analysis_python. For more information, please follow other related articles on the PHP Chinese website!

The reasons why Python scripts cannot run on Unix systems include: 1) Insufficient permissions, using chmod xyour_script.py to grant execution permissions; 2) Shebang line is incorrect or missing, you should use #!/usr/bin/envpython; 3) The environment variables are not set properly, and you can print os.environ debugging; 4) Using the wrong Python version, you can specify the version on the Shebang line or the command line; 5) Dependency problems, using virtual environment to isolate dependencies; 6) Syntax errors, using python-mpy_compileyour_script.py to detect.

Using Python arrays is more suitable for processing large amounts of numerical data than lists. 1) Arrays save more memory, 2) Arrays are faster to operate by numerical values, 3) Arrays force type consistency, 4) Arrays are compatible with C arrays, but are not as flexible and convenient as lists.

Listsare Better ForeflexibilityandMixdatatatypes, Whilearraysares Superior Sumerical Computation Sand Larged Datasets.1) Unselable List Xibility, MixedDatatypes, andfrequent elementchanges.2) Usarray's sensory -sensical operations, Largedatasets, AndwhenMemoryEfficiency

NumPymanagesmemoryforlargearraysefficientlyusingviews,copies,andmemory-mappedfiles.1)Viewsallowslicingwithoutcopying,directlymodifyingtheoriginalarray.2)Copiescanbecreatedwiththecopy()methodforpreservingdata.3)Memory-mappedfileshandlemassivedatasetsb

ListsinPythondonotrequireimportingamodule,whilearraysfromthearraymoduledoneedanimport.1)Listsarebuilt-in,versatile,andcanholdmixeddatatypes.2)Arraysaremorememory-efficientfornumericdatabutlessflexible,requiringallelementstobeofthesametype.

Pythonlistscanstoreanydatatype,arraymodulearraysstoreonetype,andNumPyarraysarefornumericalcomputations.1)Listsareversatilebutlessmemory-efficient.2)Arraymodulearraysarememory-efficientforhomogeneousdata.3)NumPyarraysareoptimizedforperformanceinscient

WhenyouattempttostoreavalueofthewrongdatatypeinaPythonarray,you'llencounteraTypeError.Thisisduetothearraymodule'sstricttypeenforcement,whichrequiresallelementstobeofthesametypeasspecifiedbythetypecode.Forperformancereasons,arraysaremoreefficientthanl

Pythonlistsarepartofthestandardlibrary,whilearraysarenot.Listsarebuilt-in,versatile,andusedforstoringcollections,whereasarraysareprovidedbythearraymoduleandlesscommonlyusedduetolimitedfunctionality.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Zend Studio 13.0.1
Powerful PHP integrated development environment
