99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁精彩閱讀為啥Pyecharts做出的圖一個是彩色的,一個是黑白呢?
為啥Pyecharts做出的圖一個是彩色的,一個是黑白呢?
2022-01-28
收藏

作者:Python進(jìn)階者

來源:Python爬蟲與數(shù)據(jù)挖掘

一、思路

下面是代碼,首先是讀取excel文件,之后他用了兩種方法生成數(shù)據(jù),一個是datas,另外一個是datas2,這兩個數(shù)據(jù),最后通過比對,發(fā)現(xiàn)竟然是一樣的,數(shù)據(jù)也都相等,但是唯獨(dú)最后生成的html動圖,有點(diǎn)不一樣。

import pandas as pd from pyecharts import options as opts from pyecharts.charts import Map import operator as op import time

df_tb = pd.read_excel('./data.xlsx')

locations = [location for location in df_tb['地區(qū)']]
values = [value for value in df_tb['2016年']]
datas = list(zip(locations, values)) print(datas) for data in datas: print(data) # print(type(data)) print(type(datas)) # print("==============================") # def func(m): #     a = [] #     for i in range(0, 35): #         b = (df_tb['地區(qū)'][i], df_tb[m][i]) #         a.append(b) #     return a # datas2 = func('2016年') # for data in datas2: #     print(data) #     print(type(data)) # print(datas2) # print(type(datas2)) map = (
    Map().
        add('gdp', [location for location in datas], 'china') # .add('gdp', [list(location) for location in datas], 'china') .set_global_opts(
        title_opts=opts.TitleOpts(title='各省貧困縣分布圖'),
        visualmap_opts=opts.VisualMapOpts(max_=150)
                    )
        )
map.render('各省貧困縣分布圖.html') # print(op.eq(datas, func('2016年'))) 

下圖是datas生成的html動圖,是有顏色的,而且有數(shù)據(jù)顯示,如下圖所示。

為啥Py<a href='/map/echarts/' style='color:#000;font-size:inherit;'>echarts</a>做出的圖一個是彩色的,一個是黑白呢?

下圖是datas2生成的html動圖,是無顏色的,而且無數(shù)據(jù)顯示,如下圖所示。

為啥Py<a href='/map/echarts/' style='color:#000;font-size:inherit;'>echarts</a>做出的圖一個是彩色的,一個是黑白呢?

這就確實(shí)很奇怪了,明明數(shù)據(jù)都一樣,為啥最后生成的圖效果差別就這么大呢?不細(xì)心一點(diǎn),還真的難以發(fā)現(xiàn)呢!

二、解決方法

其實(shí)一開始我看到這里,也是覺得非常的奇怪,都沒有任何的想法,后來我想了下,竟然地圖上的省位都可以顯示出來,只是數(shù)據(jù)方面呈現(xiàn)有問題,那么說明肯定是數(shù)據(jù)的問題。從這個思路出發(fā),我很快就找到了問題所在。依次遍歷datas和datas2數(shù)據(jù),查看數(shù)據(jù)的type,很快就看到了問題,如下圖所示:

為啥Py<a href='/map/echarts/' style='color:#000;font-size:inherit;'>echarts</a>做出的圖一個是彩色的,一個是黑白呢?

可以清晰的看到datas列表里邊的數(shù)字的類型是int類型,而datas2列表里邊的數(shù)字的類型是numpy.int64類型,而numpy.int64類型在html中是顯示不出來的,因此問題就水落石出了。只需要在函數(shù)處理的時候?qū)?a href='/map/numpy/' style='color:#000;font-size:inherit;'>numpy.int64類型來個強(qiáng)轉(zhuǎn)變?yōu)閕nt類型,問題就迎刃而解了。只需要將func()函數(shù)中的代碼替換成下面這個就可以了:

def func(m): a = [] for i in range(0, 35):
        b = (df_tb['地區(qū)'][i], int(df_tb[m][i]))
        a.append(b) return a

之后再次運(yùn)行程序,可以看到數(shù)值便可以正常顯示出來了,如下圖所示。

為啥Py<a href='/map/echarts/' style='color:#000;font-size:inherit;'>echarts</a>做出的圖一個是彩色的,一個是黑白呢?

三、總結(jié)

我是Python進(jìn)階者。本文基于粉絲針對Pyecharts可視化過程中的提問,給出了一個滿意的解決方案,達(dá)到了粉絲的要求。

數(shù)據(jù)分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個參數(shù)驗(yàn)證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗(yàn)服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時表示是新驗(yàn)證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計時完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }