What are the common commands of Python drawing tool Matplotlib library
Editor to share with you what Python drawing tool Matplotlib library commonly used commands, I believe that most people do not know much, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Matplotlib official website
Matplotlib library defaults to English fonts
Add bold ('SimHei') to the drawing font
Code:
Plt.rcParams ['font.sans-serif'] = [' SimHei'] 1. Simple routine bar chart
Basic methods:
Matplotlib.pyplot.bar ()
Basic parameters:
Bar (XBI y)
Other parameters:
Color color
Width width
Transparency alpha
Other methods:
Legend legend ()
Horizontal axis definition xlable ()
Vertical axis definition ylable ()
Picture title title ()
Calibration methods xlim (), ylim ()
Import matplotlib.pyplot as plt # drawing import pandas as pd # read exal file plt.rcParams ['font.sans-serif'] = [' SimHei'] # add boldface as drawing font name = ['tom',' rose', 'lucy'] # variable name installs a list weight = [60, 70, 80] # with location attributes and numerical attributes plt.bar (name, weight, label=' weight', color='green', alpha=0.5 Width=0.5) # call method + legend + color + transparency + width plt.xlabel ('name') plt.ylabel ('weight unit kg') plt.title (' three people's weight xx') plt.legend () plt.savefig ('bar chart .png', dip=500) plt.show () # display method
two。 Read exal method 2.1Common data processing Library: pandas
A common way to read excel files with pandas: the read_excel () parameter is the file name
Import matplotlib.pyplot as plt # drawing import pandas as pd # read the exal file Data = pd.read_excel ('E:\ PythonData/LandingData.xlsx') print (Data)
Note that the file path does not start with a number, or an error will be reported.
E:\ PythonData/LandingData.xlsx
2.2 extract list array 3. The type and format of the picture of the paper
Bitmap (mosaic after magnification): .jpg .tif .psd .bmp .png
Vector graphics (magnified and clear): .wmf .emf .epd .cdx
Things photography uses bitmaps
The .png format is a non-extensible file type; .pdf is an extensible file format, and pdf is a vector graph.
4. Histogram extension 4.1 stacked histogram 4.2 decompose histogram 5. Python plots line chart coordinates cannot display minus signs
Just add the following code:
Import matplotlibmatplotlib.rcParams ['axes.unicode_minus'] = Falseplt.rcParams [' axes.unicode_minus'] = False6. Python axis displays the Chinese character plt.rcParams ['font.sans-serif'] = [' SimHei'] # add boldface as the drawing font all the contents of this article "what are the common commands in the Matplotlib library of Python drawing tools?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!