Beispiel #1
0
def polar_scatter() -> Polar:
    data = []
    for i in range(360):
        theta = i
        r = theta * theta
        data.append([r, theta])

    print(data)
    save_path = "./polar_demo.csv"
    write_to_csv(data, save_path)

    c = (
        Polar(init_opts=opts.InitOpts(width="1920px",
                                      height="960px",
                                      page_title="Graph-Global AS Core Map",
                                      theme=ThemeType.DARK)).
        add_schema(angleaxis_opts=opts.AngleAxisOpts(
            type_="value", boundary_gap=False, start_angle=0, min_=0,
            max_=360)).add(
                "",
                data,
                type_="scatter",
                # effect_opts=opts.EffectOpts(scale=10, period=5),
                symbol="circle",
                symbol_size=10,
                label_opts=opts.LabelOpts(is_show=False)).set_global_opts(
                    title_opts=opts.TitleOpts(title="Polar Map")))
    return c
def polar(open_file) -> Polar:
    """
    根据定义好的数据格式,利用pyecharts绘制极坐标图,格式为极径、极角(0-360)
    :param open_file:
    :return:
    """
    title_str = str(open_file).strip().split("/")[-1].split(".")[0]
    title_str = "极坐标图<" + title_str + ">"
    # 打开文件读取数据
    data = []
    file_in = open(open_file, "r", encoding="utf-8")
    for line in file_in.readlines():
        line = line.strip().split(",")
        data.append(line)

    c = (Polar(init_opts=opts.InitOpts(
        width="1900px",
        height="900px",
        page_title=title_str,
        theme=ThemeType.DARK)).add_schema(angleaxis_opts=opts.AngleAxisOpts(
            type_="value", boundary_gap=False, start_angle=0, min_=0,
            max_=360)).add(
                "",
                data,
                type_="scatter",
                symbol="circle",
                symbol_size=10,
                label_opts=opts.LabelOpts(is_show=False)).set_global_opts(
                    title_opts=opts.TitleOpts(title=title_str)))
    return c
def drawer2(stage_name, data):
    c_schema = [
        {
            "name": "乐",
            "max": 0.55,
            "min": 0
        },
        {
            "name": "好",
            "max": 0.55,
            "min": 0
        },
        {
            "name": "哀",
            "max": 0.55,
            "min": 0
        },
        {
            "name": '恶',
            "max": 0.55,
            "min": 0
        },
        {
            "name": "惧",
            "max": 0.55,
            "min": 0
        },
    ]
    c = (Radar().set_colors(["#CC3300"]).add_schema(
        schema=c_schema,
        shape="circle",
        center=["50%", "50%"],
        radius="80%",
        angleaxis_opts=opts.AngleAxisOpts(
            min_=0,
            max_=360,
            is_clockwise=False,
            interval=5,
            axistick_opts=opts.AxisTickOpts(is_show=False),
            axislabel_opts=opts.LabelOpts(is_show=False),
            axisline_opts=opts.AxisLineOpts(is_show=False),
            splitline_opts=opts.SplitLineOpts(is_show=False),
        ),
        radiusaxis_opts=opts.RadiusAxisOpts(
            min_=-4,
            max_=4,
            interval=2,
            splitarea_opts=opts.SplitAreaOpts(
                is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)),
        ),
        polar_opts=opts.PolarOpts(),
        splitarea_opt=opts.SplitAreaOpts(is_show=False),
        splitline_opt=opts.SplitLineOpts(is_show=False),
    ).add(
        series_name=stage_name,
        data=data,
        areastyle_opts=opts.AreaStyleOpts(opacity=0.1),
        linestyle_opts=opts.LineStyleOpts(width=3),
    ).render("res\\output\\multi-emotion\\image\\" + stage_name + ".html"))
Beispiel #4
0
def polar_radiusaxis() -> Polar:
    c = (Polar().add_schema(
        radiusaxis_opts=opts.RadiusAxisOpts(data=Faker.week, type_="category"),
        angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True, max_=10),
    ).add("A", [1, 2, 3, 4, 3, 5, 1], type_="bar").set_global_opts(
        title_opts=opts.TitleOpts(title="Polar-RadiusAxis")).set_series_opts(
            label_opts=opts.LabelOpts(is_show=True)))
    return c
Beispiel #5
0
def polar_angleaxis() -> Polar:
    c = (Polar().add_schema(angleaxis_opts=opts.AngleAxisOpts(
        data=Faker.week, type_="category")).add(
            "A", [1, 2, 3, 4, 3, 5, 1], type_="bar", stack="stack0").add(
                "B", [2, 4, 6, 1, 2, 3, 1], type_="bar", stack="stack0").add(
                    "C", [1, 2, 3, 4, 1, 2, 5], type_="bar",
                    stack="stack0").set_global_opts(title_opts=opts.TitleOpts(
                        title="Polar-AngleAxis")))
    return c
Beispiel #6
0
def fengxiang() -> Polar:
    c = (
        Polar()
            .add_schema(angleaxis_opts=opts.AngleAxisOpts(data=['北','东','南','西'], type_="category"))
            .add("A", [1, 2, 3, 4, 3, 5, 1], type_="bar")
            .add("B", [2, 4, 6, 1, 2, 3, 1], type_="bar", stack="stack0")
            .add("C", [1, 2, 3, 4, 1, 2, 5], type_="bar", stack="stack0")
            .set_global_opts(title_opts=opts.TitleOpts(title="风向图"))

    )
    return c
Beispiel #7
0
def polar_flower() -> Polar:
    data = []
    for i in range(361):
        t = i / 180 * math.pi
        r = math.sin(2 * t) * math.cos(2 * t)
        data.append([r, i])
    c = (Polar().add_schema(
        angleaxis_opts=opts.AngleAxisOpts(start_angle=0, min_=0)).add(
            "flower", data,
            label_opts=opts.LabelOpts(is_show=False)).set_global_opts(
                title_opts=opts.TitleOpts(title="Polar-Flower")))
    return c
Beispiel #8
0
def polar_love() -> Polar:
    data = []
    for i in range(101):
        theta = i / 100 * 360
        r = 5 * (1 + math.sin(theta / 180 * math.pi))
        data.append([r, theta])
    hour = [i for i in range(1, 25)]
    c = (Polar().add_schema(angleaxis_opts=opts.AngleAxisOpts(
        data=hour, type_="value", boundary_gap=False, start_angle=0)).add(
            "love", data,
            label_opts=opts.LabelOpts(is_show=False)).set_global_opts(
                title_opts=opts.TitleOpts(title="Polar-Love")))
    return c
Beispiel #9
0
def test_radar_options(fake_writer):
    c = (Radar().add_schema(
        schema=[
            opts.RadarIndicatorItem(name="销售", max_=6500),
            opts.RadarIndicatorItem(name="管理", max_=16000),
            opts.RadarIndicatorItem(name="信息技术", max_=30000),
            opts.RadarIndicatorItem(name="客服", max_=38000),
            opts.RadarIndicatorItem(name="研发", max_=52000),
            opts.RadarIndicatorItem(name="市场", max_=25000),
        ],
        radiusaxis_opts=opts.RadiusAxisOpts(),
        angleaxis_opts=opts.AngleAxisOpts(),
        polar_opts=opts.PolarOpts(),
    ).add("预算分配", v1).add(
        "实际开销", v2).set_series_opts(label_opts=opts.LabelOpts(is_show=False)))
    c.render()
    _, content = fake_writer.call_args[0]
    assert_in("radiusAxis", content)
    assert_in("angleAxis", content)
    assert_in("polar", content)
Beispiel #10
0
def polar_scatter() -> Polar:
    data = []
    for i in range(1001):
        theta = i / 100 * 360
        r = random.randint(1, 100) * (1 + math.sin(theta / 180 * math.pi))
        data.append([r, theta])

    print(data)
    c = (
        Polar(init_opts=opts.InitOpts(width="1920px",
                                      height="960px",
                                      page_title="Graph-Global AS Core Map",
                                      theme=ThemeType.DARK)).
        add_schema(angleaxis_opts=opts.AngleAxisOpts(
            type_="value", boundary_gap=False, start_angle=0, min_=0,
            max_=360)).add(
                "",
                data,
                type_="scatter",
                # effect_opts=opts.EffectOpts(scale=10, period=5),
                symbol="arrow",
                label_opts=opts.LabelOpts(is_show=False)).set_global_opts(
                    title_opts=opts.TitleOpts(title="Polar Map")))
    return c
Beispiel #11
0
import math
import pyecharts.options as opts
from pyecharts.charts import Polar
"""
Gallery 使用 pyecharts 1.1.0
参考地址: https://www.echartsjs.com/examples/editor.html?c=line-polar
目前无法实现的功能:
1、赞无
"""

data = []

for i in range(0, 101):
    theta = i / 100 * 360
    r = 5 * (1 + math.sin(theta / 180 * math.pi))
    data.append([r, theta])

(Polar(init_opts=opts.InitOpts(width="1600px", height="800px")).add(
    series_name="line", data=data, label_opts=opts.LabelOpts(
        is_show=False)).add_schema(angleaxis_opts=opts.AngleAxisOpts(
            start_angle=0, type_="value", is_clockwise=True)).set_global_opts(
                tooltip_opts=opts.TooltipOpts(trigger="axis",
                                              axis_pointer_type="cross"),
                title_opts=opts.TitleOpts(title="极坐标双数值轴"),
            ).render("render/two_value_axes_in_polar.html"))
Beispiel #12
0
from pyecharts import options as opts
from pyecharts.charts import Polar
from pyecharts.faker import Faker

