欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

第七次全国人口普查 | Pyecharts】数据可视化~

最编程 2024-03-21 10:49:12
...
chart = Map3D(init_opts=opts.InitOpts(
width='1000px',
height='600px',
theme='dark',
bg_color='#000')
)

# 引用添加的地图
chart.add_schema(
maptype="china",
ground_color='#999',
shading="lambert",
emphasis_label_opts=opts.LabelOpts(is_show=True),
itemstyle_opts=opts.ItemStyleOpts(
border_width=0.2,
border_color="rgb(0,0,0)",
),
light_opts=opts.Map3DLightOpts(
main_shadow_quality='high',
is_main_shadow=True,
main_intensity=1,
main_alpha=30,
ambient_cubemap_texture='https://echarts.apache.org/examples/data-gl/asset/canyon.hdr',
ambient_cubemap_diffuse_intensity=0.5,
ambient_cubemap_specular_intensity=0.5
),
post_effect_opts=opts.Map3DPostEffectOpts(
is_enable=True,
is_ssao_enable=True,
ssao_radius=1,
ssao_intensity=1
)
)
chart.add(
"GDP",
data_pair=data_pair,
type_="bar3D",
bar_size=1.5,
min_height=3,
shading="lambert",
label_opts=opts.LabelOpts(
is_show=False,
formatter=JsCode(
"function(data){return data.name + ': ' + data.value[2];}"),
)
)
chart.set_global_opts(
visualmap_opts=opts.VisualMapOpts(
is_show=False,
type_='color',
dimension=2,
min_=1e7,
max_=1e8,
range_color=[
'#313695',
'#4575b4',
'#74add1',
'#abd9e9',
'#e0f3f8',
'#ffffbf',
'#fee090',
'#fdae61',
'#f46d43',
'#d73027',
'#a50026']
),
title_opts=opts.TitleOpts(
title="全国各省人口统计",
subtitle='数据来自全国第七次人口普查数据,未包含港澳台地区。',
pos_left="2%",
pos_top='1%',
title_textstyle_opts=opts.TextStyleOpts(color='#00BFFF', font_size=20)
),
tooltip_opts=opts.TooltipOpts(is_show=False),
legend_opts=opts.LegendOpts(is_show=False),
graphic_opts=[
opts.GraphicGroup(
graphic_item=opts.GraphicItem(id_='1', left="100px", bottom="100px"),
children=[
opts.GraphicRect(
graphic_item=opts.GraphicItem(
left="center", top="center", z=1
),
graphic_shape_opts=opts.GraphicShapeOpts(
width=200, height=80
),
graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
# 颜色配置,这里设置为黑色,透明度为0.5
fill="rgba(0,0,0,0.5)",
line_width=4,
stroke="#fff",
),
),
opts.GraphicText(
graphic_item=opts.GraphicItem(
left="center", top="center", z=100
),
graphic_textstyle_opts=opts.GraphicTextStyleOpts(
# 要显示的文本
text='全国人口:{:,}\n\n现役军人:{:,}'.format(int(total), int(soldier)),
font="bold italic 14px Microsoft YaHei",
graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
fill="#fff"
),
),
)
],
),

]
)


pie = Pie(
init_opts=opts.InitOpts(
theme='dark',
width='1000px',
height='400px',
bg_color='rgb(0,0,0)')
)
pie.add(
"",
data_pair_age,
# 指定饼图中心位置
center=["20%", "35%"],
# 将饼图尺寸相应缩小,不然饼图会重叠
radius=["15%", "25%"],
label_opts=opts.LabelOpts(formatter='{b}\n{c}%')
)

pie.add(
"",
data_pair_sex,
# 指定饼图中心位置
center=["50%", "35%"],
# 将饼图尺寸相应缩小,不然饼图会重叠
radius=["15%", "25%"],
label_opts=opts.LabelOpts(formatter='{b}\n{c}%')
)

pie.add(
"",
data_pair_edu,
# 指定饼图中心位置
center=["80%", "35%"],
# 将饼图尺寸相应缩小,不然饼图会重叠
radius=["15%", "25%"],
label_opts=opts.LabelOpts(formatter='{b}\n{c}%')
)

pie.add(
"",
[('城镇', 63.89), ('农村', 36.11)],
# 指定饼图中心位置
center=["20%", "70%"],
# 将饼图尺寸相应缩小,不然饼图会重叠
radius=["15%", "25%"],
label_opts=opts.LabelOpts(formatter='{b}\n{c}%')
)

pie.add(
"",
[('汉族', 91.11), ('少数民族', 8.89)],
# 指定饼图中心位置
center=["50%", "70%"],
# 将饼图尺寸相应缩小,不然饼图会重叠
radius=["15%", "25%"],
label_opts=opts.LabelOpts(formatter='{b}\n{c}%')
)

pie.add(
"",
[('流动人口', 26.62), ('非流动人口', 73.38)],
# 指定饼图中心位置
center=["80%", "70%"],
# 将饼图尺寸相应缩小,不然饼图会重叠
radius=["15%", "25%"],
label_opts=opts.LabelOpts(formatter='{b}\n{c}%')
)

pie.set_global_opts(
legend_opts=opts.LegendOpts(is_show=False),
title_opts=[dict(text='人口画像', left='2%', top='1%', textStyle=dict(color='#00BFFF', fontSize=20)),
dict(
text='年龄 ',
left='20%',
top='32%',
textAlign='center',
textStyle=dict(
color='#fff',
fontWeight='normal',
fontSize=15)),
dict(
text='性别 ',
left='50%',
top='32%',
textAlign='center',
textStyle=dict(
color='#fff',
fontWeight='normal',
fontSize=15)),
dict(text='教育 ', left='80%', top='32%', textAlign='center', textStyle=dict(color='#fff', fontWeight='normal', fontSize=15)),
dict(text='户籍 ', left='20%', top='67%', textAlign='center', textStyle=dict(color='#fff', fontWeight='normal', fontSize=15)),
dict(text='民族 ', left='50%', top='67%', textAlign='center', textStyle=dict(color='#fff', fontWeight='normal', fontSize=15)),
dict(text='流动 ', left='80%', top='67%', textAlign='center', textStyle=dict(color='#fff', fontWeight='normal', fontSize=15))
],
graphic_opts=[
opts.GraphicGroup(
graphic_item=opts.GraphicItem(
id_='2', left="center", top="40px"),
children=[
opts.GraphicRect(
graphic_item=opts.GraphicItem(
left="center", top="center", z=1
),
graphic_shape_opts=opts.GraphicShapeOpts(
width=950, height=320
),
graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
fill="rgba(0,0,0,0)",
line_width=5,
stroke="#fff",
),
)
],
)
]
)
colors = [
'#313695',
'#4575b4',
'#74add1',
'#abd9e9',
'#e0f3f8',
'#ffffbf',
'#fee090',
'#fdae61',
'#f46d43',
'#d73027',
'#a50026'
]
random.shuffle(colors)
pie.set_colors(colors)

page = Page()
page.add(chart).add(pie)
page.render_notebook()