pyecharts-page的组合

获取数据

import re
import requests
import json
import pandas as pd
import time
from pyecharts.charts import Map,Bar,Page,Pie
from pyecharts import options as opts
from pyecharts.components import Table
from pyecharts.options import ComponentTitleOpts

url = 'https://m.look.360.cn/events/feiyan?sv=&version=&market=&device=2&net=4&stype=&scene=&sub_scene=&refer_scene=&refer_subscene=&f=jsonp&location=true&sort=2&_=1597286912004&callback=jsonp2'
headers = {
   'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36 QIHU 360SE',
          'Referer': 'https://www.360kuai.com/mob/subject/400?sign=360_6aa05217&stab=0'}
response = requests.get(url=url, headers=headers)
data = json.loads(response.text[7:-2])['data']  # 国内,国外的是['country']
data[0]

{‘cities’: [{‘cityName’: ‘境外输入’,
‘cured’: 187,
‘currentConfirmed’: 4,
‘currentConfirmedFlag’: False,
‘diagnosed’: 191,
‘died’: 0,
‘diffDiagnosed’: 0,
‘modifyTime’: 1606492801000,
‘op’: [],
‘suspected’: 0},
{‘cityName’: ‘丰台区’,
‘cured’: 273,
‘currentConfirmed’: 0,
‘currentConfirmedFlag’: False,
‘diagnosed’: 273,
‘died’: 0,
‘diffDiagnosed’: 0,
‘modifyTime’: 1606492801000,
‘op’: [],
‘suspected’: 0},

{‘cityName’: ‘延庆区’,
‘cured’: 1,
‘currentConfirmed’: 0,
‘currentConfirmedFlag’: False,
‘diagnosed’: 1,
‘died’: 0,
‘diffDiagnosed’: 0,
‘modifyTime’: 1606492801000,
‘op’: [],
‘suspected’: 0}],
‘city’: ‘北京市’,
‘cityShortName’: ‘北京’,
‘cured’: 937,
‘currentConfirmed’: 4,
‘currentConfirmedFlag’: False,
‘data’: {‘cityName’: ‘’,
‘comment’: ‘北京卫健委未明确大部分治愈与死亡病例的分区归属,因此北京市下辖分区的现存确诊暂无法获取。’,
‘confirmedCount’: 442,
‘continents’: ‘’,
‘countryFullName’: ‘’,
‘countryShortCode’: ‘’,
‘countryType’: 1,
‘createTime’: 1584260897000,
‘curedCount’: 353,
‘currentConfirmedCount’: 81,
‘deadCount’: 8,
‘id’: 1085913,
‘locationId’: 110000,
‘modifyTime’: 1584260897000,
‘operator’: ‘wangjinyuan’,
‘provinceId’: ‘11’,
‘provinceName’: ‘北京市’,
‘provinceShortName’: ‘北京’,
‘sort’: 4,
‘suspectedCount’: 0,
‘tags’: ‘确诊 442 例,治愈 353 例,死亡 8 例,北京卫健委未明确大部分治愈与死亡病例的分区归属,因此北京市下辖分区的现存确诊暂无法获取。’,
‘tags_1’: '确诊 22 例 '},
‘diagnosed’: 950,
‘died’: 9,
‘diffDiagnosed’: 0,
‘isLocation’: 1,
‘suspected’: 0}

yiqing = pd.DataFrame(columns=['省份','城市', '累计确诊','当前确诊','治愈','死亡','截至时间'])
for i in range(len(data)):
    d = data[i]['cities']
    for j in range(len(d)):  # 每个市
        t = int(str(d[j]['modifyTime'])[:10])  # 取前10个数字
        t = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(t))
        yiqing = yiqing.append(pd.DataFrame([[data[i]['cityShortName'], d[j]['cityName'], d[j]['diagnosed'
### PyEcharts 实现多图表组合 #### 使用 `Tab` 类实现选项卡多图 通过 `pyecharts.charts.Tab` 类可以创建带有标签页的多图表展示方式。以下是基于引用中的描述构建的一个简单示例: ```python from pyecharts import options as opts from pyecharts.charts import Bar, Line, Tab # 创建第一个图表:柱状图 bar = ( Bar() .add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]) .add_yaxis("商家A", [120, 200, 150, 80, 70, 110]) ) # 创建第二个图表:折线图 line = ( Line() .add_xaxis(["周一", "周二", "周三", "周四", "周五", "周六", "周日"]) .add_yaxis("商家B", [120, 200, 150, 80, 70, 110, 130]) ) # 将两个图表加入到 Tab 中 tab = Tab(page_title="Awesome-pyecharts 示例") tab.add(bar, "柱状图示例") tab.add(line, "折线图示例") # 渲染为 HTML 文件 tab.render("tab_example.html") ``` 上述代码展示了如何利用 `Tab` 类来管理多个独立图表,并通过标签切换的方式查看不同类型的图表[^1]。 --- #### 使用 `Grid` 类实现并行多图 如果希望在同一页面上显示多个图表,则可以通过 `Grid` 来布局这些图表。以下是一个简单的例子: ```python from pyecharts import options as opts from pyecharts.charts import Bar, Grid, Line # 创建柱状图 bar = ( Bar(init_opts=opts.InitOpts(width="600px", height="400px")) .add_xaxis(["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]) .add_yaxis("商家C", [120, 200, 150, 80, 70, 110]) ) # 创建折线图 line = ( Line(init_opts=opts.InitOpts(width="600px", height="400px")) .add_xaxis(["周一", "周二", "周三", "周四", "周五", "周六", "周日"]) .add_yaxis("商家D", [120, 200, 150, 80, 70, 110, 130]) ) # 定义网格布局并将图表放入其中 grid = ( Grid(init_opts=opts.InitOpts( width="1200px", height="800px" )) .add(bar, grid_opts=opts.GridOpts(pos_left="5%", pos_right="55%")) # 左侧放置柱状图 .add(line, grid_opts=opts.GridOpts(pos_left="60%", pos_right="5%")) # 右侧放置折线图 ) # 渲染为 HTML 文件 grid.render("grid_example.html") ``` 此代码片段说明了如何使用 `Grid` 布局将多个图表排列在一个画布中,从而形成更紧凑的数据可视化效果[^4]。 --- #### 初始化配置项 (`InitOpts`) 为了自定义图表外观和行为,在实例化任何图表对象时都可以传递 `init_opts` 参数。例如,调整图表尺寸、背景颜色以及网页标题等属性均能在此完成[^3]。 ```python init_opts = opts.InitOpts( width="800px", height="600px", bg_color="#f0f0f0", page_title="我的数据仪表盘" ) ``` 以上初始化参数可用于所有支持该选项的图表类中。 --- #### 总结 PyEcharts 提供了多种方法用于实现多图表组合功能,具体取决于实际需求: - 如果需要分组展示不同的图表类型,推荐使用 `Tab`; - 若需在同一视窗下呈现关联性强的内容,则可选用 `Grid` 或其他高级布局工具。 ---
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值