Python Data Visualization - The Post-2000 Gaokao Generation
The post-2000 generation has finished their Gaokao (National College Entrance Examination), and there’s been extensive media coverage (they are the “fresh meat” generation, after all!). Many reports focused on this year’s examinee data, presenting it with stunning charts. Feeling a bit jealous about how beautiful those charts are? Do you want to try making one yourself? These charts are actually products of data visualization created with Python, so yes, you can definitely make them yourself!
Preparation
-
Libraries
charts
pyecharts
-
Data
- Collected directly from Baidu.
Common Chart Types
Bar charts and line charts are frequently seen and used, so let’s start with the basics.
1. Bar Chart
# Number of Gaokao examinees
gaokao_num = [940,940,...,375]
gaokao_num.reverse()
# Number of admitted students
luqu_num = [700,705,...,221]
luqu_num.reverse()
# Admission rate
luqu_lev= [74.46,75,...,59]
luqu_lev.reverse()
import charts
options = {
'chart' : {'zoomType':'xy'},
# Title
'title' : {'text': '2000-2017 Gaokao Data'},
# Subtitle
'subtitle': {'text': 'Source: edu.sina.com.cn'},
# X-axis
'xAxis' : {'categories': ['2000',...,'2017']},
# Y-axis
'yAxis' : {'title': {'text': 'Million people/year'}},
}
series = [{
'type': 'column',
'name': 'Number of Gaokao Examinees',
'data': gaokao_num
},{
'type': 'column',
'name': 'Number of Admitted Students',
'data': luqu_num
}
]
charts.plot(series, options=options, show='inline')
Due to a minor issue with my pyecharts
setup, I used the charts
library. Using pyecharts
is even simpler, but I won’t repeat it here. You can check the source code if needed.