python可视化,教你怎么画图表

python可视化库有很多,我个人比较喜欢用pyechart,灵活又简洁,出图也很好看

用python画图的优点是,当你调整好一版配置之后,以后就可以批量出图了,效率杠杠的

柱状图

from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.faker import Faker

c = (
    Bar()
    .add_xaxis(Faker.choose())
    .add_yaxis("商家A", Faker.values())
    .add_yaxis("商家B", Faker.values())
    .set_global_opts(
        title_opts=opts.TitleOpts(title="Bar-Brush示例", subtitle="我是副标题"),
        brush_opts=opts.BrushOpts(),
    )
    .render("bar_with_brush.html")
)

折线图

import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker
c = (
    Line()
    .add_xaxis(Faker.choose())
    .add_yaxis("商家A", Faker.values(), is_smooth=True)
    .add_yaxis("商家B", Faker.values(), is_smooth=True)
    .set_global_opts(title_opts=opts.TitleOpts(title="Line-smooth"))
    .render("line_smooth.html")
)

饼图

from pyecharts import options as opts
from pyecharts.charts import Pie
from pyecharts.faker import Faker
c = (
    Pie()
    .add("", [list(z) for z in zip(Faker.choose(), Faker.values())])
    .set_global_opts(title_opts=opts.TitleOpts(title="Pie-基本示例"))
    .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}"))
    .render("pie_base.html")
)

已发布

分类

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注