当前位置:网站首页>[Matplotlib drawing]
[Matplotlib drawing]
2022-07-24 21:24:00 【lxw-pro】
Catalog ~python
Personal Nickname :lxw-pro
Personal home page : Welcome to your attention My home page
Personal perception : “ Failure is the mother of success ”, This is the same truth , Sum up in failure , Grow in failure , To be IT A generation of masters in the world .
Matplotlib Study ( To continue )
Python expanded memory bank Matplotlib Depends on the extension library NumPy And the standard library Tkinter,
You can draw a variety of shapes , Include Broken line diagram 、 Scatter plot 、 The pie chart 、 Histogram 、 Radar map wait .
Python expanded memory bank Matplotlib Include pylab、pyplot And other drawing modules, as well as a large number of fonts 、 Color 、 Legend and other graphic elements of the management and control module . among pylab and pyplot The module provides information similar to MATLAB Drawing interface for , Support line style 、 Font properties 、 Management and control of axis attributes and other attributes , You can use very simple code to draw beautiful patterns .
Use
pylaborpyplotThe general process of drawing :
- Read in the data
- Draw a line chart according to actual needs 、 Scatter plot 、 Histogram 、 Radar chart or three-dimensional curve and surface
- Next, set the axis and image properties
- Display or save drawing results
Broken line diagram
# Broken line diagram
import pandas as pd
import pylab as plt
plt.rc('font', family='SimHei') # Used to display Chinese labels normally
plt.rc('font', size=20) # Set the display font size
# ditto
# plt.rcParams['font.sans-serif'] = ['SimHei']
# plt.rcParams['axes.unicode_minus'] = False
lxw = pd.read_excel('data2.xlsx', header=None)
tsj = lxw.values # Extract the data from it
# print(tsj)
x = tsj[0] # Extract the data in the first row
y = tsj[1:] # Extract data except the first row
plt.plot(x, y[0], '-*b', label=' water consumption ')
plt.plot(x, y[1], '--pr', label=' Electricity consumption ')
plt.xlabel(' month ')
plt.ylabel(' Monthly dosage ')
plt.legend(loc='upper left')
plt.grid()
plt.show()
Relevant operation effects are as follows :

Histogram
# Histogram
import pandas as pd
import pylab as plt
# Used to display Chinese labels normally
plt.rc('font', family='SimHei')
plt.rc('font', size=20)
lxw2 = pd.read_excel('data2.xlsx', header=None)
sz = lxw2.T
sz.plot(kind='bar')
plt.legend([' water consumption ', ' Electricity consumption '])
plt.xticks(range(6), sz[0], rotation=0)
plt.ylabel(' The dosage ')
plt.show()
Relevant operation effects are as follows :

Subgraphs
# Subgraphs
import numpy as np
import pylab as plt
# plt.rc('text', usetex=True)
y1 = np.random.randint(2, 6, 6)
y1 = y1/sum(y1)
plt.subplot(2, 2, 1)
su = ['Python', 'Java', 'MySQL', 'C', 'Math', 'English']
plt.barh(su, y1)
plt.subplot(222)
plt.pie(y1, labels=su)
plt.subplot(212)
x2 = np.linspace(0.01, 10, 100)
y2 = np.sin(10*x2)/x2
plt.plot(x2, y2)
plt.xlabel('$x$')
plt.ylabel('$\\mathrm{sin}(10x)/x$')
plt.show()
Relevant operation effects are as follows :

——————————————————————————————————————————
Three dimensional curve
# Three dimensional curve
import pylab as plt
import numpy as np
swx = plt.axes(projection='3d')
z = np.linspace(-50, 50, 1000)
x = z ** 2 * np.sin(z)
y = z ** 2 * np.cos(z)
swx.plot(x, y, z, 'b')
plt.show()
Relevant operation effects are as follows :

Three dimensional surface maps
# Three dimensional surface maps
import pylab as plt
import numpy as np
swt = plt.axes(projection='3d')
x = np.linspace(-5, 5, 100)
x, y = np.meshgrid(x, x)
z = 50 * np.sin(x+y)
swt.plot_surface(x, y, z, color='r')
plt.show()
Relevant operation effects are as follows :

Three dimensional surface drawing
# Three dimensional surface drawing
import pylab as plt
import numpy as np
swb = plt.axes(projection='3d')
x = np.arange(-8, 8, 0.25)
y = np.arange(-8, 8, 0.25)
x, y = np.meshgrid(x, y)
z = np.sin(np.sqrt(x**2+y**2))
tx = swb.plot_surface(x, y, z, cmap='coolwarm')
plt.colorbar(tx)
plt.show()
Relevant operation effects are as follows :

A word a day :
Life is like this , Feet grow on oneself , Just go ahead , Until the yearning scenery , Become a place to walk !
Ongoing update …
give the thumbs-up , Your recognition is my creation
power!
Collection , Your favor is my effortDirection!
Comment on , Your opinion is my progressWealth!
Focus on , Your love is my lastinginsist!
Welcome to your attention WeChat official account 【 Programmed life 6】, Discuss and study together !!!
边栏推荐
- A very useful log4net logging library
- Use of cache in C #
- Node installation using NVM succeeded, but NPM installation failed (error while downloading, TLS handshake timeout)
- Leetcode skimming -- bit by bit record 017
- Overloaded & lt; for cv:: point;, But VS2010 cannot find it
- Go language error handling
- ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘localhost:3306‘ (10061)
- Failed to create a concurrent index, leaving an invalid index. How to find it
- Defects of matrix initialization
- Using skills and design scheme of redis cache (classic collection version)
猜你喜欢

Generate self signed certificate: generate certificate and secret key

npm Warn config global `--global`, `--local` are deprecated. Use `--location=global` instead

Preview and save pictures using uni app

Using skills and design scheme of redis cache (classic collection version)
![[advanced data mining technology] Introduction to advanced data mining technology](/img/93/cb5ee07bff50662ad2496ca2bb39da.png)
[advanced data mining technology] Introduction to advanced data mining technology

【MLFP】《Face Presentation Attack with Latex Masks in Multispectral Videos》

Native applets are introduced using vant webapp

Go language structure

Five digital transformation strategies of B2B Enterprises

Opencv learning Day2
随机推荐
Scientific computing toolkit SciPy image processing
90% of people don't know the most underestimated function of postman!
How to buy Xinke financial products in CICC securities? Revenue 6%
Preview and save pictures using uni app
About the acid of MySQL, there are thirty rounds of skirmishes with mvcc and interviewers
250 million, Banan District perception system data collection, background analysis, Xueliang engineering network and operation and maintenance service project: Chinatelecom won the bid
Penetration test - command execution injection
Detailed OSPF configuration of layer 3 switch / router [Huawei ENSP experiment]
C WinForm actual operation XML code, including the demonstration of creating, saving, querying and deleting forms
Do you want to verify and use the database in the interface test
Application layer - typical protocol analysis
Go language pack management
One bite of Stream(7)
Acwing 94. recursive implementation of permutation enumeration
Codeforces Round #808 (Div. 2)(A~D)
[untitled]
Lenovo Filez helps Zhongshui North achieve safe and efficient file management
Smarter! Airiot accelerates the upgrading of energy conservation and emission reduction in the coal industry
Scientific computing toolkit SciPy Fourier transform
How to choose securities companies that support flush? Is it safe to open an account on your mobile phone
