GithubHelp home page GithubHelp logo

Comments (3)

sunhailin-Leo avatar sunhailin-Leo commented on June 4, 2024

@Updraft095

  • 麻烦提供下 example 进行测试

from pyecharts.

Updraft095 avatar Updraft095 commented on June 4, 2024

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

创建示例数据

data = {
'省份': ['山东省', '河北省', '山西省', '河南省', '江苏省'],
'2019': [100, 200, 150, 180, 120],
'2020': [120, 210, 160, 190, 130],
'2021': [130, 220, 170, 200, 140],
'2022': [140, 230, 180, 210, 150],
'2023': [150, 240, 190, 220, 160],
'2024': [160, 250, 200, 230, 170],
'2025': [170, 260, 210, 240, 180],
'2026': [180, 270, 220, 250, 190],
'2027': [190, 280, 230, 260, 200],
'2028': [200, 290, 240, 270, 210],
'2029': [210, 300, 250, 280, 220],
'2030': [220, 310, 260, 290, 230]
}

province_data = pd.DataFrame(data)
province_list = province_data['省份'].tolist()

提取数据

year_list = [str(year) for year in range(2019, 2031)]

#####折线图
line = Line()
line.set_global_opts(
xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-45))
)

for province in province_list:
data_for_province = province_data.loc[province_data['省份'] == province, year_list].values.tolist()[0]
line.add_xaxis(year_list)
line.add_yaxis(province, data_for_province, is_smooth=True)

固定地图和柱状图的数据为 2019 年

values = province_data['2019'].tolist()

map_chart = (
Map()
.add(
series_name="2019年数据",
data_pair=list(zip(province_list, values)),
maptype="china",
center=[140, 37],
zoom=1.2
)
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(max_=max(values)),
)
)

bar_chart = (
Bar()
.add_xaxis(province_list)
.add_yaxis("2019年数据", values)
.set_global_opts(title_opts=opts.TitleOpts(title="2019年各省份数据柱状图"))
)

grid = (
Grid()
.add(
bar_chart,
grid_opts=opts.GridOpts(pos_left="50%", pos_right="22%", pos_top="50%", pos_bottom="15%"),
)
.add(
line,
grid_opts=opts.GridOpts(pos_left="50%", pos_right="22%", pos_top="10%", pos_bottom="60%"),
)
.add(
map_chart,
grid_opts=opts.GridOpts(pos_left="5%", pos_right="50%", pos_top="50%", pos_bottom="15%"),
)
)
grid.render('样例.html')
grid.render_notebook()

from pyecharts.

Updraft095 avatar Updraft095 commented on June 4, 2024

这是一个示例代码,为了排除timeline造成的影响,同时使代码更加简单,我把地图和柱状图的时间固定在2019年。

from pyecharts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.