PyEcharts | 认识图形--地图和地理坐标图
地图
from pyecharts.charts import Map
from pyecharts import options as opts
from pyecharts.faker import Faker
from pyecharts.globals import ThemeType
from pyecharts.globals import CurrentConfig,NotebookType
CurrentConfig.NOTEBOOK_TYPE = NotebookType.JUPYTER_LAB
Faker.provinces
[‘广东省’, ‘北京市’, ‘上海市’, ‘江西省’, ‘湖南省’, ‘浙江省’, ‘江苏省’]
c = (
Map()
.add(
'',
[list(i) for i in zip(Faker.provinces,Faker.values())],
'china',# 地图类型
)
.set_global_opts(
title_opts=opts.TitleOpts(title='地图'),# 设置视觉映射配置项
visualmap_opts=opts.VisualMapOpts(max_=200,is_piecewise=True)
)
)
c.load_javascript()
c.render_notebook()
具体城市图
Faker.guangdong_city
[‘汕头市’, ‘汕尾市’, ‘揭阳市’, ‘阳江市’, ‘肇庆市’, ‘广州市’, ‘惠州市’]
c = (
Map()
.add(
'',
[list(i) for i in zip(Faker.guangdong_city,Faker.values())],
'广东',# 地图类型
)
.set_global_opts(
title_opts=opts.TitleOpts(title='广东地图'),# 设置视觉映射配置项
visualmap_opts=opts.VisualMapOpts()
)
)
c.load_javascript()
c.render_notebook()
世界地图
b = (
Map()
.add(
'',
[list(i) for i in zip(Faker.country,Faker.values())],
'world',# 地图类型
)
.set_global_opts(
title_opts=opts.TitleOpts(title='世界地图'),# 设置视觉映射配置项
visualmap_opts=opts.VisualMapOpts(max_=100,is_piecewise=True)
)
)
b.render_notebook()
地理坐标图
from pyecharts import options as opts
from pyecharts.charts import Geo
from pyecharts.globals import ChartType,SymbolType
from pyecharts.faker import Faker
from pyecharts.globals import CurrentConfig,NotebookType
CurrentConfig.NOTEBOOK_TYPE = NotebookType.JUPYTER_LAB
# .set_series_opts() 和 .set_global_opts() 是两个非常重要的方法,
# 它们分别用于设置图表的系列(series)配置项和全局(global)配置项
c = (
Geo()
# # 添加地图配置项,设置地图类型为 'china'
.add_schema(maptype='china')
.add(
'geo',
[list(i) for i in zip(Faker.provinces,Faker.choose())],
type_=ChartType.EFFECT_SCATTER # 涟漪散点图
)
.set_series_opts(label_opts=opts.LabelOpts(is_show=True))
.set_global_opts(title_opts=opts.TitleOpts(title='Geo + 涟漪散点图'))
)
c.load_javascript()
c.render_notebook()
# .set_series_opts() 和 .set_global_opts() 是两个非常重要的方法,
# 它们分别用于设置图表的系列(series)配置项和全局(global)配置项
c = (
Geo()
# # 添加地图配置项,设置地图类型为 'china'
.add_schema(maptype='china')
.add(
'geo',
[list(i) for i in zip(Faker.provinces,Faker.choose())],
type_=ChartType.HEATMAP # 涟漪散点图
)
.set_series_opts(label_opts=opts.LabelOpts(is_show=True))
.set_global_opts(title_opts=opts.TitleOpts(title='Geo + 热力图'),visualmap_opts=opts.VisualMapOpts())
)
c.render_notebook()
c = (
Geo()
.add_schema(maptype='china')
.add(
'',
[('广州',50),('邢台',80),('杭州',70),('重庆',90),],
type_=ChartType.EFFECT_SCATTER,
color='red'
)
.add(
'',
[('广州','邢台'),('广州','杭州'),('广州','重庆'),('广州','北京')],
type_=ChartType.LINES,
# 箭头设置
effect_opts=opts.EffectOpts(
symbol=SymbolType.ARROW,
symbol_size=6,
color='green'
),
# 弯曲度
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='Geo'))
)
c.render_notebook()
原文地址:https://blog.csdn.net/HG0724/article/details/143526571
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!