作圖詳解利用Python繪制技術(shù)功效圖的方法第二輯_第1頁(yè)
作圖詳解利用Python繪制技術(shù)功效圖的方法第二輯_第2頁(yè)
作圖詳解利用Python繪制技術(shù)功效圖的方法第二輯_第3頁(yè)
作圖詳解利用Python繪制技術(shù)功效圖的方法第二輯_第4頁(yè)
作圖詳解利用Python繪制技術(shù)功效圖的方法第二輯_第5頁(yè)
已閱讀5頁(yè),還剩3頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、作圖詳解 利用 Python 繪制技術(shù)功效圖的方法(第二輯)上一篇我們利用 Python 畫了氣泡圖(相關(guān)鏈接:作圖 詳解 | 利用 Python 繪制技術(shù)功效圖的方法) ,本期的教程是 將氣泡矩陣圖原來(lái)的氣泡變成餅圖或環(huán)圖,從而使技術(shù)功效 氣泡圖增加一個(gè)新的數(shù)據(jù)分析維度。感謝上一篇讀者 Zoe , Nano 的留言和建議,這次我們的程序增加了數(shù)據(jù)標(biāo)簽的顯 示功能, 插入了可選擇 R 語(yǔ)言 ggplot 繪圖風(fēng)格的語(yǔ)句, 并改 進(jìn)了自動(dòng)添加坐標(biāo),這個(gè)版本的程序不需要再手動(dòng)在程序里 逐一鍵入坐標(biāo)軸上的“技術(shù)手段”和“技術(shù)效果”啦,可以自動(dòng)對(duì) 應(yīng) Excel 坐標(biāo)生成橫縱坐標(biāo)標(biāo)簽。 糖果色氣泡餅

2、/氣泡環(huán)自動(dòng)生成方法: STEP 1:將 Excel (示 例數(shù)據(jù):百度網(wǎng)盤鏈接 : , 密碼: v5vw )按照如下格式準(zhǔn)備好。 Excel 包含多個(gè)工作表, 第一個(gè)工作表中是技術(shù)功效表,其中的數(shù)據(jù)大小代表氣泡的 大小(也就是餅圖或者環(huán)圖大?。?,如下圖所示:其他的工 作表中是每一個(gè)細(xì)分技術(shù)領(lǐng)域(技術(shù)手段和技術(shù)效果相對(duì)應(yīng) 的細(xì)分技術(shù)領(lǐng)域)中的文獻(xiàn)分布,比如可以是該細(xì)分技術(shù)領(lǐng) 域的主要申請(qǐng)人、主要國(guó)家、或是專利的法律狀態(tài)等,如下 圖所示: 將該 Excel 表命名為“散餅數(shù)據(jù)表 .xlsx ”。如果你要修改這個(gè).xlsxExcel 表的名稱, 那么對(duì)應(yīng)的修改程序中的“散餅數(shù)據(jù)表即可。 STEP

3、2 :1) 將程序復(fù)制粘貼至 spyder 中的源程序編 輯器(單擊 file ,new file ,跳出一個(gè)新文件) 2) 復(fù)制程序, 修改讀入excel名稱、設(shè)置圖片標(biāo)題(修改“XXX改為所需的領(lǐng)域):3) 保存,單擊 F5 或者綠色向右的小箭頭。得到如下效果: 矩陣氣泡餅圖 矩陣氣泡餅圖中心紅色數(shù)據(jù)為該環(huán)的數(shù)據(jù)量總和,三個(gè)黑色 數(shù)據(jù)為不同部分的數(shù)據(jù)量: 是不是很簡(jiǎn)單呢 “矩陣氣泡餅圖程序及說(shuō)明如下:import numpy as np # 導(dǎo)入 python 的數(shù)值計(jì)算擴(kuò)展包 numpy , 并重命名為 npimport matplotlib.pyplot as plt # 導(dǎo)入 Pyt

4、hon 的繪圖擴(kuò)展包 matplotlib ,并重新命名為 pltimport pandas as pd # 導(dǎo)入 python 的數(shù)據(jù)處理擴(kuò)展包 pandas ,并重命名為 pd, 該包用于讀寫 excel 文件 import matplotlib.patches as mpatches#plt.style.use(ggplot)# 打開(kāi)或者關(guān)閉 R 語(yǔ)言風(fēng)格 繪圖 sheet1=pd.read_excel( 散餅數(shù)據(jù)表 .xlsx, 工作表 1)# 從 excel 的工作表 1 中讀出數(shù)據(jù), sheet 名稱根據(jù)實(shí)際情 況修改 x=i 1for i in range(len(sheet1.

5、columns)# 獲取數(shù)據(jù) 表的列,作為 x 軸輔助繪圖數(shù)據(jù) y_index=i for i inrange(len(sheet1.index)# 獲取縱軸有多少行 y = i for y_data in range(len(x) for i in range(1,len(y_index) 1)# 生成 y 軸輔助數(shù)據(jù) fig, ax = plt.subplots()# 創(chuàng)建子圖 colors = gold, lightcoral, lightskyblue,yellowgreen# 顏色列表 ax.set(aspect=equal)# 設(shè)置圖形的對(duì)稱,不然餅會(huì)橢圓 for index in

6、 range(len(y_index):# 對(duì)轉(zhuǎn)置后的每一列進(jìn)行循環(huán) for i,j,r inzip(x,yindex,sheet1.Tsheet1.indexindex):#循環(huán)執(zhí)行,每次從 x,yindex 中讀取一個(gè)數(shù),從轉(zhuǎn)置后的 excel 表格中讀取一列中的一個(gè)數(shù)據(jù) sheet=pd.read_excel( 散餅數(shù)據(jù)表 .xlsx,str(sheet1.columnsi-1) str(sheet1.indexindex)# 從 excel 中的相應(yīng) sheet 中讀取數(shù)據(jù),根據(jù) excel 中的工作 表名修改 ifr/max(sheet1.max()/2 < 0.2: ax.p

7、ie(sheet 數(shù)量 , explode=None, labels=None, colors=w, autopct=%d, shadow=False, startangle=90,radius=1/2,center=(i, j),frame=True,textprops=fontsize:8)# 繪制散餅圖 ax.pie(sheet 數(shù)量 , explode=None, labels=None, colors=colors, autopct=None, shadow=False, startangle=90,radius=r/max(sheet1.max()/2,center=(i,j),f

8、r ame=True) else: ax.pie(sheet 數(shù)量 , explode=None, labels=None, colors=colors, autopct=%d, shadow=False, startangle=90,radius=r/max(sheet1.max()/2,center=(i,j),frame=True,textprops=fontsize:8)# 繪制散餅圖 ,面積大小 由 radius 調(diào)節(jié)。 #ax.pie(1, radius=np.sqrt(r/np.pi)/30/2,colors=w,center=(i,j),frame=T rue)# 增加甜甜圈的

9、圈 ,圈大小由 radius 調(diào)節(jié) #ax.text(i,j,str(r),fontsize=int(np.sqrt(r/np.pi)*0.8),#horizontalalignment=center,verticalalignment=center)#增加數(shù)據(jù)標(biāo)簽 , 字體大小由 fontsize 調(diào)節(jié)plt.grid(True)# 增加?xùn)鸥?plt.xlabel( 技術(shù)手段分類 ,size=14)#x 軸說(shuō)明 plt.ylabel( 技術(shù)效果 ,size=14)#y 軸說(shuō)明 plt.title(XXX 領(lǐng)域技 術(shù)功效分析 ,size=14)# 圖片名稱 plt.xticks(x,sheet

10、1.columns)# 利用 excel 表中的表格橫軸更 新 x 軸標(biāo)度 plt.yticks(i 1for i inrange(len(sheet1.index),list(sheet1.index),size=14)# 利 用 excel 表中的表格縱軸更新 y 軸標(biāo)度 plt.xlim(0,len(sheet1.columns) 1)# 設(shè)置 x 軸范圍,美化圖表 plt.ylim(0,len(sheet1.index) 1)# 設(shè)置 y 軸范圍,美化圖表 plt.legend(handles=mpatches.Patch(color=colorsi,label= (sheet.ind

11、exi) for i in range(len(sheet.index) ,loc=best,bbox_to_an chor=(1.05,1.0),borderaxespad =0.)plt.show()#顯示圖片“矩陣氣泡環(huán)圖”程序及說(shuō)明如下: import numpy as np # 導(dǎo)入 python 的數(shù)值計(jì)算擴(kuò)展包 numpy ,并重命名為 npimportmatplotlib.pyplot as plt # 導(dǎo)入 Python 的繪圖擴(kuò)展包 matplotlib ,并重新命名為 pltimport pandas as pd # 導(dǎo)入 python 的數(shù)據(jù)處理擴(kuò)展包 pandas ,

