赞
踩
!pip install pyecharts==1.0
python 3.6
pyecharts 1.0
jupyter notebook
from example.commons import Faker
from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.globals import ChartType, SymbolType
geo = Geo()
geo.add_schema(maptype="china")
geo.add("geo", [list(z) for z in zip(Faker.provinces, Faker.values())])
geo.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
geo.set_global_opts(visualmap_opts=opts.VisualMapOpts(),title_opts=opts.TitleOpts(title="Geo-基本示例"))
geo.render_notebook() #显示地图
geo.render() #输出html格式
add_schema() :控制地图类型、视角中心点等
add():添加图表名称、传入数据集、选择geo图类型、调整图例等
set_series_opts() :系列配置项,可配置图元样式、文字样式、标签样式、点线样式等
set_global_opts() : 全局配置项,可配置标题、动画、坐标轴、图例等
render_notebook() : 在notebook中渲染显示图表
add_coordinate() : 新增一个坐标点
add_coordinate_json() :以json形式新增多个坐标点
get_coordinate() :根据地点查询对应坐标
c = (
Geo()
.add_schema(maptype="china")
.add("geo", [list(z) for z in zip(['江苏','浙江','湖北','湖南','河南'], [22,34,27,53,42])])
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(),
title_opts=opts.TitleOpts(title="全国各省xx数据分布"),
)
)
c.render_notebook()
c = (
Geo()
.add_schema(maptype="北京") #北京作为底图
.add(
"geo",
[list(z) for z in zip(['大兴区','房山区','海淀区','朝阳区','东城区'], [150,100,300,200,500])],
type_=ChartType.EFFECT_SCATTER, #热力图
)
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(),
title_opts=opts.TitleOpts(title="Geo-HeatMap"),
)
)
c.render_notebook()
c = (
Geo()
.add_schema(maptype="北京",
itemstyle_opts=opts.ItemStyleOpts(color="#323c48", border_color="#111")) #修改地图的背景色
.add(
"geo",
[list(z) for z in zip(['大兴区','房山区','海淀区','朝阳区','东城区'], [1500,10,300,20,5])],
)
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
visualmap_opts=opts.VisualMapOpts(),
title_opts=opts.TitleOpts(title="北京市各区县xx数据分布"),
)
)
c.render_notebook()
pyecharts可以生成地理空间流动图,用来表示航班数量、人口流动等等
c = (
Geo()
.add_schema(maptype="china")
.add(
"",
[("深圳", 120), ("哈尔滨", 66), ("杭州", 77), ("重庆", 88), ("上海", 100), ("乌鲁木齐", 30),("北京", 30),("武汉",70)],
type_=ChartType.EFFECT_SCATTER,
color="green",
)
.add(
"geo",
[("北京", "上海"), ("武汉", "深圳"),("重庆", "杭州"),("哈尔滨", "重庆"),("乌鲁木齐", "哈尔滨"),("深圳", "乌鲁木齐"),("武汉", "北京")],
type_=ChartType.LINES,
effect_opts=opts.EffectOpts(
symbol=SymbolType.ARROW, symbol_size=6, color="blue"
),
linestyle_opts=opts.LineStyleOpts(curve=0.2),
)
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(title_opts=opts.TitleOpts(title="全国主要城市航班路线和数量"))
)
c.render_notebook()
from example.commons import Faker # 案例数据
from pyecharts import options as opts #负责图表配置的模块
from pyecharts.charts import Map #地图主要用于地理区域数据的可视化
c = (
Map()
.add("商家A", [list(z) for z in zip(['雁塔区','阎良区','长安区','蓝田县','周至县'], [22,100,27,53,42])], "西安")
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
title_opts=opts.TitleOpts(title="Map-西安"),
visualmap_opts=opts.VisualMapOpts(max_=100),
)
)
c.render_notebook()
c = (
Map()
.add("商家A", [list(z) for z in zip(['西安市','延安市','咸阳市'], [22,100,27])], "陕西")
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
title_opts=opts.TitleOpts(title="Map-陕西"),
visualmap_opts=opts.VisualMapOpts(max_=200),
)
)
c.render_notebook()
c = (
Map()
.add("商家A", [list(z) for z in zip(['江苏','浙江','湖北','湖南','河南'], [22,100,27,53,42])], "china")
.set_global_opts(title_opts=opts.TitleOpts(title="Map-中国地图"),
visualmap_opts=opts.VisualMapOpts(max_=200))
)
c.render_notebook()
c = (
Map()
.add("商家A", [list(z) for z in zip(['China','Canada','Brazil','United States','Russia'], [22,100,27,53,42])], "world")
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
.set_global_opts(
title_opts=opts.TitleOpts(title="Map-世界地图"),
visualmap_opts=opts.VisualMapOpts(max_=200),
)
)
c.render_notebook()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。