查看当前工作路径
import os
os.getcwd()
导入需要的类库
from pyecharts.charts import *
import pyecharts.options as opts
from pyecharts.globals import ChartType
from commons import Faker # commons是自己的一个脚本文件,放在当前工作路径上
绘制地理图表
geo = (
Geo()
.add_schema(maptype='china')
.add(series_name='',
data_pair=[(i,j) for i,j in zip(Faker.provinces,Faker.values())],
label_opts=opts.LabelOpts(is_show=False),
type_=ChartType.EFFECT_SCATTER) # 热力图类型 type_=ChartType.HEATMAP
.set_global_opts(title_opts=opts.TitleOpts(title='中国地图'),
visualmap_opts=opts.VisualMapOpts(is_piecewise=True))
)
geo.render_notebook()
迁徙图(简单例子)
from pyecharts.charts import Geo
from pyecharts.globals import ChartType,SymbolType
import pyecharts.options as opts
city_num = [('广州',101),('上海',90),('宁夏',66),('北京',70)]
start_end = [('广州','上海'),('广州','宁夏'),('广州','北京')]
(
Geo()
.add_schema(maptype='china',
itemstyle_opts=opts.ItemStyleOpts(color='#313c48',border_color="#111"))
.add(series_name='',data_pair=city_num,color='yellow')
.add(series_name='',data_pair=start_end,type_=ChartType.LINES,
effect_opts=opts.EffectOpts(symbol=SymbolType.ARROW,color='blue',symbol_size=8),label_opts=opts.LabelOpts(is_show=False))
).render_notebook()
广东地图
(
Map()
.add('',[(i,j) for i,j in zip(Faker.guangdong_city,Faker.values())],'广东')
.set_global_opts(visualmap_opts=opts.VisualMapOpts())
).render_notebook()