from pyecharts import options as opts from pyecharts.charts import Map data_map = [ {"name": "昆明", "value": 2338}, {"name": "昭通", "value": 290}, {"name": "曲靖", "value": 518}, {"name": "玉溪", "value": 239}, {"name": "普洱", "value": 390}, {"name": "保山", "value": 288}, {"name": "丽江", "value": 83}, {"name": "临沧", "value": 330}, {"name": "楚雄", "value": 90}, {"name": "红河", "value": 296}, {"name": "文山", "value": 375}, {"name": "西双版纳", "value": 271}, {"name": "大理", "value": 259}, {"name": "德宏", "value": 295}, {"name": "怒江", "value": 42}, {"name": "迪庆", "value": 24}, ] #创建Map对象 map_demo = ( Map() .add( "犯罪未遂案件数量", data_map, "云南", is_map_symbol_show=False, label_opts=opts.LabelOpts(is_show=False), # 指定颜色渐变 itemstyle_opts=opts.ItemStyleOpts( color=[ "#f5ecec", "#f5c6c6", "#f0a4a4", "#e88181", "#e35e5e", "#d93737", "#cc1e1e", "#b81a1a", "#9e1616", "#841212", "#6a0e0e", ] ), ) .set_global_opts( title_opts=opts.TitleOpts(title="云南地图示例"), visualmap_opts=opts.VisualMapOpts(min_=0, max_=3000), ) ) map_demo.render_notebook() 怎么做到当鼠标移动到地区上时颜色变化
时间: 2023-07-07 14:44:39 浏览: 131
jilin.zip_PYECHARTS 吉林省_echarts 吉林_echarts 地图_jilin_pyecharts 吉林
你可以通过设置`tooltip_opts`属性来实现当鼠标移动到地区上时颜色变化以及显示相关信息,具体代码如下:
```python
from pyecharts import options as opts
from pyecharts.charts import Map
data_map = [
{"name": "昆明", "value": 2338},
{"name": "昭通", "value": 290},
{"name": "曲靖", "value": 518},
{"name": "玉溪", "value": 239},
{"name": "普洱", "value": 390},
{"name": "保山", "value": 288},
{"name": "丽江", "value": 83},
{"name": "临沧", "value": 330},
{"name": "楚雄", "value": 90},
{"name": "红河", "value": 296},
{"name": "文山", "value": 375},
{"name": "西双版纳", "value": 271},
{"name": "大理", "value": 259},
{"name": "德宏", "value": 295},
{"name": "怒江", "value": 42},
{"name": "迪庆", "value": 24},
]
# 创建Map对象
map_demo = (
Map()
.add(
"犯罪未遂案件数量",
data_map,
"云南",
is_map_symbol_show=False,
label_opts=opts.LabelOpts(is_show=False),
# 指定颜色渐变
itemstyle_opts=opts.ItemStyleOpts(
color=[
"#f5ecec",
"#f5c6c6",
"#f0a4a4",
"#e88181",
"#e35e5e",
"#d93737",
"#cc1e1e",
"#b81a1a",
"#9e1616",
"#841212",
"#6a0e0e",
]
),
# 设置地图提示信息
tooltip_opts=opts.TooltipOpts(
formatter="{b}: {c}", trigger="item", axis_pointer_type="cross"
),
)
.set_global_opts(
title_opts=opts.TitleOpts(title="云南地图示例"),
visualmap_opts=opts.VisualMapOpts(min_=0, max_=3000),
)
)
map_demo.render_notebook()
```
其中,`tooltip_opts`可以设置如下属性:
- `formatter`:提示框内容格式器,支持字符串模板和回调函数两种形式;
- `trigger`:提示框触发类型,可选值包括:'item'、'axis'、'none';
- `axis_pointer_type`:坐标轴指示器类型,可选值包括:'line'、'shadow'、'cross'、'none'。
阅读全文