c = (
    Polar()
    .add_schema(
        radiusaxis_opts=opts.RadiusAxisOpts(data=Faker.week, type_="category"),
        angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True, max_=10),
    )
    .add("A", [1, 2, 3, 4, 3, 5, 1], type_="bar")
    .set_global_opts(title_opts=opts.TitleOpts(title="Polar-RadiusAxis"))
    .set_series_opts(label_opts=opts.LabelOpts(is_show=True))
    .render("Polar_radius.html")
)
Beispiel #13
0
def show_pyecharts():

    x_data = [
        '0.0', '0.1', '0.2', '0.3', '0.4', '0.5', '0.6', '0.7', '0.8', '0.9',
        '1.0'
    ]
    y_data = [
        '1533', '573', '502', '491', '520', '556', '577', '788', '1252',
        '20564', '6393'
    ]

    #情感分析柱状图
    bar = (Bar().add_xaxis(x_data).add_yaxis(
        "情感分析",
        y_data,
        label_opts=opts.LabelOpts(is_show=False),
        color='#3498DB').set_global_opts(title_opts={
            "text": "台海舆论情感分析",
            "subtext": "大于0.5为正面评价,小于0.5为负面评价"
        }))

    #台湾网饼图
    x_data2 = [
        "文化", "经贸", "媒体专栏", "网友专栏", "两岸专家", "两岸", "台商", "部委", "台海时事", "网友快言",
        "海峡时评", "两岸快评"
    ]
    y_data2 = [553, 553, 35, 39, 448, 465, 553, 321, 553, 406, 553, 556]

    pie = (Pie(init_opts=opts.InitOpts(theme=ThemeType.CHALK)).add(
        series_name="中国台湾网",
        data_pair=[list(z) for z in zip(x_data2, y_data2)],
        radius=["50%", "70%"],
        label_opts=opts.LabelOpts(is_show=False, position="center"),
    ).set_colors([
        "#E8F8F5", "#D1F2EB", "#A3E4D7", "#76D7C4", "#48C9B0", "#1ABC9C",
        "#17A589", "#148F77", "#117864", "#0E6251F", "#73C6B6", "#45B39D"
    ]).set_global_opts(legend_opts=opts.LegendOpts(
        pos_left="legft", orient="vertical")).set_series_opts(
            tooltip_opts=opts.TooltipOpts(
                trigger="item", formatter="{a} <br/>{b}: {c} ({d}%)"), ))

    #词云图
    word = (WordCloud().add(
        "",
        list1,
        word_size_range=[20, 100],
        shape=SymbolType.DIAMOND,
        textstyle_opts=opts.TextStyleOpts(font_family="cursive"),
    ))

    #折线图1
    y2[0], y2[1], y2[2] = None, None, None
    y4[1] = None
    line = (Line().add_xaxis(xaxis_data=x1).add_yaxis(
        series_name="微博",
        symbol="emptyCircle",
        is_symbol_show=True,
        color="#F2D7D5",
        y_axis=y1,
        label_opts=opts.LabelOpts(is_show=False),
        linestyle_opts=opts.LineStyleOpts(width=3)).add_yaxis(
            series_name="环球网",
            symbol="emptyCircle",
            is_symbol_show=True,
            color="#C0392B",
            y_axis=y2,
            label_opts=opts.LabelOpts(is_show=False),
            linestyle_opts=opts.LineStyleOpts(width=3)).add_yaxis(
                series_name="中国台湾网",
                symbol="emptyCircle",
                is_symbol_show=True,
                color="#641E16",
                y_axis=y3,
                label_opts=opts.LabelOpts(is_show=False),
                linestyle_opts=opts.LineStyleOpts(width=3)).add_yaxis(
                    series_name="知乎",
                    symbol="emptyCircle",
                    is_symbol_show=True,
                    color="#9B59B6",
                    y_axis=y4,
                    label_opts=opts.LabelOpts(is_show=False),
                    linestyle_opts=opts.LineStyleOpts(width=3)).add_yaxis(
                        series_name="中国日报网",
                        symbol="emptyCircle",
                        is_symbol_show=True,
                        color="#512E5F",
                        y_axis=y5,
                        label_opts=opts.LabelOpts(is_show=False),
                        linestyle_opts=opts.LineStyleOpts(width=3)).add_yaxis(
                            series_name="中新网",
                            symbol="emptyCircle",
                            is_symbol_show=True,
                            color="#2980B9",
                            y_axis=y6,
                            label_opts=opts.LabelOpts(is_show=False),
                            linestyle_opts=opts.LineStyleOpts(width=3)).
            add_yaxis(
                series_name="今日头条",
                symbol="emptyCircle",
                is_symbol_show=True,
                color="#154360",
                y_axis=y7,
                label_opts=opts.LabelOpts(is_show=False),
                linestyle_opts=opts.LineStyleOpts(width=3)).add_yaxis(
                    series_name="光明网",
                    symbol="emptyCircle",
                    is_symbol_show=True,
                    color="#3498DB",
                    y_axis=y8,
                    label_opts=opts.LabelOpts(is_show=False),
                    linestyle_opts=opts.LineStyleOpts(width=3)).add_yaxis(
                        series_name="凤凰网",
                        symbol="emptyCircle",
                        is_symbol_show=True,
                        color="#1ABC9C",
                        y_axis=y9,
                        label_opts=opts.LabelOpts(is_show=False),
                        linestyle_opts=opts.LineStyleOpts(width=3)).add_yaxis(
                            series_name="新华网",
                            symbol="emptyCircle",
                            is_symbol_show=True,
                            color="#0E6251",
                            y_axis=y10,
                            label_opts=opts.LabelOpts(is_show=False),
                            linestyle_opts=opts.LineStyleOpts(
                                width=3)).set_global_opts(
                                    tooltip_opts=opts.TooltipOpts(
                                        trigger="axis"),
                                    yaxis_opts=opts.AxisOpts(
                                        type_="value",
                                        axistick_opts=opts.AxisTickOpts(
                                            is_show=True),
                                        splitline_opts=opts.SplitLineOpts(
                                            is_show=True),
                                    ),
                                    xaxis_opts=opts.AxisOpts(
                                        type_="category",
                                        boundary_gap=False,
                                        axisline_opts=opts.AxisLineOpts(
                                            is_on_zero=False,
                                            linestyle_opts=opts.LineStyleOpts(
                                                color="#d14a61"))),
                                ))

    #平台占比饼图
    x_data3 = [
        "微博", "知乎", "中国台湾网", "环球网", "日报网", "中新网", "今日头条", "光明网", "凤凰网", "新华网"
    ]
    y_data3 = [5401, 157, 5035, 3245, 4296, 5574, 1891, 3131, 1052, 1997]
    data_pair = [list(z) for z in zip(x_data3, y_data3)]
    data_pair.sort(key=lambda x: x[1])

    pie2 = (Pie(init_opts=opts.InitOpts(theme=ThemeType.ROMA)).add(
        series_name="访问来源",
        data_pair=data_pair,
        rosetype="radius",
        radius="55%",
        center=["50%", "50%"],
        label_opts=opts.LabelOpts(is_show=False, position="center"),
    ).set_series_opts(label_opts=opts.LabelOpts(formatter="{b}:{d}%")))

    #折线图2
    line2 = (Line().add_xaxis(xaxis_data=x_data4).add_yaxis(
        series_name="热度走势",
        y_axis=y_data4,
        color="#FF69B4",
        markpoint_opts=opts.MarkPointOpts(
            data=[opts.MarkPointItem(type_="max")]),
        symbol="emptyCircle",
        is_symbol_show=True,
        is_smooth=True,
        label_opts=opts.LabelOpts(is_show=True),
    ).set_global_opts(
        tooltip_opts=opts.TooltipOpts(is_show=False),
        yaxis_opts=opts.AxisOpts(
            type_="value",
            axistick_opts=opts.AxisTickOpts(is_show=True),
            splitline_opts=opts.SplitLineOpts(is_show=True),
        ),
        xaxis_opts=opts.AxisOpts(type_="category",
                                 boundary_gap=False,
                                 axislabel_opts=opts.LabelOpts(rotate=45)),
    ))

    #条形图
    line3 = (Bar().add_xaxis(x_data5).add_yaxis(
        "平均值",
        y_data5,
        label_opts=opts.LabelOpts(is_show=False),
        color='#6A5ACD').reversal_axis().extend_axis(yaxis=opts.AxisOpts(
            type_='value',
            name='转发次数',
            position='left',
        )).set_global_opts(
            title_opts={"text": "评论与转发关系图"},
            xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(
                formatter='{value}(评论数量)')),
        ))

    #圆
    radius = (Polar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT)).add_schema(
        radiusaxis_opts=opts.RadiusAxisOpts(data=x_data6, type_="category"),
        angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True, max_=100000),
    ).add("点赞数量", y_data6, type_="bar").set_global_opts(
        title_opts=opts.TitleOpts(title="")).set_series_opts(
            label_opts=opts.LabelOpts(is_show=True)))

    return render_template("index2.html",
                           bar_data=bar.dump_options(),
                           word_data=word.dump_options(),
                           pie_data=pie.dump_options(),
                           pie2_data=pie2.dump_options(),
                           line_data=line.dump_options(),
                           line2_data=line2.dump_options(),
                           line3_data=line3.dump_options(),
                           radius_data=radius.dump_options())
import math

from pyecharts import options as opts
from pyecharts.charts import Polar

data = []
for i in range(361):
    t = i / 180 * math.pi
    r = math.sin(2 * t) * math.cos(2 * t)
    data.append([r, i])
c = (Polar().add_schema(
    angleaxis_opts=opts.AngleAxisOpts(start_angle=0, min_=0)).add(
        "flower", data, label_opts=opts.LabelOpts(
            is_show=False)).set_global_opts(title_opts=opts.TitleOpts(
                title="Polar-Flower")).render("polar_flower.html"))
import math

from pyecharts import options as opts
from pyecharts.charts import Polar

data = []
for i in range(361):
    t = i / 180 * math.pi
    r = math.sin(2 * t) * math.cos(2 * t)
    data.append([r, i])
c = (
    Polar()
    .add_schema(angleaxis_opts=opts.AngleAxisOpts(start_angle=0, min_=0))
    .add("flower", data, label_opts=opts.LabelOpts(is_show=False))
    .set_global_opts(title_opts=opts.TitleOpts(title="Polar-Flower"))
    .render("Polar_flower.html")
)
Beispiel #16
0
    "parallel",
    data,
).set_global_opts(title_opts=opts.TitleOpts(
    title="Parallel-Category")).render("parallel_category.html"))

# Section3 极坐标系
# 爱心图
import math
from pyecharts.charts import Polar
data = []
for i in range(101):
    theta = i / 100 * 360
    r = 5 * (1 + math.sin(theta / 180 * math.pi))
    data.append([r, theta])
hour = [i for i in range(1, 15)]
c = (Polar().add_schema(angleaxis_opts=opts.AngleAxisOpts(start_angle=0)).add(
    "love", data, label_opts=opts.LabelOpts(is_show=False)).set_global_opts(
        title_opts=opts.TitleOpts(
            title="Polar-Love")).render("polar_love.html"))

# 水溅的效果
import random
data = [(i, random.randint(1, 100)) for i in range(10)]
c = (Polar().add(
    "",
    data,
    type_="effectScatter",
    effect_opts=opts.EffectOpts(scale=10, period=5),
    label_opts=opts.LabelOpts(is_show=False),
).set_global_opts(title_opts=opts.TitleOpts(
    title="Polar-EffectScatter")).render("polar_effectscatter.html"))
Beispiel #17
0
        )
    )
}

# %% [markdown]
# ### Utils Options
AXLINE = {
    "standard": opts.AxisLineOpts(
        linestyle_opts=LINE["standard"]
    )
}
ANGLEAX = {
    "value": opts.AngleAxisOpts(
        type_="value",
        boundary_gap=True,
        start_angle=90,
        is_clockwise=True,
        interval=90,
        max_=360
    ),
    "category": lambda x: opts.AngleAxisOpts(
        data=x,
        type_="category",
        boundary_gap=True,
        start_angle=0,
        is_clockwise=True
    )
}
RADIUSAX = {
    "value": opts.RadiusAxisOpts(
        type_="value",
        boundary_gap=True,
Beispiel #18
0
boxplot.render_notebook()

# %% [markdown]
# ### Polar -- 极坐标

import math
data=[]
# 生成数据,满足格式`[r, \theta]`,即可以认为角度为自变量、径向为因变量
for i in range(0, 360):
    data.append([100 * math.sin(i/180 * math.pi), i])
polar = Polar()
polar.add("", data)
# 调整角度坐标轴样式
polar.add_schema(
    angleaxis_opts=opts.AngleAxisOpts(
        interval=90,
        max_=360
    )
)
polar.render_notebook()

# %% [markdown]
# #### 极坐标柱状图

polar = Polar()
polar.add("", list(zip(Faker.choose(), Faker.values())), type_="bar")
polar.add_schema(
    radiusaxis_opts=opts.RadiusAxisOpts(type_="category"),
    angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True)
)
polar.render_notebook()
Beispiel #19
0
    {
        "name": "市场",
        "max": 4,
        "min": -4
    },
]
c = (Radar().set_colors(["#4587E7"]).add_schema(
    schema=c_schema,
    shape="circle",
    center=["50%", "50%"],
    radius="80%",
    angleaxis_opts=opts.AngleAxisOpts(
        min_=0,
        max_=360,
        is_clockwise=False,
        interval=5,
        axistick_opts=opts.AxisTickOpts(is_show=False),
        axislabel_opts=opts.LabelOpts(is_show=False),
        axisline_opts=opts.AxisLineOpts(is_show=False),
        splitline_opts=opts.SplitLineOpts(is_show=False),
    ),
    radiusaxis_opts=opts.RadiusAxisOpts(
        min_=-4,
        max_=4,
        interval=2,
        splitarea_opts=opts.SplitAreaOpts(
            is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)),
    ),
    polar_opts=opts.PolarOpts(),
    splitarea_opt=opts.SplitAreaOpts(is_show=False),
    splitline_opt=opts.SplitLineOpts(is_show=False),
).add(
Beispiel #20
0
def radar_angle_radius_axis_opts() -> Radar:
    data = [
        {
            "value": [4, -4, 2, 3, 0, 1],
            "name": "预算分配"
        },
    ]
    c_schema = [
        {
            "name": "销售",
            "max": 4,
            "min": -4
        },
        {
            "name": "管理",
            "max": 4,
            "min": -4
        },
        {
            "name": "技术",
            "max": 4,
            "min": -4
        },
        {
            "name": "客服",
            "max": 4,
            "min": -4
        },
        {
            "name": "研发",
            "max": 4,
            "min": -4
        },
        {
            "name": "市场",
            "max": 4,
            "min": -4
        },
    ]
    c = (Radar().set_colors(["#4587E7"]).add_schema(
        schema=c_schema,
        shape="circle",
        center=["50%", "50%"],
        radius="80%",
        angleaxis_opts=opts.AngleAxisOpts(
            min_=0,
            max_=360,
            is_clockwise=False,
            interval=5,
            axistick_opts=opts.AxisTickOpts(is_show=False),
            axislabel_opts=opts.LabelOpts(is_show=False),
            axisline_opts=opts.AxisLineOpts(is_show=False),
            splitline_opts=opts.SplitLineOpts(is_show=False),
        ),
        radiusaxis_opts=opts.RadiusAxisOpts(
            min_=-4,
            max_=4,
            interval=2,
            splitarea_opts=opts.SplitAreaOpts(
                is_show=True,
                areastyle_opts=opts.AreaStyleOpts(opacity=1),
            )),
        polar_opts=opts.PolarOpts(),
        splitarea_opt=opts.SplitAreaOpts(is_show=False),
        splitline_opt=opts.SplitLineOpts(is_show=False),
    ).add(
        series_name="预算",
        data=data,
        areastyle_opts=opts.AreaStyleOpts(opacity=0.1),
        linestyle_opts=opts.LineStyleOpts(width=1),
    ))
    return c
Beispiel #21
0
) #初始化雷达图
r.add_js_funcs(
    """
    var img = new Image(); img.src = 'a5.png';
    """
) #执行js代码

(
    r.add_schema(
        schema=myschema,
        shape="circle", #图片形状
        center=["50%", "50%"], #图片中心位置
        radius="80%", #图片半径大小
        angleaxis_opts=opts.AngleAxisOpts(
            axistick_opts=opts.AxisTickOpts(is_show=False),
            axislabel_opts=opts.LabelOpts(is_show=False),
            splitline_opts=opts.SplitLineOpts(is_show=False),
        ),
        radiusaxis_opts=opts.RadiusAxisOpts(
            min_=0,
            max_=7,
            interval=1,
            splitarea_opts=opts.SplitAreaOpts(
                is_show=True, areastyle_opts=opts.AreaStyleOpts(opacity=1)
            ),
            splitline_opts=opts.series_options.SplitLineOpts(is_show=True, linestyle_opts={'color':'grey','opacity':0.8})   
            
        ),
        polar_opts=opts.PolarOpts(),
        splitline_opt=opts.SplitLineOpts(is_show=False),
        textstyle_opts=opts.TextStyleOpts(color="black"),
Beispiel #22
0
def Radar_pic(name, datas, ifratio) -> Radar:
    color = ["#ff7f00"] if ifratio else ["#4587E7"]
    data = [{"value": datas, "name": name}]
    watermax = 1000 if datas[0] < 1000 else datas[0] * 1.1
    mountainmax = 1000 if datas[1] < 1000 else datas[1] * 1.1
    corridormax = 1000 if datas[2] < 1000 else datas[2] * 1.1
    secondmax = 250 if datas[3] < 250 else datas[3] * 1.1
    intermax = 500 if datas[4] < 500 else datas[4] * 1.1
    landscapemax = 250 if datas[5] < 250 else datas[5] * 1.1
    mainmax = 250 if datas[6] < 250 else datas[6] * 1.1
    othermax = 450 if datas[7] < 450 else datas[7] * 1.1

    waterratio = 0.25 if datas[0] < 0.25 else datas[0] * 1.2
    mountainratio = 0.25 if datas[1] < 0.25 else datas[1] * 1.1

    c_schema = [
        {
            "name": "主水",
            "max": round(waterratio, 2) if ifratio else round(watermax)
        },
        {
            "name": "主山",
            "max": round(mountainratio, 2) if ifratio else round(mountainmax)
        },
        {
            "name": "廊道",
            "max": 0.25 if ifratio else round(corridormax)
        },
        {
            "name": "次路",
            "max": 0.20 if ifratio else round(secondmax)
        },
        {
            "name": "夹层",
            "max": 0.20 if ifratio else round(intermax)
        },
        {
            "name": "主景观建筑",
            "max": 0.20 if ifratio else round(landscapemax)
        },
        {
            "name": "主厅",
            "max": 0.20 if ifratio else round(mainmax)
        },
        {
            "name": "其他建筑",
            "max": 0.20 if ifratio else round(othermax)
        },
    ]

    c = (
        Radar().set_colors(color).add_schema(
            schema=c_schema,
            shape="circle",
            # 图片中心位置
            center=["50%", "50%"],
            # 雷达图半径大小
            radius="80%",
            angleaxis_opts=opts.AngleAxisOpts(
                # 径向轴大小
                # min_=0,
                # max_=360,
                # is_clockwise=False,
                # 径向轴间隔大小
                interval=4,
                axistick_opts=opts.AxisTickOpts(is_show=False),
                axislabel_opts=opts.LabelOpts(is_show=False),
                axisline_opts=opts.AxisLineOpts(is_show=False),
                splitline_opts=opts.SplitLineOpts(is_show=False),
            ),
            textstyle_opts=opts.TextStyleOpts(font_size=20),
            radiusaxis_opts=opts.RadiusAxisOpts(
                min_=0,
                max_=1000,
                interval=200,
                splitarea_opts=opts.SplitAreaOpts(
                    is_show=False,
                    areastyle_opts=opts.AreaStyleOpts(opacity=1)),
            ),
            polar_opts=opts.PolarOpts(),
            splitarea_opt=opts.SplitAreaOpts(is_show=False),
            splitline_opt=opts.SplitLineOpts(is_show=False),
        ).add(
            series_name=name,
            data=data,
            # 透明度
            areastyle_opts=opts.AreaStyleOpts(opacity=0.2),
            # 线宽
            linestyle_opts=opts.LineStyleOpts(width=2),
            label_opts=opts.LabelOpts(font_size=20)).set_global_opts(
                title_opts=opts.TitleOpts(
                    title=name,
                    pos_left="22%",
                    pos_top="10",
                ),
                legend_opts=opts.LegendOpts(pos_right=10)))
    return c
def polarChart(df):
     type_of_plot = st.selectbox("Select Type of Plot",["POLAR1","POLAR2","POLAR3 Angle"])
     all_columns = df.columns
    
        
        #st.success("Generating Customizable Plot of {} for {}".format(type_of_plot))
        
     if type_of_plot == 'POLAR1':
           
            columns_to_plot = st.selectbox("Select 1 column",all_columns,key='a' )
            
            columns_to_plot1 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot]], key='b' )
        # columns_to_plot2 = st.selectbox("Select 1 column",all_columns, key='c' )
            n = df[[columns_to_plot, columns_to_plot1]].sort_values(by = columns_to_plot1 , ascending = True)
            cje = n[columns_to_plot].tolist()
            other_var = n[columns_to_plot1].tolist()
          
           
            # cje = df[columns_to_plot].tolist()
            # other_var = df[columns_to_plot1].sort_values(ascending = True).tolist()
        # other_var1 = df[columns_to_plot2].tolist()
            polar = Polar()
            polar.add_schema( 
       radiusaxis_opts=opts.RadiusAxisOpts( data = cje ,type_="category",
                                                splitline_opts=opts.SplitLineOpts(is_show=False),
                                                axisline_opts=opts.AxisLineOpts(is_show=False),
                                                axistick_opts=opts.AxisTickOpts(is_show=False)),
            angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True,
                                              splitline_opts=opts.SplitLineOpts(is_show=False),
                                              axisline_opts=opts.AxisLineOpts(is_show=False),
                                              axislabel_opts=opts.LabelOpts(is_show=False),
                                              axistick_opts=opts.AxisTickOpts(is_show=False)))
            polar.add(columns_to_plot1, other_var, type_="bar")
            polar.set_global_opts(toolbox_opts=opts.ToolboxOpts())
            polar.set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='inside', font_size=8,
                                                            font_weight='bold'))
                             
            return polar
        
        
        
     if type_of_plot == 'POLAR2':
            columns_to_plot = st.selectbox("Select 1 column",all_columns,key='a' )
            columns_to_plot1 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot]], key='b' )
            columns_to_plot2 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot1, columns_to_plot]], key='c' )
            columns_to_plot3 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot1, columns_to_plot2,columns_to_plot]], key='c' )
            columns_to_plot4 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot1, columns_to_plot2,columns_to_plot, columns_to_plot3]], key='c' )
            n = df[[columns_to_plot, columns_to_plot1, columns_to_plot2, columns_to_plot3, columns_to_plot4]].sort_values(by = columns_to_plot1 , ascending = True)
            
            cje = n[columns_to_plot].tolist()
            other_var = n[columns_to_plot1].tolist()
            other_var2 = n[columns_to_plot2].tolist()
            other_var3 = n[columns_to_plot3].tolist()
            other_var4 = n[columns_to_plot4].tolist()
          

            polar = Polar()
            polar.add_schema( 
       radiusaxis_opts=opts.RadiusAxisOpts( data = cje ,type_= "category",
                                                splitline_opts=opts.SplitLineOpts(is_show=False),
                                                axisline_opts=opts.AxisLineOpts(is_show=False),
                                                axistick_opts=opts.AxisTickOpts(is_show=False)),
            angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True,
                                              splitline_opts=opts.SplitLineOpts(is_show=False),
                                              axisline_opts=opts.AxisLineOpts(is_show=False),
                                              axislabel_opts=opts.LabelOpts(is_show=False),
                                              axistick_opts=opts.AxisTickOpts(is_show=False)))
            polar.add(columns_to_plot1, other_var, type_="bar" )
            polar.add(columns_to_plot2, other_var2, type_="bar")
            polar.add(columns_to_plot3, other_var3, type_="bar")
            polar.add(columns_to_plot4, other_var4, type_="bar")
            polar.set_global_opts(toolbox_opts=opts.ToolboxOpts(),)
            polar.set_series_opts(label_opts=opts.LabelOpts(is_show=True))
       
            return polar
        
     if type_of_plot == 'POLAR3 Angle':
            columns_to_plot = st.selectbox("Select 1 column",all_columns,key='a' )
            columns_to_plot1 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot]], key='b' )
            columns_to_plot2 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot1, columns_to_plot]], key='c' )
            columns_to_plot3 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot1, columns_to_plot2,columns_to_plot]], key='c' )
            columns_to_plot4 = st.selectbox("Select 1 column",[col for col in df.columns if col not in [columns_to_plot1, columns_to_plot2,columns_to_plot, columns_to_plot3]], key='c' )
            n = df[[columns_to_plot, columns_to_plot1, columns_to_plot2, columns_to_plot3, columns_to_plot4]].sort_values(by = columns_to_plot1 , ascending = True)
            
            cje = n[columns_to_plot].tolist()
            other_var = n[columns_to_plot1].tolist()
            other_var2 = n[columns_to_plot2].tolist()
            other_var3 = n[columns_to_plot3].tolist()
            other_var4 = n[columns_to_plot4].tolist()
          

            polar = Polar()
            polar.add_schema( 
    #    radiusaxis_opts=opts.RadiusAxisOpts( data = cje ,type_= "category",
    #                                             splitline_opts=opts.SplitLineOpts(is_show=False),
    #                                             axisline_opts=opts.AxisLineOpts(is_show=False),
    #                                             axistick_opts=opts.AxisTickOpts(is_show=False)),
            angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True,type_= "category",
                                              splitline_opts=opts.SplitLineOpts(is_show=False),
                                              axisline_opts=opts.AxisLineOpts(is_show=False),
                                              axislabel_opts=opts.LabelOpts(is_show=False),
                                              axistick_opts=opts.AxisTickOpts(is_show=False)))
            polar.add(columns_to_plot1, other_var, type_="bar", stack="stack0" )
            polar.add(columns_to_plot2, other_var2, type_="bar" , stack="stack0")
            polar.add(columns_to_plot3, other_var3, type_="bar" , stack="stack0")
            polar.add(columns_to_plot4, other_var4, type_="bar" , stack="stack0")
            polar.set_global_opts(toolbox_opts=opts.ToolboxOpts())
            polar.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
       
            return polar
Beispiel #24
0
def pyecharts():
    from pyecharts.charts import Bar
    from pyecharts.faker import Faker
    from pyecharts import options as opts
    from pyecharts.charts import Polar
    from pyecharts.charts import HeatMap
    from pyecharts.charts import Tree

    r1 = ['草莓', '芒果', '葡萄', '雪梨', '西瓜', '柠檬', '车厘子']
    r2 = [127, 33, 110, 29, 146, 121, 36]
    r3 = [25, 87, 114, 131, 130, 94, 146]
    c1 = (Bar({
        "width": "100%"
    }).add_xaxis(r1).add_yaxis("商家A", r2).add_yaxis("商家B", r3).set_global_opts(
        title_opts=opts.TitleOpts(title="Bar-基本示例", subtitle="我是副标题")))

    c2 = (Polar({
        "width": "100%"
    }).add_schema(
        radiusaxis_opts=opts.RadiusAxisOpts(data=Faker.week, type_="category"),
        angleaxis_opts=opts.AngleAxisOpts(is_clockwise=True, max_=10),
    ).add("A", [1, 2, 3, 4, 3, 5, 1], type_="bar").set_global_opts(
        title_opts=opts.TitleOpts(title="Polar-RadiusAxis")).set_series_opts(
            label_opts=opts.LabelOpts(is_show=True)))

    data = [{
        "children": [
            {
                "name": "B"
            },
            {
                "children": [{
                    "children": [{
                        "name": "I"
                    }],
                    "name": "E"
                }, {
                    "name": "F"
                }],
                "name":
                "C",
            },
            {
                "children": [
                    {
                        "children": [{
                            "name": "J"
                        }, {
                            "name": "K"
                        }],
                        "name": "G"
                    },
                    {
                        "name": "H"
                    },
                ],
                "name":
                "D",
            },
        ],
        "name":
        "A",
    }]

    c3 = (Tree({
        "width": "100%"
    }).add("",
           data).set_global_opts(title_opts=opts.TitleOpts(title="Tree-基本示例")))

    value = [[i, j, int(i * j * 3.14 * 314 % 50)] for i in range(24)
             for j in range(7)]
    c4 = (HeatMap({
        "width": "100%"
    }).add_xaxis(Faker.clock).add_yaxis(
        "series0",
        Faker.week,
        value,
        label_opts=opts.LabelOpts(is_show=True, position="inside"),
    ).set_global_opts(
        title_opts=opts.TitleOpts(title="HeatMap-Label 显示"),
        visualmap_opts=opts.VisualMapOpts(),
    ))

    put_grid([[put_html(c1.render_notebook()),
               put_html(c2.render_notebook())],
              [put_html(c3.render_notebook()),
               put_html(c4.render_notebook())]],
             cell_width='1fr',
             cell_height='1fr')
Beispiel #25
0
from pyecharts import options as opts
from pyecharts.charts import Polar
from pyecharts.faker import Faker

c = (Polar().add_schema(
    angleaxis_opts=opts.AngleAxisOpts(data=Faker.week, type_="category")).add(
        "A", [1, 2, 3, 4, 3, 5, 1], type_="bar", stack="stack0").add(
            "B", [2, 4, 6, 1, 2, 3, 1], type_="bar", stack="stack0").add(
                "C", [1, 2, 3, 4, 1, 2, 5], type_="bar",
                stack="stack0").set_global_opts(title_opts=opts.TitleOpts(
                    title="Polar-AngleAxis")).render("Polar_angleaxis.html"))
Beispiel #26
0
    def view_radar(self, df_view):
        """
            画雷达图
            
            例子:
                page_ = Page()
                for v in view_lst:
                    view_label[1] = v
                    df_view = get_view_dt(df_all, 'label', view_label, call_cols, call_dct)
                    c = view_radar(df_view)
                    page_.add(c)
                    print(f'Finished {v}')
                print('Finished all')  
                page_.render_notebook()
            """
        c_schema = []
        try:
            add_name1, add_name2 = df_view.columns[1], df_view.columns[2]
            add_value1, add_value2 = [
                df_view.iloc[list(range(12)), 1].tolist()
            ], [df_view.iloc[list(range(12)), 2].tolist()]
            max_v = max(max(add_value1[0]), max(add_value2[0]))
            min_v = min(min(add_value1[0]), min(add_value2[0]))
            max_v_set = 1 if max_v > 0.65 else max_v + min_v
            for i in df_view.loc[list(range(12)), 'index']:
                c_schema.append({"name": i, "max": max_v_set, "min": 0})
        except:
            add_name1, add_name2 = df_view.columns[1], df_view.columns[2]
            add_value1, add_value2 = [df_view.iloc[:, 1].tolist()
                                      ], [df_view.iloc[:, 2].tolist()]
            max_v = max(max(add_value1[0]), max(add_value2[0]))
            min_v = min(min(add_value1[0]), min(add_value2[0]))
            max_v_set = 1 if max_v > 0.65 else max_v + min_v
            for i in df_view.loc[:, 'index']:
                c_schema.append({"name": i, "max": max_v_set, "min": 0})

        c = (Radar().add_schema(
            c_schema,
            shape="circle",
            center=["50%", "50%"],
            radius="80%",
            angleaxis_opts=opts.AngleAxisOpts(
                min_=0,
                max_=360,
                is_clockwise=False,
                interval=5,
                axistick_opts=opts.AxisTickOpts(is_show=False),
                axislabel_opts=opts.LabelOpts(is_show=False),
                axisline_opts=opts.AxisLineOpts(is_show=False),
                splitline_opts=opts.SplitLineOpts(is_show=False),
            ),
            radiusaxis_opts=opts.RadiusAxisOpts(
                min_=0,
                max_=round(max_v_set, 3),
                interval=round(max_v_set / 5, 3),
                splitarea_opts=opts.SplitAreaOpts(
                    is_show=True,
                    areastyle_opts=opts.AreaStyleOpts(opacity=1)),
            ),
            polar_opts=opts.PolarOpts(),
            splitarea_opt=opts.SplitAreaOpts(is_show=False),
            splitline_opt=opts.SplitLineOpts(is_show=False),
        ).add(add_name1, add_value1, color="#f9713c").add(
            add_name2,
            add_value2,
            color="#b3e4a1",
            areastyle_opts=opts.AreaStyleOpts(opacity=0.3)).set_series_opts(
                label_opts=opts.LabelOpts(is_show=False)))

        return c
import math

import pyecharts.options as opts
from pyecharts.charts import Polar

data = []

for i in range(0, 101):
    theta = i / 100 * 360
    r = 5 * (1 + math.sin(theta / 180 * math.pi))
    data.append([r, theta])

(
    Polar(init_opts=opts.InitOpts(width="1600px", height="800px"))
    .add(series_name="line", data=data, label_opts=opts.LabelOpts(is_show=False))
    .add_schema(angleaxis_opts=opts.AngleAxisOpts(
        start_angle=0, type_="value", is_clockwise=True)
    )
    .set_global_opts(
        tooltip_opts=opts.TooltipOpts(trigger="axis", axis_pointer_type="cross"),
        title_opts=opts.TitleOpts(title="极坐标双数值轴")
    )
    .render("two_value_axes_in_polar.html")
)
def draw_radar(season_x, season_name, filechart, seasonareacolor, seasonlinecolor):
    # 建立schema的json文件  season_x.columns = [season_name]
    season_index = season_x.index.to_list()
    # print(season_index)
    # n_max, n_min = max(season_x), min(season_x)
    n_max = max(enumerate(season_x[0]), key=operator.itemgetter(1))[1]
    n_min = min(enumerate(season_x[0]), key=operator.itemgetter(1))[1]
    # 用于获取对象的哪些维的数据
    # print(n_max, n_min)
    df_season = pd.DataFrame({'name': season_index})
    df_season['max'], df_season['min'] = n_max, n_min
    # season_js = df_season.to_json(orient='records')
    # print(season_js)
    # 设置16方位, 逆时针排序
    season_js = [
        {"name": "N", "max": n_max, "min": n_min},
        {"name": "NNW", "max": n_max, "min": n_min},
        {"name": "NW", "max": n_max, "min": n_min},
        {"name": "WNW", "max": n_max, "min": n_min},
        {"name": "W", "max": n_max, "min": n_min},
        {"name": "WSW", "max": n_max, "min": n_min},
        {"name": "SW", "max": n_max, "min": n_min},
        {"name": "SSW", "max": n_max, "min": n_min},
        {"name": "S", "max": n_max, "min": n_min},
        {"name": "SSE", "max": n_max, "min": n_min},
        {"name": "SE", "max": n_max, "min": n_min},
        {"name": "ESE", "max": n_max, "min": n_min},
        {"name": "E", "max": n_max, "min": n_min},
        {"name": "ENE", "max": n_max, "min": n_min},
        {"name": "NE", "max": n_max, "min": n_min},
        {"name": "NNE", "max": n_max, "min": n_min},
    ]
    # 设置数据
    fengsus = season_x[0].to_list()
    data_fengsu = [{'value': fengsus, 'name': '风频数'}]
    # print(data_fengsu)
    charts = Radar()
    charts.set_colors(['#4587E7'])  # 设置颜色
    charts.add_schema(schema=season_js,
                      shape='circle',
                      center=['50%', '50%'],
                      radius='80%',
                      angleaxis_opts=opts.AngleAxisOpts(
                          min_=0,  # 坐标轴刻度最小值
                          max_=360,  # 坐标轴刻度最大值
                          is_clockwise=True,
                          interval=22.5,  # 强制设置坐标轴分割间隔
                          axistick_opts=opts.AxisTickOpts(is_show=False),
                          axislabel_opts=opts.LabelOpts(is_show=False,),   # 坐标轴线标签配置项
                          axisline_opts=opts.AxisLineOpts(is_show=True),  # 坐标轴线风格配置项
                          splitline_opts=opts.SplitLineOpts(is_show=True)  # 分割线配置项
                      ),
                      radiusaxis_opts=opts.RadiusAxisOpts(
                          min_=n_min,  # 坐标轴刻度最小值
                          max_=n_max,   # 坐标轴刻度最大值
                          interval=2,  # 强制设置坐标轴分割间隔
                          splitarea_opts=opts.SplitAreaOpts(
                              is_show=True,
                              areastyle_opts=opts.AreaStyleOpts(opacity=0.2,
                                                                )
                          ),
                          splitline_opts=opts.SplitLineOpts(is_show=True,
                                                            linestyle_opts=opts.LineStyleOpts(is_show=True,
                                                                                              width=0.5,
                                                                                              color='grey')),
                          axislabel_opts=opts.LabelOpts(is_show=True,
                                                        font_size=12,
                                                        color='grey'),  # 坐标轴线标签配置项
                      ),
                      polar_opts=opts.PolarOpts(),
                      splitarea_opt=opts.SplitAreaOpts(is_show=True),
                      splitline_opt=opts.SplitLineOpts(is_show=False),  # 分割线配置项
                      textstyle_opts=opts.TextStyleOpts(color='black',
                                                        font_size=14)
                      )
    charts.add(series_name='%s玫瑰图' % season_name,  # 系列名称
               data=data_fengsu,  # 系列数据
               areastyle_opts=opts.AreaStyleOpts(opacity=0.5,  # 系列面样式设置
                                                 color=seasonareacolor),
               linestyle_opts=opts.LineStyleOpts(width=2,  # 系列线样式设置
                                                 color=seasonlinecolor),
               label_opts=opts.LabelOpts(is_show=False),
               )  # 系列标签设置
    charts.render(filechart)
import math

from pyecharts import options as opts
from pyecharts.charts import Polar

data = []
for i in range(101):
    theta = i / 100 * 360
    r = 5 * (1 + math.sin(theta / 180 * math.pi))
    data.append([r, theta])
hour = [i for i in range(1, 25)]
c = (Polar().add_schema(angleaxis_opts=opts.AngleAxisOpts(
    data=hour, type_="value", boundary_gap=False, start_angle=0)).add(
        "love", data, label_opts=opts.LabelOpts(
            is_show=False)).set_global_opts(title_opts=opts.TitleOpts(
                title="Polar-Love")).render("polar_love.html"))