coding:utf-8

from pyecharts import options as opts from pyecharts.charts import Bar, Grid, Map, Timeline import pandas as pd

datas = pd.read_csv('2001-2019各省GDP数据.csv', encoding='gbk')

def get_gdp_map2(datas): tl = Timeline() tl.add_schema(play_interval=500, symbol='emptydiamond')

for i in range(2001, 2020):
    # Filter the data for the current year
    year_data = datas[['地区', str(i) + '年']].copy()
    year_data.sort_values(by=str(i) + '年', ascending=False, inplace=True)
    year_data = year_data.head(10)

    # Create the bar chart for the current year
    bar_chart = (
        Bar()
        .add_xaxis(year_data['地区'].tolist())
        .add_yaxis('{}年GDP排名前十'.format(i), year_data[str(i) + '年'].tolist(), category_gap=0)
        .set_global_opts(
            title_opts=opts.TitleOpts(title='{}年GDP排名前十的省份'.format(i)),
            xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-45)),
            visualmap_opts=opts.VisualMapOpts(is_show=False),
        )
    )

    # Create the map chart for the current year
    map_chart = (
        Map()
        .add('全国各省GDP(亿元)', datas[['地区', str(i) + '年']].values.tolist(), 'china')
        .set_global_opts(
            title_opts=opts.TitleOpts(title='{}年全国各省GDP(亿元)'.format(i)),
            visualmap_opts=opts.VisualMapOpts(is_show=True, max_=110000, is_piecewise=True),
        )
        .set_series_opts(label_opts=opts.LabelOpts(is_show=False))
    )

    # Create the grid chart for the current year
    grid_chart = (
        Grid()
        .add(bar_chart, grid_opts=opts.GridOpts(pos_left='10%', pos_bottom='50%', pos_right='10%', height='40%'))
        .add(map_chart, grid_opts=opts.GridOpts(height='60%'))
    )

    tl.add(grid_chart, '{}年'.format(i))

tl.render('2001-2019年全国各省GDP.html')

get_gdp_map2(datas) 为什么map地图和bar重叠了 怎样将他两个在画布上分得开?

您可以通过调整Gridgrid_opts参数来控制bar_chartmap_chart的位置和大小,从而将它们分开。在这里,您可以尝试调整grid_optspos_leftpos_bottompos_rightheight参数的值,以适应您期望的布局。例如,您可以尝试将pos_bottom参数的值调整为较小的值,以增加bar_chart的高度,从而与map_chart分开。

Python Pyecharts 地图和柱状图重叠问题解决

原文地址: https://www.cveoy.top/t/topic/eQBG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录