大數(shù)據(jù)可視化張揚課后參考答案_第1頁
大數(shù)據(jù)可視化張揚課后參考答案_第2頁
大數(shù)據(jù)可視化張揚課后參考答案_第3頁
大數(shù)據(jù)可視化張揚課后參考答案_第4頁
大數(shù)據(jù)可視化張揚課后參考答案_第5頁
已閱讀5頁,還剩17頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

概述:大數(shù)據(jù)可視化選擇題(多選)數(shù)據(jù)可視化能用哪種語言實現(xiàn)?(ABCD)C++語言Java語言Python語言JavaScript語言數(shù)據(jù)可視化可以用哪種符號元素編碼?(B)長度長度、色彩、尺寸、位置、紋理、方向、形狀以及關系長度、高度色彩、尺寸、位置、紋理、方向、形狀以及關系數(shù)據(jù)可視化常用布局有哪些?(D)柱狀圖、餅圖、折線圖表格、散點圖、雷達圖網(wǎng)絡圖、時間線、熱力圖、地圖、樹圖、復合圖形等以上都對本任務中測試Python是否安裝成功的語句是?(B)Python-VPython-VPython-RPython-R在使用Python操作MySQL數(shù)據(jù)庫的時候,創(chuàng)建游標時使用了cursor=pyMySQL.cursors.DictCursor語句,其目的是讓查詢結(jié)果以什么格式輸出?(A)列表嵌套字典列表嵌套元組元組嵌套字典元組嵌套元組在鏈接數(shù)據(jù)庫的字符串中db=pymysql.connect(host="",port=3306,user="root",passwd="123456",db="big_data")中,用戶名是:(C)3306rootbig_data在查詢語句select_sql='SELECT*FROMmap_enword'中,查詢的數(shù)據(jù)表名是:(B)map_enwordrootbig_data實操練習題使用for循環(huán),計算1到100的和。參考答案:sum=0

foriinrange(1,101):

sum+=i

print(sum)#5050使用for循環(huán),計算10的階乘。參考答案:result=1

foriinrange(2,11):

result*=i

print(result)#3628800查詢四六級單詞庫中的前十條數(shù)據(jù)。參考答案:importpymysql

"""查詢"""

defselect_db(select_sql):

#建立數(shù)據(jù)庫連接

db=pymysql.connect(

host="",

port=3306,

user="root",

passwd="root",

db="big_data"

)

#通過cursor()創(chuàng)建游標對象,并讓查詢結(jié)果以字典格式輸出

cur=db.cursor(cursor=pymysql.cursors.DictCursor)

#使用execute()執(zhí)行sql

cur.execute(select_sql)

#使用fetchall()獲取所有查詢結(jié)果

data=cur.fetchall()

#關閉游標

cur.close()

#關閉數(shù)據(jù)庫連接

db.close()

returndata

select_sql='SELECT*FROMmap_enwordwhereid<=10'#查詢四六級單詞庫中的前十條數(shù)據(jù)

words=select_db(select_sql)#將數(shù)據(jù)賦值給變量words

print(words)#查看結(jié)果查詢四六級單詞庫中以o開頭的單詞數(shù)量。參考答案:importpymysql

"""查詢"""

defselect_db(select_sql):

#建立數(shù)據(jù)庫連接

db=pymysql.connect(

host="",

port=3306,

user="root",

passwd="root",

db="big_data"

)

#通過cursor()創(chuàng)建游標對象,并讓查詢結(jié)果以字典格式輸出

cur=db.cursor(cursor=pymysql.cursors.DictCursor)

#使用execute()執(zhí)行sql

cur.execute(select_sql)

#使用fetchall()獲取所有查詢結(jié)果

data=cur.fetchall()

#關閉游標

cur.close()

#關閉數(shù)據(jù)庫連接

db.close()

returndata

select_sql='SELECTcount(*)FROMmap_enwordwhereenglishlike"o%"'#查詢四六級單詞庫中以o開頭的單詞數(shù)量

