当前位置:网站首页>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
边栏推荐
- Jerry sometimes finds that the memory has been tampered with, but there is no exception. How should he find it? [chapter]
- 349. Intersection of two arrays
- Understand the key points of complement
- VScode
- 24. Exchange the nodes in the linked list (linked list)
- Esp32 learning - add folder to project
- Pycharm
- 242、有效字母异位词(哈希表)
- Charles 功能介绍和使用教程
- MapReduce core and foundation demo
猜你喜欢
MySQL how to merge the same data in the same table
Learning note 5 - gradient explosion and gradient disappearance (k-fold cross verification)
【leetcode】102. Sequence traversal of binary tree
精彩回顾 | DEEPNOVA x Iceberg Meetup Online《基于Iceberg打造实时数据湖》
C language - custom type
Learning Notes 6 - Summary of several deep learning convolutional neural networks
【leetcode】199. Right view of binary tree
Diary of dishes | Blue Bridge Cup - hexadecimal to octal (hand torn version) with hexadecimal conversion notes
SSH利用私钥无密钥连接服务器踩坑实录
【leetcode】107.二叉树的层序遍历II
随机推荐
19. Delete the penultimate node of the linked list (linked list)
Intuitive understanding entropy
得到知识服务app原型设计比较与实践
Problems of class in C # and database connection
142、环形链表||
MapReduce core and foundation demo
解决方案架构师的小锦囊 - 架构图的 5 种类型
Resolution and size of mainstream mobile phones
Kaggle - real battle of house price prediction
VIM usage
图像处理——噪声小记
Download and installation steps of xshell + xftp
202. Happy number
Wonderful review | deepnova x iceberg meetup online "building a real-time data Lake based on iceberg"
Is the pointer symbol of C language close to variable type or variable name?
Six practices of Windows operating system security attack and defense
net start mysql MySQL 服务正在启动 . MySQL 服务无法启动。 服务没有报告任何错误。
Solution architect's small bag - 5 types of architecture diagrams
Chapter 120 SQL function round
Jerry sometimes finds that the memory has been tampered with, but there is no exception. How should he find it? [chapter]