程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python data visualization Matplotlib drawing line graph example

編輯:Python

Catalog

plt.plot() Analysis of function parameters

The specific meaning of each parameter is :

x,y

color

linestyle

linewidth

marker

About marker Parameters of

plt.plot() Analysis of function parameters

plt.plot() The line graph() function draws a line graph , It has many parameters , Common function parameters are as follows :

plt.plot(x,y,color,linestyle,linewidth,marker,markersize,markerfacecolor,markeredgewidth,markeredgecolor) The specific meaning of each parameter is :x,y

x,y Namely X Axis data and Y Axis of the data , Their types can be tuples , list ,numpy Library array Object or pandas Library series object , These two libraries will be explained later , This section uses lists to create data .

color

The color of the line , Usually write the English name of the color directly ( Use a pair of single quotation marks ) Or 16 system .python The English name of the recognizable color is shown in the figure below :

linestyle

Style or style of line , The following styles are commonly used ,

'-': Solid line

'--' : Broken line

'-.' : Point line

':' : Dotted line

linewidth

The width of the polyline , The greater the numerical , The thicker the lines .

marker

The sign , That is, the display style of each data point in the coordinate system , Commonly used :

About marker Parameters of

markersize: Mark the size of the symbol .

markerfacecolor: The color of the marking symbol .

markeredgewidth: The width of the edge of the marker symbol .

markeredgecolor: The edge color of the marking symbol .

import matplotlib.pyplot as plt plt.rcParams['font.family']=['SimHei']plt.figure(figsize=(7,7)) # Setting the graph size is a 7*7 The square of month=['1 month ','2 month ','3 month ','4 month ','5 month ','6 month ']telephone=[100,90,105,110,85,120] # Mobile phone charges water=[10,9,20,30,25,18] # charge for water food=[500,600,500,480,400,660] # Food expenses other=[200,420,300,380,320,280] # Other expenses plt.plot(month,telephone,label=' The phone ',color='y',linestyle=':',marker='v')plt.plot(month,water,'go-',label=' charge for water ')#'go-' Is the abbreviation of three parameters ,g yes color Value , namely green,o yes marker Value , That is, the solid mark ,- yes linestyle Value , Solid line plt.plot(month,food,label=' Food expenses ',linestyle='--',marker='+',markersize=20,markerfacecolor='black',markeredgewidth=5,markeredgecolor='red')plt.plot(month,other,label=' Other ',linestyle='-.',marker='D')plt.legend() # Show Legend plt.grid(ls='--',alpha=0.4) # Show grid plt.title(' Trend chart of various expenses in the first half of the year ') # Set chart title plt.xlabel(' month ') #X Axis title plt.ylabel(' amount of money ') #y Axis title plt.show()

Use plt.plot() Function when drawing a line graph , except X Axis data and Y Axis data is necessary , Other parameters are optional , For example, color. , If not set ,python The compiler will automatically help you set the colors of the four lines to be inconsistent . So we can select the parameters to be set according to the actual needs .

That's all python Data visualization matplotlib Draw the details of the line chart example , More about python matplotlib Please pay attention to other related articles of software development network for the information of drawing line chart !



  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved