欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

PyEcharts 直角坐标系图表之散点图

程序员文章站 2022-05-26 22:02:09
...

第1关:Scatter:散点图(一)

from PreTest import *
from pyecharts import options as opts
from pyecharts.render import make_snapshot
from snapshot_phantomjs import snapshot

from pyecharts.charts import Scatter


data = [
    [10.0, 8.04],
    [8.0, 6.95],
    [13.0, 7.58],
    [9.0, 8.81],
    [11.0, 8.33],
    [14.0, 9.96],
    [6.0, 7.24],
    [4.0, 4.26],
    [12.0, 10.84],
    [7.0, 4.82],
    [5.0, 5.68],
]
data.sort(key=lambda x: x[0])
x_data = [d[0] for d in data]
y_data = [d[1] for d in data]


def scatter_chart() -> Scatter:
    # ********* Begin *********#  
    scatter = (
        Scatter(init_opts=opts.InitOpts(width="1600px", height="1000px"))
        .add_xaxis(x_data)
        .add_yaxis("",
            y_data,
            symbol_size=20
            )
        .set_series_opts(
            label_opts=opts.LabelOpts(is_show=False)
            )
        .set_global_opts(
            tooltip_opts=opts.TooltipOpts(is_show=False),
            xaxis_opts=opts.AxisOpts(
                type_="value",
                splitline_opts=opts.SplitLineOpts(is_show=True)
            ),
            yaxis_opts=opts.AxisOpts(
                type_="value",
                splitline_opts=opts.SplitLineOpts(is_show=True),
                axistick_opts=opts.AxisTickOpts(is_show=True)
            )
        )


    )
    # ********** End **********#
    return scatter

make_snapshot(snapshot, scatter_chart().render("Result/render.html"), 'StudentAnswer/student_answer.png') # 输出图片
make_snapshot(snapshot, scatter_base(x_data, y_data).render(), "StandardAnswer/task1/standard_answer_1.png")

第2关:Scatter:散点图(二)

from PreTest import *
from pyecharts import options as opts
from pyecharts.render import make_snapshot
from snapshot_phantomjs import snapshot

from pyecharts.charts import Scatter

from pyecharts.faker import Faker


data_x = Faker.choose()

data_y_1 = Faker.values()

data_y_2 = Faker.values()


def scatter_chart() -> Scatter:
    # ********* Begin *********#  
    scatter = (
        Scatter()
        .add_xaxis(data_x)
        .add_yaxis("商家A",data_y_1)
        .add_yaxis("商家B",data_y_2)
        .set_global_opts(
            title_opts=opts.TitleOpts(title="Scatter-VisualMap(Size)"),
            visualmap_opts=opts.VisualMapOpts(is_show=True,type_='size',min_=20,max_=150)
        )
    )
    # ********** End **********#
    return scatter

make_snapshot(snapshot, scatter_chart().render("Result/render.html"), "StudentAnswer/student_answer.png") # 输出图片
make_snapshot(snapshot, scatter_visual(data_x, data_y_1, data_y_2).render(), "StandardAnswer/task2/standard_answer_2.png")

第3关:Scatter:散点图(三)

from PreTest import *
from pyecharts import options as opts
from pyecharts.render import make_snapshot
from snapshot_phantomjs import snapshot

from pyecharts.charts import Scatter
from pyecharts.faker import Faker
from pyecharts.commons.utils import JsCode

data_x = Faker.choose()

data_y = [list(z) for z in zip(Faker.values(), Faker.choose())]


def scatter_chart() -> Scatter:
    # ********* Begin *********#  
    scatter = (
        Scatter()
        .add_xaxis(data_x)
        .add_yaxis(
            "商家A",
            data_y,
            label_opts=opts.LabelOpts(
                formatter=JsCode("""function(params){return params.value[1] +' : '+ params.value[2];}""")
            )
        )
        .set_global_opts(
            title_opts=opts.TitleOpts(title="Scatter-多维度数据"),
            visualmap_opts=opts.VisualMapOpts(is_show=True,type_='color',min_=20,max_=150,dimension=1),
            tooltip_opts=opts.TooltipOpts(
                formatter=JsCode("""function (params) {return params.name + ' : ' + params.value[2];}""")
            )
        )

    )
    # ********** End **********#
    return scatter

make_snapshot(snapshot, scatter_chart().render("Result/render.html"), 'StudentAnswer/student_answer.png') # 输出图片
make_snapshot(snapshot, scatter_multi(data_x, data_y).render(), "StandardAnswer/task3/standard_answer_3.png")

上一篇: iOS 坐标系

下一篇: markdown语法学习