博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【Pyecharts | heatmap】解决GEO-Heatmap图表中热力区域混成一堆的情况
阅读量:3728 次
发布时间:2019-05-22

本文共 2271 字,大约阅读时间需要 7 分钟。

前言

在做GEO-Heatmap时是不是遇到过如下情况:

# 新建GEO实例geo = Geo(    init_opts=opts.InitOpts(        theme='light',        width='980px',        height='800px'    ))data_pair = []for idx, data_item in enumerate(data):    geo.add_coordinate(idx, data_item[0], data_item[1])    data_pair.append([idx, data_item[2]])    geo.add_schema(    maptype="world")geo.add(    '',    data_pair,    type_='heatmap',    is_large=True,    label_opts=opts.LabelOpts(is_show=False),    tooltip_opts=opts.TooltipOpts(is_show=False),)geo.set_global_opts(    title_opts=opts.TitleOpts(        title="全球人口热力图", pos_top='3%', pos_left='center',         title_textstyle_opts=opts.TextStyleOpts(color='#00BFFF', font_size=20)        ),    visualmap_opts=opts.VisualMapOpts(        is_show=False,        range_color=['blue', 'blue', 'green', 'yellow', 'red']        ),)geo.render_notebook()

在这里插入图片描述

热力图区域都连接成了一大块,想通过VisualMapmin_max_参数来调,效果也不明显。

解决办法

Geo.add()方法中有两个参数:

  • point_size:每个点的大小
  • blur_size:每个点模糊的大小

在热力图绘制的过程中,是根据每个point内的值大小选择渲染的颜色,在热力区域混为一团的时候,我们可以尝试将point_sizeblur_size调小一些,在pyecharts中这两个值的默认值都是20。


来看一下调整后的效果:

在这里插入图片描述


完整代码

import requestsfrom pyecharts.charts import *from pyecharts import options as optsfrom pyecharts.commons.utils import JsCodeURL = 'https://cdn.jsdelivr.net/gh/apache/echarts-website@asf-site/examples/data-gl/asset/data/population.json'data = requests.get(URL).json()# 新建GEO实例geo = Geo(    init_opts=opts.InitOpts(        theme='light',        width='980px',        height='800px'    ))data_pair = []for idx, data_item in enumerate(data):    geo.add_coordinate(idx, data_item[0], data_item[1])    data_pair.append([idx, data_item[2]])    geo.add_schema(    maptype="world",    zoom=1.2,)geo.add(    '',    data_pair,    type_='heatmap',    is_large=True,    blur_size=1,    point_size=2,    label_opts=opts.LabelOpts(is_show=False),    tooltip_opts=opts.TooltipOpts(is_show=False),)geo.set_global_opts(    title_opts=opts.TitleOpts(        title="全球人口热力图", pos_top='3%', pos_left='center',         title_textstyle_opts=opts.TextStyleOpts(color='#00BFFF', font_size=20)        ),    visualmap_opts=opts.VisualMapOpts(        is_show=False,        max_=300,        precision=1,        series_index=0,        range_color=['blue', 'blue', 'green', 'yellow', 'red']        ),)geo.render_notebook()

转载地址:http://beqnn.baihongyu.com/

你可能感兴趣的文章
JAVA基础13——构造器
查看>>
JAVA基础14——this关键字
查看>>
JAVA基础15——方法参数
查看>>
spring boot 实现微信扫码登录
查看>>
内网穿透
查看>>
java微信公众号授权登录
查看>>
java 动态导出excel表单 无模板文件下载
查看>>
java 动态导出excel表单 无模板本地生成
查看>>
spring动态导入无模板excel
查看>>
八大排序之直接插入排序
查看>>
二叉树
查看>>
二叉树
查看>>
入门级Java版学生管理系统
查看>>
javaweb
查看>>
Mybatis-study
查看>>
SpringMVC-study
查看>>
ssmbuild
查看>>
springboot + Mybatis-plus
查看>>
笔记图片
查看>>
记录学习springboot连接阿里云oss使用视频点播
查看>>