当前位置:网站首页>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
边栏推荐
- Problems of class in C # and database connection
- How can swagger2 custom parameter annotations not be displayed
- Charles 功能介绍和使用教程
- 使用zerotier让异地设备组局域网
- C language - custom type
- The courses bought at a high price are open! PHPer data sharing
- Jerry sometimes finds that the memory has been tampered with, but there is no exception. How should he find it? [chapter]
- Wonderful review | deepnova x iceberg meetup online "building a real-time data Lake based on iceberg"
- Six practices of Windows operating system security attack and defense
- Detailed explanation of MapReduce calculation process
猜你喜欢
Notes on concurrent programming of vegetables (IX) asynchronous IO to realize concurrent crawler acceleration
Example of pop-up task progress bar function based on pyqt5
Jerry's more accurate determination of abnormal address [chapter]
Initial exploration of NVIDIA's latest 3D reconstruction technology instant NGP
Intuitive understanding entropy
MapReduce compression
The courses bought at a high price are open! PHPer data sharing
精彩回顾|「源」来如此 第六期 - 开源经济与产业投资
Chapter 120 SQL function round
Source insight 4.0 FAQs
随机推荐
微信小程序中app.js文件、组件、api
Hikvision face to face summary
SQL Server recursive query of superior and subordinate
任意文件读取漏洞 利用指南
What about Jerry's stack overflow? [chapter]
Problems of class in C # and database connection
Solution architect's small bag - 5 types of architecture diagrams
997. Square of ordered array (array)
How to Ping Baidu development board
MapReduce compression
【leetcode】199.二叉树的右视图
部署jar包
SQL Server cursor circular table data
[provincial election joint examination 2022 d2t1] card (state compression DP, FWT convolution)
Xshell+Xftp 下载安装步骤
C#和数据库连接中类的问题
CentOS/Linux安装MySQL
一个微博数据库设计带来的简单思考
Learning Notes 6 - Summary of several deep learning convolutional neural networks
What are the system events of Jerry's [chapter]