数据展示
2019 | 2018 | 2017 | 2016 | 2015 | 2014 | 2013 | 2012 | |
北京 | 5817.1 | 5785.9176 | 5430.7875 | 5081.26 | 4723.86 | 4027.1609 | 3661.1097 | 3314.934 |
天津 | 2410.25 | 2106.2397 | 2310.3552 | 2723.5 | 2667.11 | 2390.3518 | 2079.0716 | 1760.0201 |
河北 | 3742.67 | 3513.8643 | 3233.8332 | 2849.87 | 2649.18 | 2446.6166 | 2295.6203 | 2084.2825 |
山西 | 2347.56 | 2292.6982 | 1867.0022 | 1557 | 1642.35 | 1820.635 | 1701.6227 | 1516.378 |
内蒙古 | 2059.74 | 1857.6493 | 1703.2095 | 2016.43 | 1964.48 | 1843.6736 | 1720.9843 | 1552.7453 |
辽宁 | 2651.96 | 2616.0832 | 2392.7653 | 2200.49 | 2127.39 | 3192.7813 | 3343.8106 | 3105.3785 |
吉林 | 1116.86 | 1240.8892 | 1210.9081 | 1263.78 | 1229.35 | 1203.3843 | 1156.9616 | 1041.2514 |
黑龙江 | 1262.64 | 1282.595 | 1243.3118 | 1148.41 | 1165.88 | 1301.312 | 1277.3951 | 1163.1708 |
上海 | 7165.1 | 7108.148 | 6642.2638 | 6406.13 | 5519.5 | 4585.5534 | 4109.5086 | 3743.7053 |
江苏 | 8802.36 | 8630.1605 | 8171.5315 | 8121.23 | 8028.59 | 7233.1426 | 6568.464 | 5860.6884 |
浙江 | 7048 | 6598.212 | 5804.3837 | 5301.98 | 4809.94 | 4122.0211 | 3796.9241 | 3441.2267 |
安徽 | 3182.54 | 3048.6705 | 2812.4495 | 2672.79 | 2454.3 | 2218.4418 | 2075.075 | 1792.7192 |
福建 | 3052.72 | 3007.4087 | 2809.0332 | 2654.83 | 2544.24 | 2362.2138 | 2119.4455 | 1776.1728 |
江西 | 2486.51 | 2373.008 | 2247.0624 | 2151.47 | 2165.74 | 1881.8315 | 1621.2358 | 1371.994 |
山东 | 6526.64 | 6485.3959 | 6098.6324 | 5860.18 | 5529.33 | 5026.8273 | 4559.9463 | 4059.4301 |
河南 | 4041.6 | 3766.0183 | 3407.2187 | 3153.47 | 3016.05 | 2739.2556 | 2415.4482 | 2040.331 |
湖北 | 3388.39 | 3307.0782 | 3248.3159 | 3102.06 | 3005.53 | 2566.8953 | 2191.2221 | 1823.0532 |
湖南 | 3006.99 | 2860.8443 | 2757.8212 | 2697.88 | 2515.43 | 2262.7859 | 2030.8758 | 1782.156 |
广东 | 12651.46 | 12105.2552 | 11320.3497 | 10390.35 | 9366.78 | 8065.0758 | 7081.4655 | 6229.1804 |
广西 | 1811.89 | 1681.4466 | 1615.1273 | 1556.27 | 1515.16 | 1422.2803 | 1317.6035 | 1166.0614 |
海南 | 814.13 | 752.6673 | 674.105 | 637.51 | 627.7 | 555.3064 | 481.014 | 409.437 |
重庆 | 2134.88 | 2265.5421 | 2252.3788 | 2227.91 | 2154.83 | 1922.0159 | 1693.2438 | 1703.4885 |
四川 | 4070.69 | 3911.0092 | 3577.9887 | 3388.85 | 3355.44 | 3061.0684 | 2784.0952 | 2421.2703 |
贵州 | 1767.36 | 1726.8516 | 1613.8377 | 1561.34 | 1503.38 | 1366.6731 | 1206.4146 | 1014.0547 |
云南 | 2073.53 | 1994.3458 | 1886.1687 | 1812.29 | 1808.1 | 1698.0574 | 1611.2955 | 1338.1509 |
西藏 | 222 | 230.3543 | 185.8341 | 155.99 | 137.13 | 124.2708 | 95.0237 | 86.5827 |
陕西 | 2287.73 | 2243.1391 | 2006.6939 | 1833.99 | 2059.95 | 1890.4044 | 1748.3305 | 1600.6862 |
甘肃 | 850.23 | 871.0537 | 815.7323 | 786.97 | 743.86 | 672.6698 | 607.2717 | 520.3993 |
青海 | 282.14 | 272.887 | 246.1961 | 238.51 | 267.13 | 251.6759 | 223.8586 | 186.4165 |
宁夏 | 423.55 | 436.5205 | 417.5888 | 387.66 | 373.4 | 339.8627 | 308.3376 | 263.9569 |
新疆 | 1577.6 | 1531.4229 | 1466.5189 | 1298.95 | 1330.9 | 1282.3367 | 1128.4875 | 908.9655 |
2011 | 2010 | 2009 | 2008 | 2007 | 2006 | 2005 |
3006.28 | 2353.9301 | 2026.8089 | 1837.3238 | 1492.638 | 1117.1514 | 919.2098 |
1455.13 | 1068.8093 | 821.9916 | 675.6186 | 540.439 | 417.0479 | 331.8507 |
1737.77 | 1331.8547 | 1067.1231 | 947.5858 | 789.1198 | 620.534 | 515.7017 |
1213.43 | 969.6652 | 805.8279 | 748.0047 | 597.887 | 583.3752 | 368.3437 |
1356.67 | 1069.9776 | 850.8588 | 650.6764 | 492.3615 | 343.3774 | 277.4553 |
2643.15 | 2004.8352 | 1591.2197 | 1356.0812 | 1082.6948 | 817.6718 | 675.2768 |
850.1 | 602.4092 | 487.0943 | 422.7961 | 320.6892 | 245.2045 | 207.152 |
997.55 | 755.5788 | 641.6627 | 578.2773 | 440.4689 | 386.844 | 318.2056 |
3429.83 | 2873.584 | 2540.2975 | 2358.7464 | 2074.4792 | 1576.0742 | 1417.3976 |
5148.91 | 4079.8595 | 3228.78 | 2731.4074 | 2237.7276 | 1656.682 | 1322.6753 |
3150.8 | 2608.4655 | 2142.5131 | 1933.389 | 1649.4981 | 1298.2044 | 1066.5964 |
1463.56 | 1149.3952 | 863.9175 | 724.6197 | 543.6973 | 428.0265 | 334.017 |
1501.51 | 1151.4923 | 932.4282 | 833.4032 | 699.4577 | 541.1707 | 432.6003 |
1053.43 | 778.0922 | 581.3012 | 488.6476 | 389.851 | 305.5214 | 252.9236 |
3455.93 | 2749.3842 | 2198.6324 | 1957.0541 | 1675.398 | 1356.2526 | 1073.125 |
1721.76 | 1381.3178 | 1126.0638 | 1008.9009 | 862.0804 | 679.1715 | 537.6514 |
1526.91 | 1011.2314 | 814.8653 | 710.8492 | 590.3552 | 476.0823 | 375.5217 |
1517.07 | 1081.6901 | 847.6178 | 722.7122 | 606.5508 | 477.9274 | 395.2651 |
5514.84 | 4517.0445 | 3649.811 | 3310.3235 | 2785.8007 | 2179.4608 | 1807.2044 |
947.72 | 771.9918 | 620.9888 | 518.4245 | 418.8265 | 342.5788 | 283.0359 |
340.12 | 270.9915 | 178.242 | 144.8584 | 108.2935 | 81.8139 | 68.6802 |
1488.33 | 952.0745 | 655.1701 | 577.5738 | 442.7 | 317.7165 | 256.8072 |
2044.79 | 1561.6727 | 1174.5927 | 1041.6603 | 850.8606 | 607.585 | 479.6635 |
773.08 | 533.7309 | 416.4761 | 347.8416 | 285.1375 | 226.8157 | 182.4963 |
1111.16 | 871.1875 | 698.2525 | 614.0518 | 486.7146 | 379.9702 | 312.649 |
54.76 | 36.6473 | 30.0894 | 24.8823 | 20.1412 | 14.5607 | 12.0312 |
1500.18 | 958.2065 | 735.2704 | 591.475 | 475.2398 | 362.4805 | 275.3183 |
450.12 | 353.5833 | 286.5898 | 264.965 | 190.9107 | 141.2152 | 123.5026 |
151.81 | 110.2153 | 87.7381 | 71.5692 | 56.7083 | 42.2437 | 33.8222 |
219.98 | 153.5507 | 111.5755 | 95.009 | 80.0312 | 61.357 | 47.7216 |
720.43 | 500.5759 | 388.7848 | 361.0616 | 285.86 | 219.4628 | 180.3184 |
2004 | 2003 | 2002 | 2001 | 2000 |
744.4874 | 592.5388 | 533.99 | 454.1676 | 344.9968 |
246.18 | 204.5295 | 209.7021 | 163.635 | 133.6069 |
407.8273 | 335.8263 | 302.3068 | 283.5023 | 248.7621 |
256.3634 | 186.0547 | 150.8245 | 132.7618 | 114.4762 |
196.7589 | 138.7157 | 112.8546 | 99.4313 | 95.032 |
529.6405 | 447.049 | 399.6888 | 370.4387 | 295.6274 |
166.2807 | 154.0033 | 131.4885 | 121.1015 | 103.8267 |
289.42 | 248.8643 | 231.8908 | 213.6398 | 185.3379 |
1106.1932 | 886.2277 | 719.79 | 609.4719 | 485.3777 |
980.4939 | 798.1065 | 643.6966 | 572.1473 | 448.3097 |
805.9479 | 706.5607 | 566.8522 | 500.6948 | 342.7745 |
274.6284 | 220.7487 | 200.2154 | 192.1813 | 178.7187 |
333.523 | 304.7095 | 272.8867 | 274.2846 | 234.1061 |
205.7667 | 168.167 | 140.5457 | 131.979 | 111.5536 |
828.3306 | 713.7877 | 610.2242 | 573.1793 | 463.6788 |
428.7799 | 338.0535 | 296.7179 | 267.7459 | 246.4694 |
310.4464 | 259.7636 | 243.4403 | 231.941 | 214.345 |
320.6279 | 268.6469 | 231.1459 | 205.4078 | 177.0403 |
1418.5056 | 1315.5151 | 1201.6126 | 1160.5126 | 910.556 |
237.7721 | 203.6578 | 186.732 | 178.6706 | 147.0539 |
57.0358 | 51.3205 | 46.2385 | 43.7656 | 39.1995 |
200.6241 | 161.5618 | 157.8651 | 106.1243 | 87.2442 |
385.7848 | 336.5917 | 291.8746 | 271.1245 | 233.863 |
149.2855 | 124.5552 | 108.28 | 99.7494 | 85.2324 |
263.3618 | 228.9992 | 206.7594 | 191.2799 | 180.745 |
10.0188 | 8.1499 | 7.3082 | 6.1108 | 5.3848 |
214.9586 | 177.33 | 150.2934 | 135.8109 | 114.9711 |
104.16 | 87.6561 | 76.2432 | 69.9485 | 61.2849 |
26.996 | 24.0411 | 21.0965 | 19.8241 | 16.5843 |
37.4677 | 30.031 | 26.4714 | 27.5745 | 20.8244 |
155.704 | 128.2218 | 116.4724 | 95.0933 | 79.0724 |
在 Python 中,可以使用 Echarts 来实现交互式动态可视化。Echarts 是一个强大的可视化库,能够创建各种精美的图表和可视化效果。
以下是实现步骤:
一、安装必要的库
首先,确保你已经安装了 Python 和以下库:
pyecharts
:用于在 Python 中生成 Echarts 图表。
可以使用以下命令安装 pyecharts
:
pip install pyecharts
二、创建图表
- 导入所需的模块:
from pyecharts.charts import Bar
from pyecharts import options as opts
- 创建一个柱状图示例:
bar = Bar()
bar.add_xaxis(["A", "B", "C", "D", "E"])
bar.add_yaxis("Series 1", [10, 20, 30, 40, 50])
bar.set_global_opts(title_opts=opts.TitleOpts(title="Sample Bar Chart"))
三、渲染图表
- 可以将图表渲染为 HTML 文件:
bar.render("bar_chart.html")
- 也可以在 Jupyter Notebook 中直接显示图表:
bar.render_notebook()
import pyecharts.options as opts
from pyecharts.globals import ThemeType
from pyecharts.commons.utils import JsCode
from pyecharts.charts import Timeline, Grid, Bar, Map, Pie
import pandas as pd
data = pd.read_excel('全国各省财政收入.xlsx',index_col=0)
years=list(data.keys()) #获取列名
citys=list(data.index) #获取索引行名
citys=[city.replace('省','').replace('市','').replace('自治区','') for city in citys]
datas=[]
for time in years:
dict_year={}
dict_year['time']=time
data_list=[[i,j] for i,j in zip(citys,list(data[time]))]
dict_year['data']=sorted(data_list, key=(lambda x: x[1]),reverse=True)
datas.append(dict_year)
def get_year_chart(year: int):
map_data = [datasDict["data"] for datasDict in datas if datasDict["time"]==year][0][:10]
print(map_data)
min_data, max_data = (
min([d[1] for d in map_data]),
max([d[1] for d in map_data]),
)
map_chart = (
Map(init_opts=opts.InitOpts(theme=ThemeType.DARK))## 实例化一个Map对象
.add(
series_name="",
data_pair=map_data,
label_opts=opts.LabelOpts(is_show=True),
is_map_symbol_show=False,
maptype="china"
)#创建地图
#Map图表中add基本参数为:add(‘图例名称’,date,maptype),maptype选项分为:全球:world;中国:china;
#set_series_opts(label_opts=opts.LabelOpts(is_show=False))作用为不显示地图中省份名称
#设置全局配置项
.set_global_opts(
title_opts=opts.TitleOpts(
title="{}年以来中国各省GDP排名情况".format(year),
subtitle="GDP单位:亿元",
pos_left="center",
pos_top="top",
title_textstyle_opts=opts.TextStyleOpts(
font_size=25, color="rgba(123,104,238, 0.9)"
),
),
visualmap_opts=opts.VisualMapOpts(
is_calculable=True,
dimension=0,
pos_left="10",
pos_top="center",#
range_text=["High", "Low"],
range_color=["lightskyblue", "yellow", "orangered"],#visualMap 组件过渡颜色 (可以自定义)(颜色从淡到深)
textstyle_opts=opts.TextStyleOpts(color="#ddd"),#文字样式配置项
min_=min_data,
max_=max_data,
),#视觉映射配置项,设置最大值后不同金额会显示不同颜色
)
)
bar_x_data = [x[0] for x in map_data]
bar_y_data = [x[1] for x in map_data]
bar = (
Bar(init_opts=opts.InitOpts(theme=ThemeType.DARK))
.add_xaxis(xaxis_data=bar_x_data)
.add_yaxis(
series_name="",
y_axis=bar_y_data,
label_opts=opts.LabelOpts(
is_show=True, position="right", formatter="{b}: {c}"
),
)
.reversal_axis()#横向柱状图展示
.set_global_opts(
xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(is_show=False)),#对X轴和Y轴标上名字
yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(is_show=False)),#柱状图X轴和Y轴上面的个性化标记,旋转坐标轴: 解决坐标轴名字过长的问题
tooltip_opts=opts.TooltipOpts(is_show=True),#要设置柱形图上面的提示框,这个时候需要用到TooltipOpts。
visualmap_opts=opts.VisualMapOpts(
is_calculable=True,#是否显示拖拽用的手柄
dimension=0,
pos_left="10",
pos_top="center",
range_text=["High", "Low"],
range_color=["lightskyblue", "yellow", "orangered"],
textstyle_opts=opts.TextStyleOpts(color="#ddd"),
min_=min_data,
max_=max_data,
),
)
)
pie_data = [[x[0], x[1]] for x in map_data]
percent_sum = sum([x[1] for x in map_data])
print(percent_sum)
rest_value = 0
for d in map_data:
rest_percent = 100.0
rest_percent = rest_percent - percent_sum
rest_value = d[1] * (rest_percent / d[1])
pie = (
Pie(init_opts=opts.InitOpts(theme=ThemeType.DARK))
.add(
series_name="",
data_pair=pie_data,
radius=["12%", "20%"],# #百分比根据实际情况进行修改(空心和实心),饼图的半径,数组的第一项是内半径,第二项是外半径
center=["80%", "90%"],#饼图的中心(圆心)坐标,数组的第一项是横坐标,第二项是纵坐标
itemstyle_opts=opts.ItemStyleOpts(
border_width=1, border_color="rgba(0,0,0,0.3)"#RGBA,比如'rgba(128, 128, 128, 0.5),0.5参数通道表示不透明度
),## 图元样式配置项
)
.set_global_opts(
tooltip_opts=opts.TooltipOpts(is_show=True, formatter="{b} {d}%"),
legend_opts=opts.LegendOpts(is_show=False),
)
)
grid_chart = (
Grid()#Grid 类:并行显示多张图
.add(
bar,
grid_opts=opts.GridOpts(
pos_left="10", pos_right="45%", pos_top="70%", pos_bottom="5"
),
)
.add(pie, grid_opts=opts.GridOpts())
.add(map_chart, grid_opts=opts.GridOpts())
)
return grid_chart
# 生成时间轴实现轮播
time_list = list(range(2000,2020))
#timeline本身是时间轴,Timeline 类:提供时间线轮播多张图
timeline = Timeline(
init_opts=opts.InitOpts(width="900px", height="400px", theme=ThemeType.DARK)
)
for time in time_list:
g = get_year_chart(year=time)
timeline.add(g, time_point=str(time))
timeline.add_schema(
orient="vertical",
is_auto_play=True,#是否自动播放。
is_inverse=True,##是否反向放置 timeline,反向则首位颠倒过来
play_interval=500,#表示播放的速度(跳动的间隔)
pos_left="null",
pos_right="5",
pos_top="20",
pos_bottom="20",
width="50",
label_opts=opts.LabelOpts(is_show=True, color="#fff"),
)
timeline.render(path='test_bar.html')
import pyecharts.options as opts
from pyecharts.charts import Timeline, Map
import pandas as pd
# 读取 Excel 文件中的数据(假设你的 Excel 文件中包含省份和对应年份的 GDP 数据)
data = pd.read_excel('全国各省财政收入.xlsx', index_col=0)
years = list(data.keys())
citys = list(data.index)
citys = [city.replace('省', '').replace('市', '').replace('自治区', '') for city in citys]
# 重新组织数据
total_data = {}
for year in years:
temp = list(data[year])
total_data[year] = []
for i in range(len(temp)):
total_data[year].append({"name": citys[i], "value": temp[i]})
# 获取指定年份的中国地图图表
def get_map_chart(year: int) -> Map:
map_chart = (
Map()
.add("GDP", total_data[year], "china")
.set_global_opts(
title_opts=opts.TitleOpts(title=f"{year}年各省 GDP 分布"),
visualmap_opts=opts.VisualMapOpts(max_=max([item["value"] for item in total_data[year]]),
min_=min([item["value"] for item in total_data[year]]))
)
)
return map_chart
# 生成时间轴的图
timeline = Timeline()
for y in years:
timeline.add(get_map_chart(year=y), time_point=str(y))
# 设置时间轴自动播放等属性
timeline.add_schema(is_auto_play=True, play_interval=1000)
timeline.render("gdp_china_map_timeline.html")
import pyecharts.options as opts
from pyecharts.charts import Timeline, Bar, Pie
import pandas as pd
# 读取 Excel 文件中的数据
data = pd.read_excel('全国各省财政收入.xlsx', index_col=0)
years = list(data.keys())
citys = list(data.index)
citys = [city.replace('省', '').replace('市', '').replace('自治区', '') for city in citys]
# 重新组织数据
total_data = {}
for year in years:
temp = list(data[year])
total_data[year] = []
for i in range(len(temp)):
total_data[year].append({"name": citys[i], "value": temp[i]})
max_data = max(temp)
sum_data = sum(temp)
total_data[str(year) + "max"] = int(max_data / 100) * 100
total_data[str(year) + "sum"] = sum_data
# 获取指定年份的图表
def get_year_overlap_chart(year: int) -> Bar:
bar = (
Bar()
.add_xaxis(xaxis_data=[item["name"] for item in total_data[year]])
.add_yaxis(
series_name="财政收入",
y_axis=[item["value"] for item in total_data[year]],
label_opts=opts.LabelOpts(is_show=False),
)
.set_global_opts(
title_opts=opts.TitleOpts(
title="{}年全国各省财政收入".format(year), subtitle="数据来源:全国各省财政收入.xlsx"
),
tooltip_opts=opts.TooltipOpts(
is_show=True, trigger="axis", axis_pointer_type="shadow"
),
legend_opts=opts.LegendOpts(
selected_map={
"财政收入": False,
}
),
)
)
return bar
# 生成时间轴的图
timeline = Timeline()
for y in years:
timeline.add(get_year_overlap_chart(year=y), time_point=str(y))
# 设置时间轴自动播放等属性
timeline.add_schema(is_auto_play=True, play_interval=1000)
timeline.render("finance_indices_2003.html")
import pyecharts.options as opts
from pyecharts.charts import Pie
import pandas as pd
import pandas as pd
from pyecharts.charts import Bar, Scatter
from pyecharts import options as opts
# 读取 Excel 文件中的数据
data = pd.read_excel('全国各省财政收入.xlsx', index_col=0)
years = list(data.keys())
citys = list(data.index)
citys = [city.replace('省', '').replace('市', '').replace('自治区', '') for city in citys]
# 重新组织数据
total_data = {}
for year in years:
temp = list(data[year])
total_data[year] = []
for i in range(len(temp)):
total_data[year].append({"name": citys[i], "value": temp[i]})
# 选择某一年份(这里以第一年为例)来绘制饼图
year = years[0]
data_for_pie = total_data[year]
# 获取饼图
def get_pie_chart() -> Pie:
pie = (
Pie()
.add(
"",
[(item["name"], item["value"]) for item in data_for_pie],
radius=["30%", "75%"],
)
.set_global_opts(
title_opts=opts.TitleOpts(title=f"{year}年全国各省财政收入饼图"),
tooltip_opts=opts.TooltipOpts(trigger="item", formatter="{a} <br/>{b}: {c} ({d}%)"),
)
.set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
)
return pie
get_pie_chart().render("pie_chart.html")