前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >pyecharts可视化

pyecharts可视化

作者头像
luxuantao
发布2021-02-24 11:27:19
1.1K0
发布2021-02-24 11:27:19
举报
文章被收录于专栏:Fdu弟中弟

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()
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-04-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档