words=select_db(select_sql)#將數(shù)據(jù)賦值給變量words

print(words)#查看結(jié)果項目一:Matplotlib應用選擇題使用plot()繪制折線圖時fmt參數(shù)設置為'rD--',其含義是(A)線段顏色為紅色,菱形點標記,破折線連接線段顏色為紅色,菱形點標記,實線連接線段顏色為紅色,窄菱形標記,破折線連接線段顏色為紅色,窄菱形標記,實線連接本任務中使用Matplotlib繪制柱狀圖時,調(diào)用的函數(shù)是(B)plt.plotplt.barplt.barhplt.hist本任務中調(diào)整y坐標軸為對數(shù)軸時,調(diào)用的函數(shù)是(D)plt.ylabelplt.yticksplt.ylimplt.yscale本任務中使用Matplotlib繪制水平條形圖時,調(diào)用的函數(shù)是(D)A.plt.barB.plt.pieC.plt.histD.plt.barh本任務中使用Matplotlib繪制詞云圖時,調(diào)用了哪個庫(B)A.plot_surfaceB.WordCloudC.plt.histD.plt.barh實操練習題使用本項目中的四六級單詞庫數(shù)據(jù)繪制一個折線圖,要求顏色為綠色,點為5像素大小的實心圈標記,線為2像素粗的點劃線形狀。參考答案:#導入Matplotlib庫

importmatplotlib.pyplotasplt

letter=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

enword=[215,149,528,318,255,245,170,182,274,38,27,175,271,112,148,483,35,396,819,364,110,118,205,1,23,7]

#繪制折線圖

plt.plot(letter,enword,color='green',marker='o',

markersize=5,linestyle='-.',linewidth=2)

#或者

#plt.plot(letter,enword,'go-.',markersize=5,linewidth=2)

plt.show()#展示將本項目任務1.1.6示例中的圖例位置設置為為右下角顯示,寫出修改后的完整的示例代碼。參考答案:#導入Matplotlib庫

importmatplotlib.pyplotasplt

letter=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

enword=[215,149,528,318,255,245,170,182,274,38,27,175,271,112,148,483,35,396,819,364,110,118,205,1,23,7]

plt.rcParams['font.sans-serif']=['SimHei']#顯示中文標簽

plt.rcParams['axes.unicode_minus']=False#正常顯示負號

#繪制條形圖

bar=plt.bar(letter,enword)

plt.legend(handles=bar,labels=['某字母開頭的單詞數(shù)'],loc='lowerright')

#修改坐標數(shù)字的字號

plt.xticks(fontsize=12)

plt.yticks(fontsize=12)

plt.show()#展示使用下列農(nóng)作物產(chǎn)量數(shù)據(jù),繪制氣泡圖。df_cl={"經(jīng)度":[11,62,86,67,75],"緯度":[71,5,76,112,156],"產(chǎn)量":[41,12,66,32,89]}參考答案:frommatplotlibimportpyplotaspltplt.rcParams['font.sans-serif']=['SimHei']#顯示中文標簽

df_cl={"經(jīng)度":[11,62,86,67,75],"緯度":[71,5,76,112,156],"產(chǎn)量":[41,12,66,32,89]}

plt.figure(figsize=(8,6))

plt.scatter(df_cl["經(jīng)度"],df_cl["緯度"],s=df_cl["產(chǎn)量"],alpha=0.6)#增加s氣泡的大小取值,alpha設置透明度#s設置點的尺寸,可以是標量,也可以是序列,alpha設置點的透明度

plt.xlabel("經(jīng)度",fontsize=12)#設置x軸標簽

plt.ylabel("維度",fontsize=12)#設置y軸標簽

plt.title("農(nóng)作物分布",fontsize=14)#設置標題

plt.yticks(range(0,91,30))#設置y軸的刻度

plt.xticks(range(0,181,30))#設置x軸的刻度

plt.show()使用以下給定數(shù)據(jù)實現(xiàn)棒棒糖圖。data=[{'letter':'a','num':215},{'letter':'b','num':149},{'letter':'c','num':528},{'letter':'d','num':318},{'letter':'e','num':255},{'letter':'f','num':245},{'letter':'g','num':170},{'letter':'h','num':182},{'letter':'i','num':274},{'letter':'j','num':38},{'letter':'k','num':27},{'letter':'l','num':175},{'letter':'m','num':271},{'letter':'n','num':112},{'letter':'o','num':148},{'letter':'p','num':483},{'letter':'q','num':35},{'letter':'r','num':396},{'letter':'s','num':819},{'letter':'t','num':364},{'letter':'u','num':110},{'letter':'v','num':118},{'letter':'w','num':205},{'letter':'x','num':1},{'letter':'y','num':23},{'letter':'z','num':7}]參考答案:importmatplotlib.pyplotasplt

importnumpyasnp

frompylabimportmpl

#設置顯示中文字體

mpl.rcParams["font.sans-serif"]=["SimHei"]

data=[{'letter':'a','num':215},{'letter':'b','num':149},{'letter':'c','num':528},{'letter':'d','num':318},{'letter':'e','num':255},{'letter':'f','num':245},{'letter':'g','num':170},{'letter':'h','num':182},{'letter':'i','num':274},{'letter':'j','num':38},{'letter':'k','num':27},{'letter':'l','num':175},{'letter':'m','num':271},{'letter':'n','num':112},{'letter':'o','num':148},{'letter':'p','num':483},{'letter':'q','num':35},{'letter':'r','num':396},{'letter':'s','num':819},{'letter':'t','num':364},{'letter':'u','num':110},{'letter':'v','num':118},{'letter':'w','num':205},{'letter':'x','num':1},{'letter':'y','num':23},{'letter':'z','num':7}]

N=26

x=np.arange(N)

y=[]

foreach_dataindata:

y.append(each_data['num'])

my_label=[]

foreach_dataindata:

my_label.append(each_data['letter'])

fig=plt.figure(figsize=(12,9))

plt.stem(x,y)

plt.ylabel('數(shù)量',fontsize=22)

plt.xticks(ticks=x,labels=my_label,ha='right')

#修改坐標數(shù)字的字號

plt.xticks(fontsize=22)

plt.yticks(fontsize=22)

#自動調(diào)整子圖參數(shù),使之填充整個圖像區(qū)域

plt.tight_layout()

plt.savefig("lollipop_word.png",dpi=300)

plt.show()使用下面的文本數(shù)據(jù)集text繪制詞云圖,要求畫布默認長300像素,寬200像素,背景色為黑色。text=“Theworldisbeautiful,butonlythroughhardworkanddiligencecanwecreateabetterlife”參考答案:importmatplotlib.pyplotasplt

fromwordcloudimportWordCloud

#準備文本數(shù)據(jù)

text=“Theworldisbeautiful,butonlythroughhardworkanddiligencecanwecreateabetterlife”

#創(chuàng)建詞云對象

wordcloud=WordCloud(width=300,height=200,background_color="black").generate(text)

#繪制詞云圖

plt.figure(figsize=(6,6),facecolor=None)

plt.imshow(wordcloud,interpolation="bilinear")

plt.axis("off")

#顯示圖表

plt.show()項目二:Matplotlib實戰(zhàn)選擇題任務2.1.1向服務器端發(fā)出HTTP請求,調(diào)用的Python開源包是(C)requestjsonsrequestsjson任務2.2.2中使用plt.pie函數(shù)繪制餅圖時,對其相關參數(shù)的描述正確的是以下哪項(A)explode:列表,表示每個扇區(qū)與圓心的距離,用于突出顯示某些扇區(qū)center:(x,y)元組,表示餅圖的中心位置,默認為(1,1)colors:每個餅塊的顏色。類數(shù)組結(jié)構(gòu)。顏色不可以循環(huán)使用shadow:餅圖下是否有陰影,默認值為TureCSV文件格式規(guī)范的特點是(A)數(shù)據(jù)間使用逗號分隔數(shù)據(jù)間使用分號分隔數(shù)據(jù)間使用Tab制表符分隔數(shù)據(jù)間使用自定義字符分隔任務任務2.x還是本項目?本項目中有好幾個任務呢?已修改題干和選項2.2.4中使用plt.bar函數(shù)繪制柱狀圖,對其相關參數(shù)的描述,不正確的是以下哪項(B)任務2.x還是本項目?本項目中有好幾個任務呢?已修改題干和選項align:表示柱子在x軸上的對齊方式,默認為’center’color:柱狀圖的邊框顏色tick_label:柱狀圖的刻度標簽linewidth:柱狀圖邊框?qū)挾萂atplotlib工具包的特點不包括以下哪個選項(B)是一種開源的可視化工具包是一種非開源的可視化工具包能夠繪制散點圖折線圖等基礎圖標也能夠繪制熱力圖等一些復雜圖表實操練習題實現(xiàn)對“豆瓣電影分類排行榜-劇情片”數(shù)據(jù)的抓取。參考答案:importrequestsimportjsonurl='/j/chart/top_list'params={'type':'11','interval_id':'100:90','action':'','start':'0','limit':'200'}headers={'User-Agent':'Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/101.0.4951.67Safari/537.36'}response=requests.get(url=url,params=params,headers=headers)content=response.json()print(content)withopen('豆瓣電影劇情排行榜.csv','w',encoding='utf-8')asfp:foriincontent:title=i['title']mtype='\\'.join(i['types'])regions='\\'.join(i['regions'])release_date=i['release_date']score=i['score']vote_count=str(i['vote_count'])fp.write(title+','+mtype+','+regions+','+release_date+','+score+','+vote_count+'\n')對“豆瓣電影分類排行榜-劇情片”數(shù)據(jù)進行過濾,只輸出豆瓣評分>9.0的排行記錄。參考答案:importrequestsimportjsonurl='/j/chart/top_list'params={'type':'11','interval_id':'100:90','action':'','start':'0','limit':'200'}headers={'User-Agent':'Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/101.0.4951.67Safari/537.36'}response=requests.get(url=url,params=params,headers=headers)content=response.json()print(content)##foriincontent:##print(json.dumps(i,indent=4,ensure_ascii=False,separators=(',',':')))##breakwithopen('豆瓣電影劇情排行榜.csv','w',encoding='utf-8')asfp:foriincontent:title=i['title']mtype='\\'.join(i['types'])regions='\\'.join(i['regions'])release_date=i['release_date']score=i['score']vote_count=str(i['vote_count'])iffloat(score)>=9.0:fp.write(title+','+mtype+','+regions+','+release_date+','+score+','+vote_count+'\n')對“豆瓣電影分類排行榜-劇情片”數(shù)據(jù)進行統(tǒng)計分析,計算抓取的記錄條數(shù)和評分的平均值。參考答案:importrequestsimportjsonurl='/j/chart/top_list'params={'type':'11','interval_id':'100:90','action':'','start':'0','limit':'200'}headers={'User-Agent':'Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/101.0.4951.67Safari/537.36'}response=requests.get(url=url,params=params,headers=headers)content=response.json()print(content)##foriincontent:##print(json.dumps(i,indent=4,ensure_ascii=False,separators=(',',':')))##breakcount=0sum=0.0withopen('豆瓣電影劇情排行榜.csv','w',encoding='utf-8')asfp:foriincontent:title=i['title']mtype='\\'.join(i['types'])regions='\\'.join(i['regions'])release_date=i['release_date']score=i['score']vote_count=str(i['vote_count'])count=count+1sum=sum+float(score)fp.write(title+','+mtype+','+regions+','+release_date+','+score+','+vote_count+'\n')avg=sum/countprint("抓取記錄數(shù)為:"+str(count))print("評分平均值為:"+str(avg))項目三:PyEcharts應用選擇題(1) (多選)關于工具箱工具配置項的描述正確的有哪些?(ABCD)A.ToolBoxFeatureSaveAsImageOpts()表示保存圖片B.ToolBoxFeatureDataViewOpts()表示數(shù)據(jù)視圖工具C.ToolBoxFeatureDataZoomOpts()表示數(shù)據(jù)區(qū)域縮放D.ToolBoxFeatureMagicTypeOpts()表示動態(tài)類型切換圖例配置項有兩種類型分別是?(A)'plain','scroll''horizontal','vertical''line','bar''True','Fales'下列詞云圖數(shù)據(jù)輸入方式正確的是?(A)[(word1,count1),(word2,count2)][word1,count1,word2,count2](word1,count1),(word2,count2)[{word1,count1},{word2,count2}]象形柱狀圖繪制過程中的symbol_repeat函數(shù)用來指定圖形元素是否重復,該函數(shù)可以取什么值?(A)false/null/undefinedarrowstartorthogonal3D柱狀圖繪制過程中shading函數(shù)控制著三維圖形的著色效果,該函數(shù)可以取到下列何值?(A)realisticleafDepthcenterRadial實操練習題1.在本教材任務3.2.1的基礎上,更換標題位置重新輸出圖表。參考答案:c=(

Bar(init_opts=opts.InitOpts())

.add_xaxis(x_data)

.add_yaxis("第一產(chǎn)業(yè)就業(yè)",y_data1)

.add_yaxis("第二產(chǎn)業(yè)就業(yè)",y_data2)

.add_yaxis("第三產(chǎn)業(yè)就業(yè)",y_data3)

.set_global_opts(title_opts=opts.TitleOpts(

title="三次產(chǎn)業(yè)就業(yè)人員數(shù)量",

subtitle='2012年~2021年',

title_textstyle_opts=opts.TextStyleOpts(font_size=22),

pos_right="center"),

legend_opts=opts.LegendOpts(

type_='scroll',

selected_mode='double',

pos_left='center',

pos_top='95%',

orient='horizontal',

)

)

)

c.render_notebook()2.在本教材任務3.2.1的基礎上,更換標題顏色和大小重新輸出圖表。參考答案:c=(

Bar(init_opts=opts.InitOpts())

.add_xaxis(x_data)

.add_yaxis("第一產(chǎn)業(yè)就業(yè)",y_data1)

.add_yaxis("第二產(chǎn)業(yè)就業(yè)",y_data2)

.add_yaxis("第三產(chǎn)業(yè)就業(yè)",y_data3)

.set_global_opts(

title_opts=opts.TitleOpts(

title="2012年~2021年三次產(chǎn)業(yè)就業(yè)人員數(shù)量",

subtitle='近十年',

title_textstyle_opts=opts.TextStyleOpts(color='red',font_size=20),

subtitle_textstyle_opts=opts.TextStyleOpts(color='#f987a2',font_size=20),

pos_right="center"),

legend_opts=opts.LegendOpts(

type_='scroll',

selected_mode='double',

pos_left='center',

pos_top='95%',

orient='horizontal',

)

)

)

print(type(c))

c.render_notebook()3.以數(shù)據(jù)words繪制詞云圖,標題設置為“學科分類”,words=[("數(shù)學",230),("語文",124),("英語",436),("物理",255),("化學",247),("生物",244),("地理",138),("歷史",184),("政治",12),("考研輔導",165),("考研擇校",247)]。參考答案:frompyecharts.chartsimportWordCloud

words=[

("數(shù)學",230),

("語文",124),

("英語",436),

("物理",255),

("化學",247),

("生物",244),

("地理",138),

("歷史",184),

("政治",12),

("考研輔導",165),

("考研擇校",247),

]

wc=(

WordCloud()

.set_global_opts(

title_opts=opts.TitleOpts(

title="學科分類",

pos_right="center",

pos_top="5%",

title_textstyle_opts=opts.TextStyleOpts(color='black',font_size=22),))

.add("",words)

)

