导入
from pyecharts import Line
from pyecharts import WordCloud
from pyecharts import EffectScatter, Overlap
x_attr = ["1月", "2月", "3月", "4月", "5月", "6月"]
data1 = [5, 20, 36, 10, 75, 90]
data2 = [10, 25, 8, 60, 20, 80]
基础折线示例图
# 折线示例图
line = Line("折线示例图")
line.add('商家1', x_attr, data1, mark_point=['average'])
line.add('商家2', x_attr, data2, is_smooth=True, mark_line=['max', 'average'])
line.render('line.demo.html')
# 折线面积图
line = Line('折线面积示例图')
line.add('商家1', x_attr, data1, is_fill=True,line_opacity=0.2, area_opacity=0.4, symbol=None)
line.add('商家2', x_attr, data2, line_color='#000', area_opacity=0.3, is_smooth=True)
line.render('line2_demo.html')
# 词云图
name = [
'Though', 'the answer', 'this question',
'may at first', 'seem to border', 'on the',
'absurd', 'reflection', 'will show', 'that there',
'is a', 'good deal', 'more in', 'it than meets', 'the eye'
]
value = [10000, 6189, 4556, 2356, 2233,
1895, 1456, 1255, 981, 875,
542, 462, 361, 265, 125]
worldcloud = WordCloud(width=1300, height=620)
worldcloud.add('词云', name, value, word_size_range=[20, 100])
worldcloud.render('worldcloud.html')
# 线性闪烁图
line2 = Line('线性闪烁图')
line2.add('line', x_attr, data1, is_random=True)
es = EffectScatter()
es.add('es', x_attr, data1, effect_scale=8) # 闪烁
overlop = Overlap()
overlop.add(line2) # 必须先添加line 再添加 es
overlop.add(es)
overlop.render('line-es.html')