赞
踩
链式调用是Pyecharts常用的程序书写方法,本文以一个简单的实例展示链式调用,同时说明图像的全局配置。
本篇文章使用的版本为: Pyecharts 1.9.1、 Python 3.6+
代码实例如下:
- from pyecharts.charts import Bar
- from pyecharts import options as opts
-
- # 示例数据
- CLOTHES = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
- clothes_v1 = [5, 20, 36, 10, 75, 90]
- clothes_v2 = [10, 25, 8, 60, 20, 80]
-
- # 1.x版本支持的链式调用
- bar = (Bar()
- .add_xaxis(CLOTHES)
- .add_yaxis('clothes_v1', clothes_v1)
- .add_yaxis('clothes_v2', clothes_v1)
- .set_global_opts(title_opts=opts.TitleOpts(title="基本示例", subtitle="副标题"))
- )
- # 在jupyter notebook总渲染
- bar.render_notebook()
通过链式调用,使代码更加简洁,方便查看。
通过set_global_opts()对各个区域进行修改配置,自定义图形界面。
- from pyecharts.charts import Bar
- from pyecharts import options as opts
-
- # 示例数据
- CLOTHES = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
- clothes_v1 = [5, 20, 36, 10, 75, 90]
- clothes_v2 = [10, 25, 8, 60, 20, 80]
-
- # 1.x版本支持链式调用
- bar = (Bar()
- .add_xaxis(CLOTHES)
- .add_yaxis('clothes_v1', clothes_v1)
- .add_yaxis('clothes_v2', clothes_v1)
- .set_global_opts(title_opts=opts.TitleOpts(title="基本示例", subtitle="副标题"),
- legend_opts=opts.LegendOpts(is_show=True),
- toolbox_opts=opts.ToolboxOpts(),
- tooltip_opts=opts.TooltipOpts(),
- visualmap_opts=opts.VisualMapOpts()
- )
- )
- # 在jupyter notebook总渲染
- bar.render_notebook()
可以通过系列配置set_series_opts()
控制图表中的文本,线样式,标记等示例如下:
- from pyecharts.charts import Bar
- from pyecharts import options as opts
-
- # 示例数据
- CLOTHES = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
- clothes_v1 = [5, 20, 36, 10, 75, 90]
- clothes_v2 = [10, 25, 8, 60, 20, 80]
-
- # 1.x版本支持链式调用
- bar = (Bar()
- .add_xaxis(CLOTHES)
- .add_yaxis('clothes_v1', clothes_v1)
- .add_yaxis('clothes_v2', clothes_v1)
- .set_series_opts(label_opts=opts.LabelOpts(is_show=True),
- markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max", name="最大值"),]))
- .set_global_opts(title_opts=opts.TitleOpts(title="基本示例", subtitle="副标题"),
- legend_opts=opts.LegendOpts(is_show=True),
- toolbox_opts=opts.ToolboxOpts(),
-
- tooltip_opts=opts.TooltipOpts(),
- visualmap_opts=opts.VisualMapOpts()
- )
- )
- # 在jupyter notebook总渲染
- bar.render_notebook()
通过set_global_opts()对各个区域进行修改配置,自定义图形界面;
可以通过系列配置set_series_opts()
控制图表中的文本,线样式,标记等.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。