大家好,我是 【Python当打之年(点击跳转)】
本期我们通过分析 2021年中国统计年鉴数据 ,统计全国各地人民的消费地图,看看:
希望对小伙伴们有所帮助,如有疑问或者需要改进的地方可以私信小编。
import pandas as pd
from pyecharts.charts import Bar
from pyecharts.charts import Map
from pyecharts.charts import Pie
from pyecharts.charts import Grid
from pyecharts import options as opts
from pyecharts.commons.utils import JsCode
df = pd.read_csv('./居民人均消费支出.txt',sep=' ')
df1['消费支出占比'] = df1['消费支出']/df1['人均可支配收入']
df1['食品烟酒消费占比'] = df1['食品烟酒']/df1['消费支出']
df1['衣着消费占比'] = df1['衣着']/df1['消费支出']
df1['居住消费占比'] = df1['居住']/df1['消费支出']
df1['生活用品及服务'] = df1['生活用品及服务']/df1['消费支出']
df1['交通通信消费占比'] = df1['交通通信']/df1['消费支出']
b1 = (
Bar(init_opts=opts.InitOpts(theme='dark',width='1000px', height='1500px',bg_color='#0d0735'))
.add_xaxis(x_data1)
.add_yaxis("消费支出", y_data1,category_gap='35%', stack="stack1",
label_opts=opts.LabelOpts(position="inside"),
itemstyle_opts={"normal": {
'shadowBlur': 10,
'shadowColor': 'rgba(0,191,255,0.5)',
'shadowOffsetY': 1,
'color':'#203fb6',
}
},
)
.add_yaxis("人均净收入", y_data2, category_gap='35%', stack="stack1",
label_opts=opts.LabelOpts(position="inside", font_size=12, font_weight='bold', formatter='{c}'),
itemstyle_opts={"normal": {
"barBorderRadius": [0, 30, 30, 0],
'shadowBlur': 10,
'shadowColor': 'rgba(0,191,255,0.5)',
'shadowOffsetY': 1,
'color':'#e7298a'
}
},
)
.set_global_opts(
xaxis_opts=opts.AxisOpts(position='top'),
yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(font_size=13,formatter="{value}")),
title_opts=opts.TitleOpts(title='1-全国各地区人均收入、消费支出排行榜',pos_top='2%',pos_left="2%",
title_textstyle_opts=opts.TextStyleOpts(color='#fff200',font_size=20)),
legend_opts=opts.LegendOpts(pos_right="8%", pos_top="9%", orient="vertical")
)
)
m1 = (
Map()
.add('',
[list(z) for z in zip(x_data1, y_data1)],
maptype='china',
is_map_symbol_show=False,
label_opts=opts.LabelOpts(is_show=False,color='red'))
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(
is_show=True,
min_ = 20000,
max_ = 50000,
series_index=0,
pos_top='70%',
pos_left='10%',
),
tooltip_opts=opts.TooltipOpts(formatter='{b}:{c}'),
title_opts=opts.TitleOpts(title='2-全国各地区人均可支配收入地图',pos_top='2%',pos_left="2%",
title_textstyle_opts=opts.TextStyleOpts(color='#fff200',font_size=20))
)
)
网盘: https://pan.baidu.com/doc/share/Olj4d~aKuXT7AF0cq01MrQ-437060019167360
提取码: pyra
以上就是本期为大家整理的全部内容了,赶快练习起来吧,原创不易,喜欢的朋友可以点赞、收藏也可以分享(注明出处)让更多人知道。