Python之pyecharts的常见用法2-柱状图-折线图

Pyecharts是一个基于Echarts的Python可视化库,可以用Python语言轻松地生成各种交互式图表和地图。它支持多种图表类型,包括折线图、柱状图、散点图、饼图、地图等,并且可以通过简单的API调用实现数据可视化。

Pyecharts的优点包括:

1. 简单易用:Pyecharts提供了简单易用的API,可以轻松地生成各种图表和地图。

2. 丰富的图表类型:Pyecharts支持多种图表类型,包括折线图、柱状图、散点图、饼图、地图等。

3. 交互式可视化:Pyecharts生成的图表可以进行交互式操作,包括缩放、拖拽、数据筛选等。

4. 支持多种数据格式:Pyecharts支持多种数据格式,包括CSV、JSON、Excel等。

5. 可扩展性强:Pyecharts可以与其他Python库和框架集成,如Pandas、Flask、Django等。

总之,Pyecharts是一个功能强大、易于使用的Python可视化库,可以帮助开发者快速生成各种交互式图表和地图。

今天我们一起看一下Pyecharts常见基础用法,第二课

from pyecharts.charts import Bar  # 柱状图
from pyecharts import options as opts

bar = Bar()
kind = ["哇哈哈","脉动","可乐","雪碧","牛奶"]
data1 = [89,89,78,80,100]
data2 = [50,60,78,90,100]
bar.add_xaxis(kind)
bar.add_yaxis("商家A",data1)
bar.add_yaxis("商家B",data2,category_gap = "60%") # 设置矩形宽度百分比
bar.set_colors(["pink","orange"]) # 颜色取第一个元素
bar.set_global_opts(title_opts=opts.TitleOpts(title="饮料销售"))
bar.render("./bar.html")

1、柱状图

在这里插入图片描述

横向

from pyecharts.charts import Bar  # 柱状图
from pyecharts.charts import Line # 折线图
from pyecharts.globals import SymbolType
from pyecharts import options as opts
bar = Bar()
kind = ["1组","2组","3组","4组月","5组","6组","7组","8组","9组","10组","11组","12组","13组","14组",]
data1 = [5,7,18,5,9,5,2,5,7,1,2,0,2,1]
bar.add_xaxis(kind)
# bar.add_yaxis("商家A",data1)
bar.add_yaxis("数量",data1,category_gap = "60%") # 设置矩形宽度百分比
# bar.set_colors(["blue","green","yellow","red","pink","orange"]) # 颜色取第一个元素
bar.set_global_opts(title_opts=opts.TitleOpts(title="2022创新工具小组维度"))
bar.reversal_axis() # 将坐标轴颠倒
bar.set_series_opts(label_opts=opts.LabelOpts(position="right"))
bar.render("./2022创新工具小组维度.html")

在这里插入图片描述

2、折线图(平滑状)

from pyecharts.charts import Bar  # 柱状图
from pyecharts.charts import Line # 折线图
from pyecharts.globals import SymbolType
from pyecharts import options as opts
line = Line()
data2 = [89,89,78,80,100]
data3 = [78,98,93,85,89]
m = ["1月","2月","3月","4月","5月"]
line.add_xaxis(m)
line.add_yaxis("商家A",data2)
line.add_yaxis("商家B",data3,is_smooth = True)
line.render("./line.html")

在这里插入图片描述

折线图(阶梯状)

from pyecharts.charts import Bar  # 柱状图
from pyecharts.charts import Line # 折线图
from pyecharts.globals import SymbolType
from pyecharts import options as opts
line_2 = Line()
data2 = [89,89,78,80,100]
data3 = [78,98,93,85,89]
m = ["1月","2月","3月","4月","5月"]
line_2.add_xaxis(m)
line_2.add_yaxis("商家A",data2,is_step = True)
line_2.add_yaxis("商家B",data3,is_step = True)
line_2.render("./line_2.html")

在这里插入图片描述

希望对初学者有帮助

致力于办公自动化的小小程序员一枚

希望能得到大家的【一个免费关注】!感谢

猜你喜欢

转载自blog.csdn.net/weixin_42636075/article/details/130984664