wc.render_notebook()項目四:PyEcharts實戰(zhàn)選擇題以下關于用戶畫像的描述不正確的是哪一項?(B)用戶畫像是指根據(jù)用戶的屬性、用戶偏好、生活習慣、用戶行為等信息而抽象出來的標簽化用戶模型。用戶畫像就不需要給用戶打標簽。用戶畫像中的標簽是通過對用戶信息分析而來的高度精煉的特征標識。用戶畫像通過打標簽可以利用一些高度概括、容易理解的特征來描述用戶(多選)用戶畫像的應用場景有哪些?(ABCD)企業(yè)精準營銷用戶流失用戶偏好產(chǎn)品推薦(多選)屬于用戶畫像標簽屬性的是?(ABCD)年齡學歷婚姻粉絲數(shù)以下哪類圖形可以展示數(shù)據(jù)的區(qū)域位置分布?(D)散點圖柱狀圖折線圖地理圖表(多選)用戶標簽主要包括以下哪些?(ABCD)用戶基本特征社會身份顧客生命周期消費偏好實操練習題借助DataStat數(shù)據(jù)統(tǒng)計類,編寫頁面pv/uv統(tǒng)計函數(shù)page_stat,輸入的rdd包含page、userid、spot_code等列。要求按pv倒序,統(tǒng)計結(jié)果文件保存/home/ysedu/answer/文件目錄下。參考答案:#頁面pvuv

defpage_stat(rdd):

dim_columns=["page"]

indices=[Count(),CountUniq(["userid"])]

ds=DataStat(dim_columns,indices)

rdd=rdd.filter(lambdar:r["spot_code"]=="spot_interval").map(ds.converts).reduceByKey(ds.calculates).map(ds.map_results)

#根據(jù)pv排序

rdd=rdd.sortBy(lambdar:r[-2],False,1)

#保存

fb=open("/home/ysedu/answer/"+sys._getframe().f_code.co_name,"w")

fb.write('\n'.join(rdd.map(ds.tab_text).collect()))借助DataStat數(shù)據(jù)統(tǒng)計類和pandas庫,編寫函數(shù)retention_stat計算用戶訪問的次日留存率~7日留存率,輸入的rdd包含date、userid等列。要求統(tǒng)計結(jié)果文件保存/home/ysedu/answer/文件目錄下。參考答案:#用戶訪問7日留存率

defretention_stat(rdd):

#首次訪問日期

ds=DataStat(["userid"],[Min(["date"])])

f_rdd=rdd.map(add_date_row).map(ds.converts).reduceByKey(ds.calculates).map(ds.map_results)

#用戶訪問記錄

ds=DataStat(["userid","date"],[])

r_rdd=rdd.map(add_date_row).map(ds.converts).reduceByKey(ds.calculates).map(ds.map_results)

#將rdd轉(zhuǎn)為dataframe

schema=StructType([StructField('userid',StringType()),StructField('first_date',StringType())])

f_df=SQLContext(sc).createDataFrame(f_rdd,schema)

schema=StructType([StructField('userid',StringType()),StructField('request_date',StringType())])

r_df=SQLContext(sc).createDataFrame(r_rdd,schema)

#將兩個df合并

f_df=f_df.select("*").toPandas()

r_df=r_df.select("*").toPandas()

pd_df=pd.merge(r_df,f_df)#計算距離首次訪問時間天數(shù)

pd_df["first_date"]=pd.to_datetime(pd_df["first_date"])

pd_df["request_date"]=pd.to_datetime(pd_df["request_date"])

pd_df['days']=pd_df["request_date"]-pd_df["first_date"]

#創(chuàng)建透視表

data=pd.pivot_table(pd_df,values='userid',index='first_date',columns='days',aggfunc=lambdax:len(x.unique()),fill_value='').reset_index()

#將單元格改為數(shù)值格式,用于后續(xù)計算留存比例

data=data.applymap(lambdax:pd.to_numeric(x,errors='ignore'))

#留存率計算,用1days列除以0days為次日留存率,依次類推

create_index=data.columns

pd_df=data.iloc[:,[0,1]]

#這里我們只算到7日留存率

foriinrange(2,8):

s=data[create_index[i]]/data[create_index[1]]

