コード例 #1
0
def parallel_base() -> Parallel:
    rL = []
    with open("iris.data", "r") as f:
        rL = f.read().split("\n")
    nameSet, data = set(), {}
    for i in range(len(rL) - 1):
        tmp = rL[i].split(",")
        if tmp[-1] not in nameSet:
            nameSet.add(tmp[-1])
            data[tmp[-1]] = []
        data[tmp[-1]].append(list(map(float, tmp[:-1])))

    c = (Parallel(init_opts=opts.InitOpts(theme=ThemeType.CHALK)).add_schema([
        {
            "dim": 0,
            "name": "calyx length"
        },
        {
            "dim": 1,
            "name": "calyx width"
        },
        {
            "dim": 2,
            "name": "petal length"
        },
        {
            "dim": 3,
            "name": "petal width"
        },
    ]).set_global_opts(title_opts=opts.TitleOpts(title="鸢尾花数据集")))

    for k in data.keys():
        c.add(k, data[k])
    return c
コード例 #2
0
def parallel_base() -> Parallel:
    data = [
        [1, 91, 45, 125, 0.82, 34],
        [2, 65, 27, 78, 0.86, 45],
        [3, 83, 60, 84, 1.09, 73],
        [4, 109, 81, 121, 1.28, 68],
        [5, 106, 77, 114, 1.07, 55],
        [6, 109, 81, 121, 1.28, 68],
        [7, 106, 77, 114, 1.07, 55],
        [8, 89, 65, 78, 0.86, 51, 26],
        [9, 53, 33, 47, 0.64, 50, 17],
        [10, 80, 55, 80, 1.01, 75, 24],
        [11, 117, 81, 124, 1.03, 45],
    ]
    c = (
        Parallel()
        .add_schema(
            [
                {"dim": 0, "name": "data"},
                {"dim": 1, "name": "AQI"},
                {"dim": 2, "name": "PM2.5"},
                {"dim": 3, "name": "PM10"},
                {"dim": 4, "name": "CO"},
                {"dim": 5, "name": "NO2"},
            ]
        )
        .add("parallel", data)
        .set_global_opts(title_opts=opts.TitleOpts(title="Parallel-基本示例"))
    )
    return c
コード例 #3
0
def parallel_category() -> Parallel:
    data = [
        [1, 91, 45, 125, 0.82, 34, 23, "良"],
        [2, 65, 27, 78, 0.86, 45, 29, "良"],
        [3, 83, 60, 84, 1.09, 73, 27, "良"],
        [4, 109, 81, 121, 1.28, 68, 51, "轻度污染"],
        [5, 106, 77, 114, 1.07, 55, 51, "轻度污染"],
        [6, 109, 81, 121, 1.28, 68, 51, "轻度污染"],
        [7, 106, 77, 114, 1.07, 55, 51, "轻度污染"],
        [8, 89, 65, 78, 0.86, 51, 26, "良"],
        [9, 53, 33, 47, 0.64, 50, 17, "良"],
        [10, 80, 55, 80, 1.01, 75, 24, "良"],
        [11, 117, 81, 124, 1.03, 45, 24, "轻度污染"],
        [12, 99, 71, 142, 1.1, 62, 42, "良"],
        [13, 95, 69, 130, 1.28, 74, 50, "良"],
        [14, 116, 87, 131, 1.47, 84, 40, "轻度污染"],
    ]
    c = (Parallel().add_schema([
        opts.ParallelAxisOpts(dim=0, name="data"),
        opts.ParallelAxisOpts(dim=1, name="AQI"),
        opts.ParallelAxisOpts(dim=2, name="PM2.5"),
        opts.ParallelAxisOpts(dim=3, name="PM10"),
        opts.ParallelAxisOpts(dim=4, name="CO"),
        opts.ParallelAxisOpts(dim=5, name="NO2"),
        opts.ParallelAxisOpts(dim=6, name="CO2"),
        opts.ParallelAxisOpts(
            dim=7,
            name="等级",
            type_="category",
            data=["优", "良", "轻度污染", "中度污染", "重度污染", "严重污染"],
        ),
    ]).add("parallel", data).set_global_opts(title_opts=opts.TitleOpts(
        title="Parallel-Category")))
    return c
コード例 #4
0
ファイル: G.py プロジェクト: Akasakar/Experimental_Class
def parallel_base(dataSet) -> Parallel:
    schema = [{
        "dim": i - 1,
        "name": dataSet[0][i]
    } for i in range(1, len(dataSet[0]))]
    DS, data = dataSet[1:], {0: [], 1: []}
    for ds in DS:
        data[ds[0]].append(list(map(float, ds[1:])))

    c = (
        Parallel(init_opts=opts.InitOpts(width="4444px", height="666px"))
        #下面是暗黑主题
        #Parallel(init_opts=opts.InitOpts(width = "3000px", height = "800px", theme=ThemeType.CHALK))
        .add_schema(schema).set_global_opts(
            title_opts=opts.TitleOpts(title="学生体侧数据"),
            legend_opts=opts.LegendOpts(is_show=True),
            toolbox_opts=opts.ToolboxOpts(),
        ))
    for k in data.keys():
        c.add(str(k), data[k])
    return c
コード例 #5
0
def test_parallel_base(fake_writer):
    data = [
        [1, 91, 45, 125, 0.82, 34],
        [2, 65, 27, 78, 0.86, 45],
        [3, 83, 60, 84, 1.09, 73],
        [4, 109, 81, 121, 1.28, 68],
        [5, 106, 77, 114, 1.07, 55],
        [6, 109, 81, 121, 1.28, 68],
    ]
    c = (Parallel().add_schema([
        {
            "dim": 0,
            "name": "data"
        },
        {
            "dim": 1,
            "name": "AQI"
        },
        {
            "dim": 2,
            "name": "PM2.5"
        },
        {
            "dim": 3,
            "name": "PM10"
        },
        {
            "dim": 4,
            "name": "CO"
        },
        {
            "dim": 5,
            "name": "NO2"
        },
    ]).add("parallel", data))
    c.render()
    _, content = fake_writer.call_args[0]
    eq_(c.theme, "white")
    eq_(c.renderer, "canvas")
コード例 #6
0
def test_parallel_base():
    data = [
        [1, 91, 45, 125, 0.82, 34],
        [2, 65, 27, 78, 0.86, 45],
        [3, 83, 60, 84, 1.09, 73],
        [4, 109, 81, 121, 1.28, 68],
        [5, 106, 77, 114, 1.07, 55],
        [6, 109, 81, 121, 1.28, 68],
    ]
    c = (Parallel().add_schema([
        {
            "dim": 0,
            "name": "data"
        },
        {
            "dim": 1,
            "name": "AQI"
        },
        {
            "dim": 2,
            "name": "PM2.5"
        },
        {
            "dim": 3,
            "name": "PM10"
        },
        {
            "dim": 4,
            "name": "CO"
        },
        {
            "dim": 5,
            "name": "NO2"
        },
    ]).add("parallel", data))
    assert c.theme == "white"
    assert c.renderer == "canvas"
    c.render("render.html")
コード例 #7
0
ファイル: C.py プロジェクト: Akasakar/Experimental_Class
def parallel_base(dataSet) -> Parallel:
    nameSet, data = set(), {}
    for ds in dataSet:
        if ds[-1] not in nameSet:
            nameSet.add(ds[-1])
            data[ds[-1]] = []
        data[ds[-1]].append(list(map(float, ds[:-1])))

    c = (
        Parallel(init_opts=opts.InitOpts(theme=ThemeType.CHALK))
        .add_schema(
            [
                {"dim": 0, "name": "calyx length"},
                {"dim": 1, "name": "calyx width"},
                {"dim": 2, "name": "petal length"},
                {"dim": 3, "name": "petal width"},
            ]
        )
        .set_global_opts(title_opts=opts.TitleOpts(title="鸢尾花数据集"))
    )
    for k in data.keys():
        c.add(k, data[k])
    return c
コード例 #8
0
(Parallel().add_schema([
    {
        "dim": 0,
        "name": "排名"
    },
    {
        "dim": 1,
        "name": "教育质量"
    },
    {
        "dim": 2,
        "name": "校友就业"
    },
    {
        "dim": 3,
        "name": "教师质量"
    },
    {
        "dim": 4,
        "name": "影响"
    },
    {
        "dim": 5,
        "name": "引文"
    },
    {
        "dim": 6,
        "name": "广泛影响"
    },
]).add("parallel", data).set_global_opts(title_opts=opts.TitleOpts(
    title="2017cwur前10大学具体得分排名")).render("2017cwur前10大学具体得分排名.html"))
コード例 #9
0
    {
        "dim": 2,
        "name": "C"
    },
    {
        "dim": 3,
        "name": "Score",
        "type": "category",
        "data": ["Excellent", "Good", "OK", "Bad"],
    },
]

parallel_data = [[12.99, 100, 82, "Good"], [9.99, 80, 77, "OK"],
                 [20, 120, 60, "Excellent"]]
# init_opts=opts.InitOpts(width="800px",height="300px")
parallel = Parallel(init_opts=opts.InitOpts(width="800px", height="300px"))
parallel.add_schema(parallel_axis)
parallel.add(series_name="Related Indexes",
             data=parallel_data,
             linestyle_opts=opts.LineStyleOpts(width=4, opacity=0.5))

liquid = Liquid(init_opts=opts.InitOpts(width="300px", height="300px"))
liquid.add("liquid", [0.6, 0.7, 0.3])
liquid.set_global_opts(title_opts=opts.TitleOpts(title="Basic Example"))

heatmap_data = [[i, j, random.randint(0, 50)] for i in range(7)
                for j in range(7)]
heatmap = HeatMap()
heatmap.add_xaxis(Faker.week)
heatmap.add_yaxis(
    "相关表",
コード例 #10
0
    [11, 117, 81, 124, 1.03, 45, 24, "轻度污染"],
    [12, 99, 71, 142, 1.1, 62, 42, "良"],
    [13, 95, 69, 130, 1.28, 74, 50, "良"],
    [14, 116, 87, 131, 1.47, 84, 40, "轻度污染"],
]

c = (Parallel().add_schema([
    opts.ParallelAxisOpts(dim=0, name="data"),
    opts.ParallelAxisOpts(dim=1, name="AQI"),
    opts.ParallelAxisOpts(dim=2, name="PM2.5"),
    opts.ParallelAxisOpts(dim=3, name="PM10"),
    opts.ParallelAxisOpts(dim=4, name="CO"),
    opts.ParallelAxisOpts(dim=5, name="NO2"),
    opts.ParallelAxisOpts(dim=6, name="CO2"),
    opts.ParallelAxisOpts(
        dim=7,
        name="等级",
        type_="category",
        data=["优", "良", "轻度污染", "中度污染", "重度污染", "严重污染"],
    ),
]).add(
    "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 = []
コード例 #11
0
parallel_axis = [
    {
        "dim": 0,
        "name": "Price"
    },
    {
        "dim": 1,
        "name": "Net Weight"
    },
    {
        "dim": 2,
        "name": "Amount"
    },
    {
        "dim": 3,
        "name": "Score",
        "type": "category",
        "data": ["Excellent", "Good", "OK", "Bad"],
    },
]

data = [[12.99, 100, 82, "Good"], [9.99, 80, 77, "OK"],
        [20, 120, 60, "Excellent"]]

(Parallel(init_opts=opts.InitOpts(width="1400px", height="800px")).add_schema(
    schema=parallel_axis).add(
        series_name="",
        data=data,
        linestyle_opts=opts.LineStyleOpts(width=4, opacity=0.5),
    ).render("Basic_parallel.html"))
コード例 #12
0
ファイル: pyecharts_basic_2.py プロジェクト: xyy15926/demark
schema = [
    opts.ParallelAxisOpts(dim=0, name="data"),
    opts.ParallelAxisOpts(dim=1, name="AQI"),
    opts.ParallelAxisOpts(dim=2, name="PM2.5"),
    opts.ParallelAxisOpts(dim=3, name="PM10"),
    opts.ParallelAxisOpts(dim=4, name="CO"),
    opts.ParallelAxisOpts(dim=5, name="NO2"),
    opts.ParallelAxisOpts(dim=6, name="CO2"),
    opts.ParallelAxisOpts(
        dim=7,
        name="等级",
        type_="category",
        data=["优", "良", "轻度污染", "中度污染", "重度污染", "严重污染"],
    ),
]
parallel = Parallel()
# 添加坐标轴和数据
parallel.add_schema(schema=schema).add("", data)
parallel.render_notebook()

# %% [markdown]
# ### Radar -- 雷达图

radar = Radar()
radar.add_schema(schema=[
    opts.RadarIndicatorItem(name=_k, max_=200) for _k in list("ABCDFG")
])
radar.add("Expectation", [Faker.values()]).add("Reality", [Faker.values()])
radar.render_notebook()

# %% [markdown]
コード例 #13
0
parallel_axis = [
    {
        "dim": 0,
        "name": "Price"
    },
    {
        "dim": 1,
        "name": "Net Weight"
    },
    {
        "dim": 2,
        "name": "Amount"
    },
    {
        "dim": 3,
        "name": "Score",
        "type": "category",
        "data": ["Excellent", "Good", "OK", "Bad"],
    },
]

data = [[12.99, 100, 82, "Good"], [9.99, 80, 77, "OK"],
        [20, 120, 60, "Excellent"]]

(Parallel().add_schema(schema=parallel_axis).add(
    series_name="",
    data=data,
    linestyle_opts=opts.LineStyleOpts(width=4, opacity=0.5),
).render("basic_parallel.html"))
コード例 #14
0
        "dim": 0,
        "name": "Price"
    },
    {
        "dim": 1,
        "name": "Net Weight"
    },
    {
        "dim": 2,
        "name": "Amount"
    },
    {
        "dim": 3,
        "name": "Score",
        "type": "category",
        "data": ["Excellent", "Good", "OK", "Bad"],
    },
]

data = [[12.99, 100, 82, "Good"], [9.99, 80, 77, "OK"],
        [20, 120, 60, "Excellent"]]

c = (Parallel().add_schema(schema=parallel_axis).add(
    series_name="",
    data=data,
    linestyle_opts=opts.LineStyleOpts(width=4, opacity=0.5),
))

c.width = "100%"
put_html(c.render_notebook())
コード例 #15
0
def find_value_render(query_filter, x_label, x, result, Data, query,
                      table_path, answer):

    colorList = ['#f36c6c', '#e6cf4e', '#20d180', '#0093ff']
    # x = ['GDP', 'Industry', 'Architecture', 'Service']
    # y = [990865, 317109, 70904, 534233]
    # x1 = ["周一"]
    # y1 = [11]

    Y = []
    # for i in range(len(y)):
    #     if i==0:
    #         Y.append(
    #             opts.BarItem(
    #                 name=x[i],
    #                 value=round(y[i], 2),
    #                 label_opts=opts.LabelOpts(position="insideTop"),
    #                 itemstyle_opts={
    #                     "normal": {
    #                         "color": colorList[0],
    #                         "barBorderRadius": [30, 30, 30, 30],
    #                     }
    #                 }
    #         ))
    #     else:
    #         Y.append(
    #             opts.BarItem(
    #                 name=x[i],
    #                 value=round(y[i], 2),
    #                 label_opts=opts.LabelOpts(position="insideTop"),
    #                 itemstyle_opts={
    #                     "normal": {
    #                         "color": "blue",
    #                         "barBorderRadius": [30, 30, 30, 30],
    #                     }
    #                 }
    #             ))
    bar1 = Bar()
    bar1.add_xaxis(x)
    bar1.add_yaxis(result[0][0],
                   y_axis=result[0][1],
                   label_opts=opts.LabelOpts(position="insideTop"))
    bar1.set_global_opts(
        yaxis_opts=opts.AxisOpts(is_show=False),
        xaxis_opts=opts.AxisOpts(
            axisline_opts=opts.AxisLineOpts(is_show=False),
            axispointer_opts=opts.AxisPointerOpts(is_show=False),
            axistick_opts=opts.AxisTickOpts(is_show=False)),
        title_opts=opts.TitleOpts(subtitle="When the search condition is " +
                                  query_filter,
                                  pos_left='center'),
        graphic_opts=[
            opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",
                    z=100,
                ),
                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                    # 可以通过jsCode添加js代码,也可以直接用字符串
                    text=[
                        '\n' + "Q:" + ' ' + query + '\n' + "\n" + 'A:' + ' ' +
                        answer
                    ],
                    font="14px Microsoft YaHei",
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill="#333")))
        ])
    bar2 = Bar()
    bar2.add_xaxis(x)
    for i in range(len(result)):
        bar2.add_yaxis(result[i][0], y_axis=result[i][1])
    bar2.set_global_opts(
        yaxis_opts=opts.AxisOpts(is_show=False),
        xaxis_opts=opts.AxisOpts(
            axisline_opts=opts.AxisLineOpts(is_show=False),
            axispointer_opts=opts.AxisPointerOpts(is_show=False),
            axistick_opts=opts.AxisTickOpts(is_show=False)),
        graphic_opts=[
            opts.GraphicText(
                graphic_item=opts.GraphicItem(
                    left="center",
                    top="bottom",
                    z=100,
                ),
                graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                    # 可以通过jsCode添加js代码,也可以直接用字符串
                    text=[
                        '\n' + "\n" + "Q:" + ' ' + query + '\n' + "\n" + 'A:' +
                        ' ' + answer
                    ],
                    font="16px Microsoft YaHei",
                    graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                        fill="#333")))
        ])

    Label = []
    data = []
    for i in range(len(Data)):
        Label.append(str(Data[i][0]))
        data.append(Data[i][1])
    data = list(map(list, zip(*data)))
    parallel = Parallel()
    parallel_axis = []
    for i in range(len(Label)):
        parallel_axis.append({"dim": i, "name": Label[i]})
    parallel.add_schema(schema=parallel_axis)
    parallel.add("", data, is_smooth=True)
    parallel.set_global_opts(graphic_opts=[
        opts.GraphicText(
            graphic_item=opts.GraphicItem(
                left="center",
                top="bottom",
                z=100,
            ),
            graphic_textstyle_opts=opts.GraphicTextStyleOpts(
                # 可以通过jsCode添加js代码,也可以直接用字符串
                text=['\n' + "Q:" + ' ' + query + '\n' + 'A:' + ' ' + answer],
                font="14px Microsoft YaHei",
                graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(
                    fill="#333")))
    ])
    grid0 = Grid(init_opts=opts.InitOpts(
        width="100%",
        height="100%",
        renderer=globals.RenderType.SVG,
    ))
    grid0.add(bar1, grid_opts={'left': '20%', 'bottom': '34%'})
    option0 = grid0.dump_options_with_quotes()
    option0 = json.loads(option0)
    grid = Grid(init_opts=opts.InitOpts(
        width="100%",
        height="100%",
        renderer=globals.RenderType.SVG,
    ))
    grid.add(bar2, grid_opts={'left': '15%', 'bottom': '50%'})
    option1 = grid.dump_options_with_quotes()
    option1 = json.loads(option1)
    grid1 = Grid(init_opts=opts.InitOpts(
        width="100%",
        height="100%",
        renderer=globals.RenderType.SVG,
    ))
    grid1.add(parallel, grid_opts={'left': '30%', 'bottom': '34%'})
    option2 = grid1.dump_options_with_quotes()
    option2 = json.loads(option2)

    option = {"option": [option1, option2], "query": query}
    return option
コード例 #16
0
    def plot_hyperparams(self, destination='notebook', output='hyperparams.html'):
        """Plot hyperparams in a parallel line chart

        Args:
            destination: one of notebook, html
            output: the html file path

        Returns:

        """

        try:
            import pyecharts
        except Exception as e:
            raise Exception("You may not install 'pyecharts',"
                            "please refer to https://github.com/pyecharts/pyecharts and install it.")

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

        if destination == 'notebook' and not isnotebook():
            raise Exception("You may not running in a notebook,"
                            " try to set 'destination' to 'html' or run it in notebook ")

        if self.trials is None or len(self.trials) < 1:
            raise Exception("Trials is empty ")

        REWARD_METRIC_COL = 'Reward metric'

        def get_space_params(trial):
            space = trial.space_sample
            params_dict = {}
            for hyper_param in space.get_all_params():
                references = list(hyper_param.references)
                if len(references) > 0:
                    param_name = hyper_param.alias[len(list(hyper_param.references)[0].name) + 1:]
                    param_value = hyper_param.value

                    if isinstance(param_value, int) or isinstance(param_value, float):
                        if not isinstance(param_value, bool):
                            params_dict[param_name] = param_value
                params_dict[REWARD_METRIC_COL] = trial.reward

            return params_dict

        def make_dims(df_params):
            parallel_axis = []
            for i, col in enumerate(df_params.columns):
                if df_params.dtypes[col].kind == 'O':
                    parallel_axis.append({
                        "dim": i,
                        "name": col,
                        "type": "category",
                        "data": df_params[col].unique().tolist(),
                    })
                else:
                    parallel_axis.append({'dim': i, 'name': col})
            return parallel_axis

        trials_params = [get_space_params(trial) for trial in self.trials]

        param_names = list(set([v for ps in trials_params for v in ps.keys()]))
        param_names.remove(REWARD_METRIC_COL)
        param_names.insert(len(param_names), REWARD_METRIC_COL)

        trial_params_values = []
        for t in trials_params:
            param_values = [t.get(n) for n in param_names]
            trial_params_values.append(param_values)

        df_train_params = pd.DataFrame(data=trial_params_values, columns=param_names)

        # remove if all is None
        df_train_params.dropna(axis=1, how='all', inplace=True)

        parallel_axis = make_dims(df_train_params)
        chart = \
            Parallel(init_opts=opts.InitOpts(width="%dpx" % (len(param_names) * 100), height="400px")) \
                .add_schema(schema=parallel_axis).add(series_name="",
                                                      data=df_train_params.values.tolist(),
                                                      linestyle_opts=opts.LineStyleOpts(width=1, opacity=0.5),

                                                      ).set_global_opts(
                visualmap_opts=[
                    opts.VisualMapOpts(
                        type_="color",
                        is_calculable=True,
                        precision=2,
                        # dimension=0,
                        pos_left="-10",
                        pos_bottom="30",
                        max_=df_train_params[REWARD_METRIC_COL].max().tolist(),
                        min_=df_train_params[REWARD_METRIC_COL].min().tolist()
                    )
                ]
            )

        if destination == 'notebook':
            return chart.render_notebook()
        else:
            return chart.render(output)