当前位置:网站首页>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
边栏推荐
- 图像处理——噪声小记
- Resolution and size of mainstream mobile phones
- 209. Subarray with the smallest length (array)
- Read integrity monitoring techniques for vision navigation systems
- 142. Circular linked list||
- SQL Server 游标循环表数据
- Problems of class in C # and database connection
- MySQL how to merge the same data in the same table
- 【leetcode】199. Right view of binary tree
- Windows installs redis and sets the redis service to start automatically
猜你喜欢

UEditor之——图片上传组件大小4M的限制

Deploy jar package

Ueditor -- limitation of 4m size of image upload component

微信小程序简介、发展史、小程序的优点、申请账号、开发工具、初识wxml文件和wxss文件

net start mysql MySQL 服务正在启动 . MySQL 服务无法启动。 服务没有报告任何错误。

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

解决方案架构师的小锦囊 - 架构图的 5 种类型

高价买来的课程,公开了!phper资料分享

Idea - indexing or scanning files to index every time you start
![Jerry's more accurate determination of abnormal address [chapter]](/img/ed/a08949bfc63823baf25fd57c324996.png)
Jerry's more accurate determination of abnormal address [chapter]
随机推荐
Idea - indexing or scanning files to index every time you start
Construction and traversal of binary tree
Anaconda3 installation
Linked list intersection (linked list)
Learning notes 7-depth neural network optimization
mysql同一个表中相同数据怎么合并
Read integrity monitoring techniques for vision navigation systems
解决方案架构师的小锦囊 - 架构图的 5 种类型
UDP basic learning
142、环形链表||
Esp32 learning - add folder to project
Define linked list (linked list)
使用zerotier让异地设备组局域网
A diary of dishes | 238 Product of arrays other than itself
Comparison and practice of prototype design of knowledge service app
Deploy jar package
Strongest date regular expression
CentOS/Linux安装MySQL
Full stack cross compilation x86 completion process experience sharing
Swagger2 自定义参数注解如何不显示