pd_df=pd.concat([pd_df,s],axis=1)

pd_df.columns=['日期','訪問人數(shù)','次日留存率','3日留存率','4日留存率','5日留存率','6日留存率','7日留存率']

pd_df.to_csv("/home/ysedu/answer/"+sys._getframe().f_code.co_name+".csv")根據(jù)stat_result目錄中的total_stat數(shù)據(jù),在jupyter中編寫程序并使用pyecharts柱狀圖展示為總訪問次數(shù)和總訪問人數(shù)兩列。參考答案:#整體pvuv(表格)total_stat

title=["總訪問次數(shù)","總訪問人數(shù)"]

df=pd.read_csv('stat_result/total_stat',sep='\t',header=None

,names=title)

y_data=[int(df.loc[0][0]),int(df.loc[0][1])]

total_stat=(Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))

.add_xaxis(title)

.add_yaxis('',y_data)

.set_global_opts(title_opts=opts.TitleOpts(title="整體訪問PV/UV數(shù)據(jù)",subtitle="總訪問次數(shù)/總訪問人數(shù)",pos_left='center'))

)

total_stat.render_notebook()項目五:Plotly應用選擇題本任務中使用express繪制柱狀圖時,調(diào)用的函數(shù)是(B)express.Barexpress.barexpress.histogramexpress.Histogram本任務中使用graph_objs繪制柱狀圖時,調(diào)用的函數(shù)是(A)plotly.graph_objects.Barplotly.graph_objects.barplotly.graph_objects.Histogramplotly.graph_objects.histogram使用express繪制柱狀圖時,barmode參數(shù)設置為group時,繪制的是?(B)疊加柱狀圖并列柱狀圖覆蓋柱狀圖相對柱狀圖(多選)本任務中使用graph_objs繪制散點圖時,marker參數(shù)的作用有(ACD)調(diào)整數(shù)據(jù)節(jié)點大小調(diào)整數(shù)據(jù)節(jié)點透明度調(diào)整數(shù)據(jù)節(jié)點顏色調(diào)整數(shù)據(jù)節(jié)點格式(多選)fig.update_layout中的font參數(shù)具有哪些取值?(ABC)colorfamilysizesite要設置直方圖的透明度,需要控制哪個參數(shù)?(A)opacitycolor_discrete_sequencecategory_ordersbarmode繪制環(huán)形餅圖時,控制環(huán)形餅圖內(nèi)徑孔的半徑的參數(shù),他的默認值為0,取值范圍是多少?(D)0~100~50~200~1以下參數(shù),哪個是在繪制雙坐標軸圖時用于設置標題格式的?(D)ticktitletickfonttitlefont實操練習題1. 使用任務5.1.2中的數(shù)據(jù),繪制帶文本條柱狀圖。參考答案:importpandasaspd

importnumpyasnp

importplotly.expressaspx

importpymysql

importsqlalchemyassql

importwarnings

warnings.filterwarnings("ignore")

engine=sql.create_engine('mysql+pymysql://root:root@localhost:3306/bdv')

sql1='''select*from1_plastic'''

df=pd.read_sql(sql1,engine)

fig=px.bar(df,

x=df["時間"],

y=df["農(nóng)用塑料薄膜使用量(噸)"],text_auto=True)

fig.update_layout(font_size=22,legend=dict(

orientation="h",

yanchor="bottom",

y=-0.2,

xanchor="center",

x=0.5,

title_text=''

))

fig.update_xaxes(

side='bottom',

title={'text':''}

)

fig.update_yaxes(

side='left',

title={'text':''}

)

fig.update_layout(

title={

'text':"2012年~2019年農(nóng)用塑料薄膜使用量",

'y':0.95,

'x':0.5

})

fig.show()2. 使用任務5.1.3中的數(shù)據(jù),繪制圖例在上方的堆疊柱狀圖。參考答案:importplotlyaspy

importplotly.graph_objsasgo

importpandasaspd

importnumpyasnp

importpymysql

importsqlalchemyassql

importwarnings

warnings.filterwarnings("ignore")

engine=sql.create_engine('mysql+pymysql://root:root@localhost:3306/bdv')

sql1='''select*from1_nlmy'''

df=pd.read_sql(sql1,engine)

trace0=go.Bar(x=df["year"],y=df["ny"],name="農(nóng)業(yè)總產(chǎn)值")

trace1=go.Bar(x=df["year"],y=df["ly"],name="林業(yè)總產(chǎn)值")

trace2=go.Bar(x=df["year"],y=df["my"],name="牧業(yè)總產(chǎn)值")

trace3=go.Bar(x=df["year"],y=df["yy"],name="漁業(yè)總產(chǎn)值")

data=[trace0,trace1,trace2,trace3]

layout=go.Layout(title='農(nóng)林牧漁',barmode='stack',font={'size':22})

fig=go.Figure(data=data,layout=layout)

fig.update_layout(font_size=22,legend=dict(

orientation="h",

yanchor="bottom",

y=1.2,

xanchor="center",

x=0.5,

title_text=''

))

fig.update_xaxes(

side='bottom',

title={'text':''}

)

fig.update_yaxes(

side='left',

title={'text':''}

)

fig.update_layout(

title={

'text':"2012年~2021年農(nóng)林牧漁業(yè)總產(chǎn)值",

'y':0.9,

'x':0.5

})

fig.show()3. 使用任務5.1.4中的數(shù)據(jù),用express繪制并列柱狀圖。參考答案:importplotlyaspy

importplotly.expressaspx

importplotly.graph_objsasgo

importpandasaspd

importnumpyasnp

importpymysql

importsqlalchemyassql

importwarnings

warnings.filterwarnings("ignore")

engine=sql.create_engine('mysql+pymysql://root:root@localhost:3306/bdv')

sql1='''select*from1_fruits'''

df=pd.read_sql(sql1,engine)

trace0=go.Bar(x=df["year"],y=df["gy"],name="果園面積")

trace1=go.Bar(x=df["year"],y=df["xj"],name="香蕉園面積")

trace2=go.Bar(x=df["year"],y=df["pg"],name="蘋果園面積")

trace3=go.Bar(x=df["year"],y=df["gj"],name="柑橘園面積")

trace4=go.Bar(x=df["year"],y=df["ly"],name="梨園面積")

trace5=go.Bar(x=df["year"],y=df["pt"],name="葡萄園面積")

data=[trace0,trace1,trace2,trace3,trace4,trace5]

fig=go.Figure(data)

fig.update_layout(barmode='group')

layout=go.Layout(title='果園面積',barmode='group',font={'size':22})

fig=go.Figure(data=data,layout=layout)

fig.update_layout(font_size=22,legend=dict(

orientation="h",

yanchor="bottom",

y=-0.4,

xanchor="center",

x=0.5,

title_text=''

))

fig.update_xaxes(

side='bottom',

title={'text':''}

)

fig.update_yaxes(

side='left',

title={'text':''}

)

fig.update_layout(

title={

'text':"2012年~2019年果園面積",

'y':0.9,

'x':0.5

})

fig.show()項目六:Plotly實戰(zhàn)選擇題常用的清洗數(shù)據(jù)的包是?(A)PandasMatplotlibSeabornRequest以下哪個Pandas方法能返回數(shù)據(jù)的行數(shù)和列數(shù)?(A)pd.shapepd.head()pd.tail()pd.drop()以下哪個Pandas方法能夠刪除缺失數(shù)據(jù)?(B)pd.drop()pd.dropna()pd.delete()pd.loc()Plotly繪制餅圖的方法,需要使用graph_objs中的哪個函數(shù)?(A)Pie()Scatter()Bar()Histogram()Plotly繪制柱狀圖的方法,需要使用graph_objs中的哪個函數(shù)?(D)Scatter()Histogram()Pie()Bar()與用戶畫像中無關的是以下哪個選項?(D)數(shù)據(jù)清洗和預處理數(shù)據(jù)可視化

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論