欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python+Pyecharts實(shí)現(xiàn)散點(diǎn)圖的繪制

 更新時(shí)間:2022年06月20日 14:14:04   作者:數(shù)據(jù)程序設(shè)計(jì)  
散點(diǎn)圖是指在回歸分析中,數(shù)據(jù)點(diǎn)在直角坐標(biāo)系平面上的分布圖,散點(diǎn)圖表示因變量隨自變量而變化的大致趨勢(shì),據(jù)此可以選擇合適的函數(shù)對(duì)數(shù)據(jù)點(diǎn)進(jìn)行擬合。本文將利用Python Pyecharts實(shí)現(xiàn)散點(diǎn)圖的繪制,需要的可以參考一下

第1關(guān):Scatter:散點(diǎn)圖(一)

編程要求

根據(jù)以上介紹,在右側(cè)編輯器補(bǔ)充代碼,繪制給定數(shù)據(jù)的散點(diǎn)圖,要求:

  • 畫(huà)布大小初始化為寬 1600 像素,高 1000 像素
  • X 軸數(shù)據(jù)設(shè)置為 x_data
  • 添加 Y 軸數(shù)據(jù)。系列名稱(chēng)設(shè)置為空,數(shù)據(jù)使用 y_data,標(biāo)記的大小設(shè)置為20,不顯示標(biāo)簽
  • X 軸類(lèi)型設(shè)置為數(shù)值軸,并顯示分割線(xiàn)
  • Y 軸類(lèi)型設(shè)置為數(shù)值軸,并顯示分割線(xiàn)以及坐標(biāo)軸刻度
  • 不顯示提示框

代碼

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")

測(cè)試說(shuō)明

平臺(tái)會(huì)運(yùn)行你編寫(xiě)的代碼進(jìn)行繪圖,并與預(yù)期圖片進(jìn)行比對(duì)。預(yù)期效果如下:

第2關(guān):Scatter:散點(diǎn)圖(二)

編程要求

根據(jù)以上介紹,在右側(cè)編輯器補(bǔ)充代碼,利用給定數(shù)據(jù)繪制相應(yīng)的散點(diǎn)圖,要求:

  • X 軸數(shù)據(jù)項(xiàng)使用data_x
  • 添加兩組 Y 軸數(shù)據(jù)。
  • 第一組系列名稱(chēng)設(shè)置為“商家A”,數(shù)據(jù)使用data_y_1
  • 第二組系列名稱(chēng)設(shè)置為“商家B”,數(shù)據(jù)使用data_y_2
  • 將標(biāo)題設(shè)置為“Scatter-VisualMap(Size)”
  • 視覺(jué)映射過(guò)渡類(lèi)型選擇“size”,最大值設(shè)為 150,最小值設(shè)置為 20

代碼

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")

測(cè)試說(shuō)明

平臺(tái)會(huì)運(yùn)行你編寫(xiě)的代碼進(jìn)行繪圖,并與預(yù)期圖片進(jìn)行比對(duì)。預(yù)期效果如下:

第3關(guān):Scatter:散點(diǎn)圖(三)

編程要求

根據(jù)以上介紹,在右側(cè)編輯器補(bǔ)充代碼,利用給定數(shù)據(jù)繪制相應(yīng)的散點(diǎn)圖,要求:

  • X 軸數(shù)據(jù)項(xiàng)使用data_x
  • Y 軸數(shù)據(jù)項(xiàng)使用data_y,系列名稱(chēng)設(shè)置為“商家A”,并用 JsCode 格式化標(biāo)簽(具體格式見(jiàn)文末)
  • 標(biāo)題設(shè)置為“Scatter-多維度數(shù)據(jù)”
  • 用 JsCode 格式化提示框文本(詳見(jiàn)文末)
  • 視覺(jué)映射類(lèi)型設(shè)置為顏色,最大值設(shè)置為 150,最小值設(shè)置為 20,組件映射維度為 1

代碼

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-多維度數(shù)據(jù)"),
            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")

測(cè)試說(shuō)明

平臺(tái)會(huì)運(yùn)行你編寫(xiě)的代碼進(jìn)行繪圖,并與預(yù)期圖片進(jìn)行比對(duì)。預(yù)期效果如下:

以上就是Python+Pyecharts實(shí)現(xiàn)散點(diǎn)圖的繪制的詳細(xì)內(nèi)容,更多關(guān)于Python Pyecharts散點(diǎn)圖的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評(píng)論