pyecharts的折线图与柱状图案例

pyecharts 第一个项目案例(汽车销售)

x_data = Faker.cars
y1_data = [300, 440, 100, 200, 600, 300, 800]
y2_data = [340, 130, 140, 510, 770, 820, 360]
(
    Line(opts.InitOpts(theme=ThemeType.DARK))
    .set_global_opts(
        tooltip_opts=opts.TooltipOpts(is_show=False),
        legend_opts=opts.LegendOpts(
            textstyle_opts=opts.TextStyleOpts(
                color='#90979C'
            )
        ),
        xaxis_opts=opts.AxisOpts(
            axistick_opts=opts.AxisTickOpts(is_show=False)
        ),
        yaxis_opts=opts.AxisOpts(
            type_="value",
            max_=900,
            splitline_opts=opts.SplitLineOpts(
                is_show=True
            )
        )
    )
    .add_xaxis(xaxis_data=x_data)
    .add_yaxis(
        series_name="2020",
        y_axis=y1_data,
        symbol="circle",
        symbol_size=10,
        is_symbol_show=True,
        label_opts=opts.LabelOpts(is_show=True),
        itemstyle_opts=opts.ItemStyleOpts(
            color="#6f7de3"
        )
    )
    .add_yaxis(
        series_name="2021",
        y_axis=y2_data,
        symbol="circle",
        symbol_size=10,
        is_symbol_show=True,
        label_opts=opts.LabelOpts(is_show=True),
        itemstyle_opts=opts.ItemStyleOpts(
            color="#c257F6"
        )
    )
    .render("pyecharts.html")
)

2)pyecharts中, markpoint的使用

import pyecharts.options as opts
from pyecharts.charts import Line
from pyecharts.faker import Faker
from pyecharts.globals import ThemeType

x_data = Faker.cars
y1_data = [300, 440, 100, 200, 600, 300, 800]
y2_data = [340, 130, 140, 510, 770, 820, 360]
(
    Line(opts.InitOpts(bg_color="1A1835"))
    .set_global_opts(
        tooltip_opts=opts.TooltipOpts(is_show=False),
        legend_opts=opts.LegendOpts(
            textstyle_opts=opts.TextStyleOpts(
                color='#90979C'
            )
        ),
        xaxis_opts=opts.AxisOpts(
            type_="category",
            axisline_opts=opts.AxisLineOpts(
                linestyle_opts=opts.LineStyleOpts(
                    color="rgba(204,187,225,0.5)"
                )
            ),
            splitline_opts=opts.SplitLineOpts(
                is_show=False
            ),
            axistick_opts=opts.AxisTickOpts(
                is_show=False
            )
        ),
        yaxis_opts=opts.AxisOpts(
            type_="value",
            max_=900,
            splitline_opts=opts.SplitLineOpts(
                is_show=False
            ),
            axisline_opts=opts.AxisLineOpts(
                linestyle_opts=opts.LineStyleOpts(
                    color="rgba(204,187,225,0.5)"
                )
            )
        )
    )
    .add_xaxis(xaxis_data=x_data)
    .add_yaxis(
        series_name="2020",
        y_axis=y1_data,
        symbol="circle",
        symbol_size=10,
        is_symbol_show=True,
        label_opts=opts.LabelOpts(is_show=True),
        itemstyle_opts=opts.ItemStyleOpts(
            color="#6f7de3"
        ),
        markline_opts=opts.MarkPointOpts(
            label_opts=opts.LabelOpts(
                color="#FFF"
            ),
            data=[opts.MarkPointItem(
                type_="max",
                name="最大值",
            ), opts.MarkPointItem(
                type_="min",
                name="最小值"
            )]
        )
    )
    .add_yaxis(
        series_name="2021",
        y_axis=y2_data,
        symbol="circle",
        symbol_size=10,
        is_symbol_show=True,
        label_opts=opts.LabelOpts(is_show=True),
        itemstyle_opts=opts.ItemStyleOpts(
            color="#c257F6"
        ),
        markline_opts=opts.MarkPointOpts(
            label_opts=opts.LabelOpts(
                color="#FFF"
            ),
            data=[opts.MarkPointItem(
                type_="max",
                name="最大值",
            ), opts.MarkPointItem(
                type_="min",
                name="最小值"
            )]
        )
    )
    .render("pyecharts.html")
)

3)pyecharts中, 柱状图的使用案例

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

x_data = Faker.cars
y1_data = [300, 440, 100, 200, 600, 300, 800]
y2_data = [340, 130, 140, 510, 770, 820, 360]
y3_data = [740, 230, 540, 310, 570, 520, 560]

bar = Bar(init_opts=opts.InitOpts(theme=ThemeType.DARK))
(
    bar.set_global_opts(
        legend_opts=opts.LegendOpts(
            pos_top=12,
            pos_right=10,
            textstyle_opts=opts.TextStyleOpts(
                color="#fff"
            )
        ),
        yaxis_opts=opts.AxisOpts(
            type_="value",
            max_=1000,
            splitline_opts=opts.SplitLineOpts(
                is_show=True,
                linestyle_opts=opts.LineStyleOpts(
                    color="rgba(255,255,255,0.3)"
                )
            )
        )
    )
    .add_xaxis(xaxis_data=x_data)
    .add_yaxis(
        series_name="2019",
        y_axis=y1_data,
    )
    .add_yaxis(
        series_name="2020",
        y_axis=y2_data,
    )
    .add_yaxis(
        series_name="2021",
        y_axis=y3_data,
    )
).render("series_bar.html")

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值