1.安装库
pip install pyecharts==1.9.0
pip install snapshot_selenium
2.地图绘制代码实现
from pyecharts.charts import Geo
from pyecharts import options as opts
from pyecharts.render.snapshot import make_snapshot
from snapshot_selenium import snapshot
from pyecharts .globals import ChartType, SymbolType, GeoType
geo_sight_coord = {point.iloc[i,1]: [point.iloc[i,3],point.iloc[i,2]] for i in range(len(point))}
g = Geo(init_opts=opts.InitOpts(width="1800px", height="1000px",))
g.add_schema(maptype="world",zoom=1.2,itemstyle_opts=opts.ItemStyleOpts(color='#333333',border_color='#FFFF22'))
list1 = []
for i in geo_sight_coord:
g.add_coordinate(str(i), geo_sight_coord[i][0], geo_sight_coord[i][1])
list1.append([i, geo_sight_coord[i][0]])
g.add("", list1,symbol_size=10,label_opts=opts.LabelOpts(
position="top",
is_show=True,
formatter='{b}'))
g.set_series_opts(label_opts=opts.LabelOpts(is_show=False,formatter='{b}'))
g.set_global_opts(title_opts=opts.TitleOpts(title="全球地图",pos_left='900px',title_textstyle_opts=opts.TextStyleOpts(font_size=30)))
g.render("data/img/pyecharts_world.html")
3.折线图绘制代码实现
from pyecharts.charts import Line
from pyecharts import options as opts
from pyecharts.render.snapshot import make_snapshot
from snapshot_selenium import snapshot
data=pd.read_csv('data/data.csv')
x=data.columns.to_list()[1:]
line =Line(init_opts=opts.InitOpts(width="1600px", height="900px",))
line.add_xaxis(xaxis_data=x)
for i in range(len(data)):
country=list(data.iloc[i]).pop(0)
y=[str(i) for i in list(data.iloc[i])[1:]]
line.add_yaxis(series_name=country, y_axis=y,symbol='circle',is_smooth = True)
line.set_global_opts(title_opts=opts.TitleOpts(title=title),
legend_opts = opts.LegendOpts(type_="scroll", pos_right="right", orient="vertical"),
xaxis_opts=opts.AxisOpts(name='日期'),
yaxis_opts=opts.AxisOpts(name='人数')
)
line.set_series_opts(
label_opts=opts.LabelOpts(is_show=False)
)
line.render('data/a.html')
4.组合折线图绘制代码实现
def func(data,title,pos_x=None,pos_y=None):
grid = Grid(init_opts=opts.InitOpts(width="1800px", height="900px"))
grid.add(func(data1,'折线图1',"5%","25%"),grid_opts=opts.GridOpts(pos_bottom="60%", pos_left="60%"))
grid.add(func(data2,'折线图2',"5%","75%"),grid_opts=opts.GridOpts(pos_bottom="60%", pos_right="60%"))
grid.add(func(data3,'折线图3',"50%","25%"),grid_opts=opts.GridOpts(pos_top="60%", pos_left="60%") )
grid.add(func(data4,'折线图4',"50%","75%"), grid_opts=opts.GridOpts(pos_top="60%", pos_right="60%"))
grid.render("data/组合图.html")