pyecharts-12-涟漪图和日历图

2021-03-01 13:26:53 浏览数 (2)

Pyecharts-12-涟漪散点图 日历图

本文中介绍的是如何利用pyecharts来绘制涟漪散点图和日历图,本文是自己依照官网的整理和学习,具体例子请移步至官网

导入库

代码语言:javascript复制
from pyecharts.globals import CurrentConfig, OnlineHostType   # 事先导入,防止不出图
from pyecharts import options as opts
from pyecharts.charts import EffectScatter,Calendar  # 涟漪散点图 日历图
from pyecharts.faker import Faker
from pyecharts.commons.utils import JsCode
from pyecharts.globals import ThemeType
from pyecharts.globals import SymbolType

import datetime
import random
import pandas as pd
import numpy as np

涟漪图-EffectScatter

基本案例
代码语言:javascript复制
c = (
    EffectScatter()
    .add_xaxis(df['子类'].tolist())  # x轴数据
    .add_yaxis("", df['数据'].tolist())  # y轴数据
    .set_global_opts(title_opts=opts.TitleOpts(title="EffectScatter-月度开支"))
)

c.render_notebook()
显示坐标分割线
代码语言:javascript复制
c = (
    EffectScatter()
    .add_xaxis(df['子类'].tolist())  # x轴数据
    .add_yaxis("", df['数据'].tolist())  # y轴数据
    .set_global_opts(
        title_opts=opts.TitleOpts(title="EffectScatter-显示分割线"),
        xaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
        yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(is_show=True)),
    )
)

c.render_notebook()
不同标识
代码语言:javascript复制
c = (
    EffectScatter()
    .add_xaxis(df['子类'].tolist())  # x轴数据
    .add_yaxis("", df['数据'].tolist(),symbol=SymbolType.ARROW)  # y轴数据 标识符
    .set_global_opts(title_opts=opts.TitleOpts(title="EffectScatter-月度开支"))
)

c.render_notebook()

日历图-Calendar

datetime模块使用

关于时间模块的使用,参考之前的文章:3大时间序列

基本案例
代码语言:javascript复制
begin = datetime.date(2019, 1, 1)
end = datetime.date(2019, 12, 31)
data = [
    [str(begin   datetime.timedelta(days=i)), random.randint(2000, 20000)]
    for i in range((end - begin).days   1)
]

c = (
    Calendar()
    .add("", data, calendar_opts=opts.CalendarOpts(range_="2019"))   # 添加数据并且指定年份
    .set_global_opts(
        title_opts=opts.TitleOpts(title="Calendar-2019年微信步数情况"),
        visualmap_opts=opts.VisualMapOpts(
            max_=20000,  # 指定数据范围
            min_=500,
            orient="horizontal",
            is_piecewise=True,
            pos_top="230px",
            pos_left="100px",
        ),
    )
)

c.render_notebook()
Label变成中文
代码语言:javascript复制
begin = datetime.date(2019, 1, 1)
end = datetime.date(2019, 12, 31)
data = [
    [str(begin   datetime.timedelta(days=i)), random.randint(2000, 20000)]
    for i in range((end - begin).days   1)
]

c = (
    Calendar()
    .add(
        "",
        data,
        calendar_opts=opts.CalendarOpts(
            range_="2019",
            daylabel_opts=opts.CalendarDayLabelOpts(name_map="cn"),
            monthlabel_opts=opts.CalendarMonthLabelOpts(name_map="cn"),
        ),
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(title="Calendar-2019年微信步数情况(中文 Label)"),
        visualmap_opts=opts.VisualMapOpts(
            max_=20000,
            min_=500,
            orient="horizontal",
            is_piecewise=True,
            pos_top="230px",
            pos_left="100px",
        ),
    )
)
c.render_notebook()

0 人点赞