目录
Pyecharts是一个用于创建交互式图表的Python库。它基于Echarts,一个强大的JavaScript图表库,Pyecharts允许Python开发者使用Python代码轻松地生成各种类型的图表,包括线性图、饼图、散点图、柱状图、地理地图和热力图等。Pyecharts的目标是使数据可视化变得更加容易,同时保持高度的可定制性。
可以使用Bar函数绘制柱状图。
- from pyecharts.charts import Bar
- from pyecharts import options as opts
- bar = Bar()
- bar.add_xaxis(["衬衫", "毛衣", "领带", "裤子", "风衣", "高跟鞋", "袜子"])
- bar.add_yaxis("商家A", [114, 55, 27, 101, 125, 27, 105])
- bar.add_yaxis("商家B", [57, 134, 137, 129, 145, 60, 49])
- bar.set_global_opts(title_opts = opts.TitleOpts(title = "货品销售情况",subtitle = "A和B公司"))
- bar.render_notebook()
结果图:
- from pyecharts.charts import Bar
- from pyecharts import options as opts
- %matplotlib inline
- bar = Bar()
- bar.add_xaxis(["衬衫", "毛衣", "领带", "裤子", "风衣", "高跟鞋", "袜子"])
- bar.add_yaxis("商家A", [114, 55, 27, 101, 125, 27, 105])
- bar.add_yaxis("商家B", [57, 134, 137, 129, 145, 60, 49])
- bar.set_global_opts(title_opts=opts.TitleOpts(title="货品销售情况",subtitle = "A和B公司"),toolbox_opts = opts.ToolboxOpts(is_show = True))
- bar.set_series_opts(label_opts=opts.LabelOpts(position = "right"))
- bar.reversal_axis()
- bar.render_notebook()
结果图:
右上角有选项可以选择,改变图像样式,例如改成堆叠样式: