Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common commands of Python drawing tool Matplotlib library

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report