pyecharts中的常用可视化工具。
http://pyecharts.org/#/zh-cn/
代码语言:javascript复制from pyecharts import options as opts
from pyecharts.faker import Faker
from pyecharts.charts import Bar, Bar3D, Line, Pie, EffectScatter, Funnel, Geo, Liquid, Radar, WordCloud
from pyecharts.globals import ThemeType, SymbolType
import random
bar = Bar(
init_opts=opts.InitOpts(
theme=ThemeType.PURPLE_PASSION,
width='720px',
height='540px'))
bar.add_xaxis(Faker.choose())
bar.add_yaxis('商家', Faker.values())
# bar.add_yaxis('商家1', Faker.values(), stack='stack1')
# bar.add_yaxis('商家2', Faker.values(), stack='stack1')
# bar.add_yaxis('商家3', Faker.values(), stack='stack2')
# bar.add_yaxis('商家4', Faker.values(), stack='stack2')
bar.set_global_opts(
title_opts=opts.TitleOpts(
title='Bar1',
subtitle='副标题'),
datazoom_opts=[opts.DataZoomOpts()],
xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=30)))
bar.set_series_opts(
label_opts=opts.LabelOpts(is_show=False),
markpoint_opts=opts.MarkPointOpts(
data=[
opts.MarkPointItem(type_='max', name='最大值'),
opts.MarkPointItem(type_='min', name='最小值')
]
),
markline_opts=opts.MarkPointOpts(
data=[
opts.MarkLineItem(type_='average', name='平均值')
]
)
)
bar.reversal_axis()
bar.render()
data = [(i, j, random.randint(0, 12)) for i in range(24) for j in range(6)]
bar3d = Bar3D()
bar3d.add(
"",
data,
xaxis3d_opts=opts.Axis3DOpts(Faker.clock, type_='category'),
yaxis3d_opts=opts.Axis3DOpts(Faker.week_en, type_='category'),
zaxis3d_opts=opts.Axis3DOpts(Faker.week_en, type_='value')
)
bar3d.set_global_opts(
visualmap_opts=opts.VisualMapOpts(max_=20),
title_opts=opts.TitleOpts(title='Bar3D')
)
bar3d.render()
line = Line()
line.add_xaxis(Faker.choose())
line.add_yaxis(
'商家1',
Faker.values(),
is_smooth=True,
areastyle_opts=opts.AreaStyleOpts(
opacity=0.2,
color={
'type': 'linear',
'x': 0,
'y': 0,
'x2': 0,
'x2': 1,
'colorStops': [{
'offset': 0, 'color': 'red'
}, {
'offset': 1, 'color': 'blue'
}]
}
)
)
line.add_yaxis('商家2', Faker.values())
line.set_global_opts(
title_opts=opts.TitleOpts(
title='line1',
subtitle='副标题'
)
)
line.render()
pie = Pie()
pie.add("",
[list(z) for z in zip(Faker.choose(), Faker.values())],
radius=['40%', '75%'],
rosetype="area")
pie.set_global_opts(
title_opts=opts.TitleOpts(
title='Pie1',
subtitle='副标题')
)
pie.set_series_opts(
label_opts=opts.LabelOpts(formatter='{b}:{c}')
)
pie.render()
effect_scatter = EffectScatter()
effect_scatter.add_xaxis(Faker.choose())
effect_scatter.add_yaxis(
'',
Faker.values(),
symbol=SymbolType.ARROW)
effect_scatter.set_global_opts(
title_opts=opts.TitleOpts(
title='effect_scatter2',
subtitle='副标题'
)
)
effect_scatter.render()
funnel = Funnel()
funnel.add(
'用户转化率',
[list(z) for z in zip(Faker.choose(), Faker.values())],
label_opts=opts.LabelOpts(position='inside'))
funnel.set_global_opts(
title_opts=opts.TitleOpts(
title='funnel1',
subtitle='副标题'
)
)
funnel.render()
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='funnel1',
subtitle='副标题'
)
)
geo.render()
liquid = Liquid()
liquid.add('liquid', [0.7, 0.6, 0.5])
liquid.set_global_opts(
title_opts=opts.TitleOpts(
title='funnel1',
subtitle='副标题'
)
)
liquid.render()
radar = Radar()
radar.add_schema(
schema=[
opts.RadarIndicatorItem(name='a', max_=6500),
opts.RadarIndicatorItem(name='b', max_=5500),
opts.RadarIndicatorItem(name='c', max_=4500),
opts.RadarIndicatorItem(name='d', max_=3500),
]
)
# radar.add('G', v1)
# radar.add('H', v)
radar.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
radar.set_global_opts(
title_opts=opts.TitleOpts(
title='funnel1',
subtitle='副标题'
)
)
radar.render()
words = [
('aaaaaaa', 10000),
('bbbb', 20000),
('ccc', 30000)
]
wordcloud = WordCloud()
wordcloud.add('', words, word_size_range=[20, 100])
wordcloud.set_global_opts(
title_opts=opts.TitleOpts(
title='funnel1',
subtitle='副标题'
)
)
wordcloud.render()