当前位置:网站首页>Visualized common drawing (II) line chart
Visualized common drawing (II) line chart
2022-04-23 10:53:00 【The big pig of the little pig family】
Broken line diagram
One . Introduction to line chart (Line Chart)
Line chart is used to show the change of data in a continuous time interval or time span , Its characteristic is to reflect The tendency of things to change over time or ordered categories .
In the line chart, you can clearly see whether the data is increasing or decreasing 、 The rate of increase and decrease 、 The law of increase and decrease and the characteristics of peak value . Line charts are often used to analyze the trend of data over time , It can also be used to analyze the interaction and interaction of multiple groups of data over time . In a line chart, the horizontal axis is usually used to represent the time span and the time interval is the same , The vertical axis represents the data values at different times .
Two . Composition of line chart
The composition of a line chart includes :
- The horizontal axis : Time
- The vertical axis : Represents the value
- spot : Indicates the location of the data
- Line : Indicates the trend relationship between data
3、 ... and . Use scenarios
Applicable scenarios :
- Apply to Continuous independent variable , A scenario in which dependent variables are ordered .
Scenarios that are not applicable :
- When the data type of the horizontal axis is disordered classification or the data type of the vertical axis is continuous time , Line chart is not suitable .
Four . Realization
stay matplotlib Use in plot Method to realize line graph .plot The method is introduced as follows :
plot(args,scalex = True,scaley = True,data = None,** kwargs)
Parameters 1:x: Iteratable numeric type ( The length must be equal to Y equal ), Appoint x Axis data , Default range(len(y))
Parameters 2:y: Iteratable numeric type , Appoint y Axis data
Parameters 3:fmt : String type ( Optional ), Specifies the format string , The format is [marker][linestyle][color]
- marker: Specifies the marker point style
- linestyle: Specifies the polyline linearity
- color: Specify the line color
Parameters 4:scalex : bool type , ( Optional ), Default True, Appoint X Whether the view is applicable to data restrictions
Parameters 5:scalex: bool type , ( Optional ), Default True, Appoint Y Whether the view is applicable to data restrictions .
Parameters 6:data : Specify the data to be marked ( Optional )
Parameters 7:** kwargs: The accepted keyword parameters are passed to Line2D Class instance .
Return value : Plotting data Line2D Class instance list
notes :
- *args The variable parameters passed include x, y, fmt
- Line2D Class explanation
Implementation code :
import matplotlib.pyplot as plt
import numpy as np
x_data = np.array(['2011', '2012', '2013', '2014', '2015', '2016', '2017'])
y_data = np.array([58000, 60200, 63000, 71000, 84000, 90500, 107000])
y_data2 = np.array([52000, 54200, 51500, 58300, 56800, 59500, 62700])
# Initialize drawing frame
figure, ax = plt.subplots(1, 2)
# draw y_data
line1 = ax[0].plot(y_data, marker='o', lw=2, ls='--', markersize=6, markerfacecolor='r', label="line1")
ax[0].legend()
ax[0].set_xticks(range(len(y_data)))
ax[0].set_xticklabels(x_data)
ax[0].set_title("line1", fontsize=20, fontweight="bold")
ax[0].set_xlabel("year", fontsize=15)
ax[0].set_ylabel("amount", fontsize=15)
# draw y_data2
line2 = ax[1].plot(y_data2, marker='o', lw=2, ls='-', color='k', markersize=6, markerfacecolor='b', label="line2")
ax[1].legend()
ax[1].set_xticks(range(len(y_data)))
ax[1].set_xticklabels(x_data)
ax[1].set_title("line2", fontsize=20, fontweight="bold")
ax[1].set_xlabel("year", fontsize=15)
ax[1].set_ylabel("amount", fontsize=15)
plt.show()
The effect is as follows :

If you want to be more beautiful, you can make the following changes
ax[0].grid(True): Draw gridax[1].grid(True): Draw gridplt.style.use('ggplot'): Use ggplot style
The effect is as follows :

have access to text Mark the value of each marked point , The complete procedure is as follows :
# draw y_data
line1 = ax[0].plot(y_data, lw=2, color='k', label="line1", marker='o', markerfacecolor='g')
ax[0].legend()
ax[0].set_xticks(range(len(y_data)))
ax[0].set_xticklabels(x_data)
ax[0].set_title("line1", fontsize=20, fontweight="bold")
ax[0].set_xlabel("year", fontsize=15)
ax[0].set_ylabel("amount", fontsize=15)
ax[0].grid(True)
# Tag the data
for x_, y_ in zip(range(len(y_data)), y_data):
ax[0].text(x_, y_, y_, ha='left', va='top', color='red')
# draw y_data2
line2 = ax[1].plot(y_data2, lw=2, color='k', label="line2", marker='o', markerfacecolor='g')
ax[1].legend()
ax[1].set_xticks(range(len(y_data)))
ax[1].set_xticklabels(x_data)
ax[1].set_title("line2", fontsize=20, fontweight="bold")
ax[1].set_xlabel("year", fontsize=15)
ax[1].set_ylabel("amount", fontsize=15)
ax[1].grid(True)
# Tag the data
for x_, y_ in zip(range(len(y_data2)), y_data2):
ax[1].text(x_, y_, y_, ha='left', va='top', color="red")
plt.show()
The effect is as follows :

5、 ... and . Reference resources
版权声明
本文为[The big pig of the little pig family]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230617063490.html
边栏推荐
- 部署jar包
- 【leetcode】199.二叉树的右视图
- Jinglianwen technology - professional data annotation company and intelligent data annotation platform
- 24. Exchange the nodes in the linked list (linked list)
- Latex usage
- 206. Reverse linked list (linked list)
- Ueditor -- limitation of 4m size of image upload component
- UEditor之——图片上传组件大小4M的限制
- Yarn core parameter configuration
- SSH uses private key to connect to server without key
猜你喜欢

Notes on concurrent programming of vegetables (V) thread safety and lock solution

Intuitive understanding entropy

SQL Server cursor circular table data

景联文科技—专业数据标注公司和智能数据标注平台

Introduction to data analysis 𞓜 kaggle Titanic mission (IV) - > data cleaning and feature processing

Reading integrity monitoring techniques for vision navigation systems - 5 Results
![Jerry's more accurate determination of abnormal address [chapter]](/img/ed/a08949bfc63823baf25fd57c324996.png)
Jerry's more accurate determination of abnormal address [chapter]

Introduction to wechat applet, development history, advantages of applet, application account, development tools, initial knowledge of wxml file and wxss file

Download and installation steps of xshell + xftp

Example of pop-up task progress bar function based on pyqt5
随机推荐
【leetcode】102.二叉树的层序遍历
Learning notes 7-depth neural network optimization
第六站神京门户-------手机号码的转换
19. Delete the penultimate node of the linked list (linked list)
349、两个数组的交集
Notes on concurrent programming of vegetables (V) thread safety and lock solution
Let the LAN group use the remote device
Latex usage
SQL Server cursor circular table data
Example of pop-up task progress bar function based on pyqt5
SSH uses private key to connect to server without key
Deploy jar package
Installing MySQL with CentOS / Linux
Cve-2019-0708 vulnerability exploitation of secondary vocational network security 2022 national competition
MapReduce core and foundation demo
得到知识服务app原型设计比较与实践
App. In wechat applet JS files, components, APIs
How can swagger2 custom parameter annotations not be displayed
SQLServer 查询数据库死锁
Comparison and practice of prototype design of knowledge service app