12、并重命名為 pd ,該包用 于讀寫 excel 文件 import matplotlib.patches as mpatches# 導(dǎo)入用于生成圖例的庫(kù) #plt.style.use(ggplot)# 打開(kāi)或者關(guān) 閉R語(yǔ)言風(fēng)格繪圖 sheet仁pd.read_excel( 散餅數(shù)據(jù) 表.xlsx,工作表1)#從excel的工作表1中讀出數(shù)據(jù),sheet 名稱根據(jù)實(shí)際情況修改x=i 1for i inrange(len(sheet1.columns)# 獲取數(shù)據(jù)表的列,作為 x 軸輔 助繪圖數(shù)據(jù) y_index=i for i inrange(len(sheet1.index)# 獲 取縱軸有多

13、少行 y = i for y_data in range(len(x) for i in range(1,len(y_index) 1)# 生成 y 軸輔助數(shù)據(jù) fig, ax = plt.subplots()# 創(chuàng)建子圖 colors = yellowgreen, gold, lightskyblue, lightcoral# 顏色列表 ax.set(aspect=equal)# 設(shè)置圖形的對(duì)稱,不然餅會(huì)橢圓 for index in range(len(y_index):# 對(duì)轉(zhuǎn)置后的每一列進(jìn)行循環(huán) for i,j,r inzip(x,yindex,sheet1.Tsheet1.index

14、index):#循環(huán)執(zhí)行,每次從 x,yindex 中讀取一個(gè)數(shù), 從轉(zhuǎn)置后的 excel 表格中讀 取一列中的一個(gè)數(shù)據(jù)sheet=pd.read_excel( 散餅數(shù)據(jù)表.xlsx,str(sheet1.columnsi-1)str(sheet1.indexindex)# 從 excel 中的相應(yīng) sheet 中讀取數(shù) 據(jù),根據(jù) excel 中的工作表名修改ifnp.sqrt(r/np.pi)/30 < 0.4: ax.pie(sheet 數(shù)量 , explode=None, labels=None, colors=w, autopct=%d, shadow=False, starta

15、ngle=90,radius=1/2,center=(i, j),frame=True,textprops=fontsize:8)# 繪制散餅圖 ax.pie(sheet 數(shù)量 , explode=None, labels=None, colors=colors, autopct=None, shadow=False, startangle=90,radius=r/max(sheet1.max()/2,center=(i,j),fr ame=True) else: ax.pie(sheet 數(shù)量 , explode=None, labels=None, colors=colors, autop

16、ct=%d, shadow=False, startangle=90,radius=r/max(sheet1.max()/2,center=(i,j),fr ame=True,textprops=fontsize:8)# 繪制散餅圖 ,面積大小 由 radius 調(diào)節(jié)。 ax.pie(1, radius=r/max(sheet1.max()/2/2,colors=w,center=(i,j),fram e=True)# 增加甜甜圈的圈 ,圈大小由 radius 調(diào)節(jié) ax.text(i,j,str(r),fontsize=8, horizontalalignment=center,vertic

17、alalignment=center,col or=red)# 增加數(shù)據(jù)標(biāo)簽 , 字體大小由 fontsize 調(diào)節(jié) plt.grid(True)# 增加?xùn)鸥?plt.xlabel( 技術(shù)手段分類,size=14)#x 軸說(shuō)明 plt.ylabel( 技術(shù)效果 ,size=14)#y 軸說(shuō)明 plt.title(XXX 領(lǐng)域技術(shù)功效分析 ,size=14)# 圖片名稱plt.xticks(x,sheet1.columns)# 利用 excel 表中的表格橫軸更新 x 軸標(biāo)度 plt.yticks(i 1for iinrange(len(sheet1.index),list(sheet1.index),size=14)# 利 用 excel 表中的表格縱軸更新 y 軸標(biāo)度plt.xlim(0,len(sheet1.columns) 1)# 設(shè)置 x 軸范圍,美化圖表 plt.ylim(0,len(sheet1.index) 1)# 設(shè)置 y 軸范圍,美化圖表 plt.legend(handles=

溫馨提示

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

評(píng)論

0/150

提交評(píng)論