当前位置:网站首页>Visual common drawing (I) stacking diagram
Visual common drawing (I) stacking diagram
2022-04-23 10:53:00 【The big pig of the little pig family】
One . stacked column chart (Stacked Bar Chart)
1.1 Definition
Stacked histogram can vividly show the data of each small category contained in a large category , And the proportion of each sub category , It shows the relationship between a single project and the whole . There are two types of stacked histograms :
- General stacked histogram : The values on each column represent different data sizes , The sum of the data of each floor represents the height of the whole column . It is very suitable for comparing the total amount of data in each group .
- Stacked histogram of percentage : Each layer of the column represents the percentage of the category data in the overall data of the group .
1.2 Use scenarios
Applicable scenario :
- Apply to need Compare the total size of different groups , At the same time, compare the size of different classifications in the same group .
Not applicable to the scene :
- Compare the data size of the same category in different groups ( Percentage stacked histogram )
- Compare the size of the total number of groups ( Backup is better than stacking histogram )
1.3 Realization
stay matplotlib Use in bar Function to implement , Appoint bottom Stack parameters , The code is as follows :
import numpy as np
import matplotlib.pyplot as plt
# Data set used
year = [1950, 1960, 1970, 1980, 1990, 2000, 2010, 2018]
population_by_continent = {
'africa': [228, 284, 365, 477, 631, 814, 1044, 1275],
'americas': [340, 425, 519, 619, 727, 840, 943, 1006],
'asia': [1394, 1686, 2120, 2625, 3202, 3714, 4169, 4560],
'europe': [220, 253, 276, 295, 310, 303, 294, 293],
'oceania': [12, 15, 19, 22, 26, 31, 36, 39],
}
# initialization figure and axes
fig, ax = plt.subplots()
sum = np.zeros((1, len(year))).reshape(-1)
# mapping
for i in population_by_continent:
ax.bar(year, population_by_continent.get(i), label=i, alpha=0.8, bottom=sum, width=5)
sum += population_by_continent.get(i)
# Add legend and title
ax.legend(loc='upper left')
ax.set_title('World population')
ax.set_xlabel('Year')
ax.set_ylabel('Number of people (millions)')
plt.show()
The effect is as follows :

Two . Stacking area map (Stacked Area Chart)
2.1 Definition
Stacked area map draws multiple data sets as vertically stacked areas . The stacked area map is the same as the basic area map , The only difference is that the starting point of each data set on the graph is different , The starting point is based on the previous dataset , Used to display the trend line of the proportion of each value over time or category , It shows the relationship between part and whole .
The largest area on the stacked area graph represents the sum of all data volumes , It's a whole . Each stacked area represents the size of each data volume , These stacked area maps are particularly useful in showing the changes of the total component of big data .
Based on the stacked area map , The data of the dependent variables of each area are normalized by the total amount after addition to form a percentage stacked area map . The chart does not reflect the change of the total amount , But you can clearly
2.2 Use scenarios
Applicable scenario :
- Applicable to trend lines that need to reflect the percentage of each value over time or category , For analysis, the independent variable is time-varying data 、 The proportion of each index component is very useful when using ordered data .
- It is suitable for comparing multivariable changes over time .
Not applicable to the scene :
- Not applicable with negative Data set of .
2.3 Realization
Use stackplots Realize the stacking area diagram ,stackplots The function parameters are as follows :
effect : Draw stacking area map
stackplot(x, *args, labels=(), colors=None, baseline='zero', data=None, **kwargs)
Parameters 1:x: ( N , ) (N,) (N,) Array , Specify the horizontal axis .
Parameters 2:*args,y: ( N , M ) (N,M) (N,M) Array , Specify the data to plot .
Parameters 3:labels: String list : Specify the label for each drawing data .
Parameters 4:colors: Color list : Specifies the shading of the stacked area , Not necessarily with y Same end , Colors will be recycled .
Parameters 5:baseline: Qualified string : Specify the method of calculating the baseline , Optional :
zero: Constant zero baseline , A simple stacked graph .sym: Symmetry around zerowiggle: Minimize the sum of the square slopes .weighted_wiggle: Weighted , The weight accounts for the size of each layer
Parameters 6:data: Unknown
Parameters 7:**kwargs: The received keyword parameters are passed to fill_between Method .
import numpy as np
import matplotlib.pyplot as plt
year = [1950, 1960, 1970, 1980, 1990, 2000, 2010, 2018]
population_by_continent = {
'africa': [228, 284, 365, 477, 631, 814, 1044, 1275],
'americas': [340, 425, 519, 619, 727, 840, 943, 1006],
'asia': [1394, 1686, 2120, 2625, 3202, 3714, 4169, 4560],
'europe': [220, 253, 276, 295, 310, 303, 294, 293],
'oceania': [12, 15, 19, 22, 26, 31, 36, 39],
}
fig, ax = plt.subplots()
ax.stackplot(year, population_by_continent.values(),
labels=population_by_continent.keys(), alpha=0.8)
ax.legend(loc='upper left')
ax.set_title('World population')
ax.set_xlabel('Year')
ax.set_ylabel('Number of people (millions)')
plt.show()
The effect is as follows :

版权声明
本文为[The big pig of the little pig family]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230617063572.html
边栏推荐
- Detailed explanation of MapReduce calculation process
- STM32接电机驱动,杜邦线供电,然后反烧问题
- Leetcode22: bracket generation
- colab
- What if Jerry's function to locate the corresponding address is not accurate sometimes? [chapter]
- Is the pointer symbol of C language close to variable type or variable name?
- Reading integrity monitoring techniques for vision navigation systems - 5 Results
- 24. Exchange the nodes in the linked list (linked list)
- Learning notes 7-depth neural network optimization
- Chapter 120 SQL function round
猜你喜欢

Charles 功能介绍和使用教程

ID number verification system based on visual structure - Raspberry implementation

SQL Server 递归查询上下级

Yarn core parameter configuration

SQL Server recursive query of superior and subordinate

C language - custom type

Swagger2 自定义参数注解如何不显示

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

Jinglianwen technology - professional data annotation company and intelligent data annotation platform

mysql同一个表中相同数据怎么合并
随机推荐
解决方案架构师的小锦囊 - 架构图的 5 种类型
Problems of class in C # and database connection
Introduction to data analysis 𞓜 kaggle Titanic mission (III) - > explore data analysis
SQLServer 查询数据库死锁
Derivation and regularization
部署jar包
Deploy jar package
SWAT—Samba WEB管理工具介绍
Learning notes 7-depth neural network optimization
解决方案架构师的小锦囊 - 架构图的 5 种类型
定义链表(链表)
19、删除链表的倒数第N个节点(链表)
203. Remove linked list elements (linked list)
Swagger2 接口如何导入Postman
STM32接电机驱动,杜邦线供电,然后反烧问题
Understand the key points of complement
Linked list intersection (linked list)
What about Jerry's stack overflow? [chapter]
MySQL how to merge the same data in the same table
The courses bought at a high price are open! PHPer data sharing