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)文章
在Python中實(shí)現(xiàn)替換字符串中的子串的示例
今天小編就為大家分享一篇在Python中實(shí)現(xiàn)替換字符串中的子串的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-10-10ruff check文件目錄檢測(cè)--exclude參數(shù)設(shè)置路徑詳解
這篇文章主要為大家介紹了ruff check文件目錄檢測(cè)exclude參數(shù)如何設(shè)置多少路徑詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10python隊(duì)列通信:rabbitMQ的使用(實(shí)例講解)
下面小編就為大家分享一篇python隊(duì)列通信:rabbitMQ的使用(實(shí)例講解),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2017-12-12python 實(shí)現(xiàn)兩個(gè)變量值進(jìn)行交換的n種操作
這篇文章主要介紹了python 實(shí)現(xiàn)兩個(gè)變量值進(jìn)行交換的n種操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06python的dataframe轉(zhuǎn)換為多維矩陣的方法
下面小編就為大家分享一篇python的dataframe轉(zhuǎn)換為多維矩陣的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-04-04sklearn和keras的數(shù)據(jù)切分與交叉驗(yàn)證的實(shí)例詳解
這篇文章主要介紹了sklearn和keras的數(shù)據(jù)切分與交叉驗(yàn)證的實(shí)例詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-06-06