国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python畫(huà)環(huán)形圖的方法

瀏覽:2日期:2022-08-01 11:00:59

本文實(shí)例為大家分享了python畫(huà)環(huán)形圖的具體代碼,供大家參考,具體內(nèi)容如下

import os import pandas as pdimport matplotlib.pyplot as pltimport randomimport numpy as np # 獲取漸變色的listdef gradual(number): colors = [] h = 0.00001 gradual2 = random.uniform(0, 1) r = gradual2 if gradual2 >= 0.5: g = h b = gradual2 else: g = gradual2 b = h colors.append((r, g, b, 1)) for i in range(number - 1): # 大于0.5 則為綠色漸變,小于則為藍(lán)色漸變 if gradual2 >= 0.5: g = 1 if ((1 - h) / number) > 1 else (g + (1 - h) / number) else: b = 1 if ((1 - h) / number) > 1 else (b + (1 - h) / number) colors.append((r, g, b, 1)) return colors # 獲取綠色的個(gè)數(shù),standardRedIndex為要將那個(gè)顏色改為紅色def listGreen(number, standardRedIndex): colors = [] for i in range(number): if i == standardRedIndex - 1: colors.append(’r’) else: colors.append(’#6CAD4F’) return colors # 畫(huà)環(huán)形圖def circularGraph(outerData, innerData, labels, standardRedIndex): data = pd.DataFrame([outerData, innerData], columns=labels) # 設(shè)置字體這樣才可以顯示中文 plt.rcParams[’font.sans-serif’] = ’Microsoft YaHei’ plt.rcParams[’axes.unicode_minus’] = False plt.figure(figsize=(8, 5)) colors = gradual(len(labels)) # 數(shù)據(jù)內(nèi)環(huán) plt.pie(data.iloc[1, :], radius=0.65, wedgeprops=dict(width=0.3, edgecolor=’w’), colors=colors) # 數(shù)據(jù)外環(huán) plt.pie(data.iloc[0, :], radius=1, wedgeprops=dict(width=0.3, edgecolor=’w’), colors=listGreen(len(labels), standardRedIndex)) # 獲取ax label ax = plt.subplot(1, 1, 1) # loc是位置,bbox_to_anchor是位置坐標(biāo),borderaxespad將圖例放外面 frameon=False去掉圖例邊框 # bbox_to_anchor 的y坐標(biāo) y = -1 / 40 * len(labels) + 0.5 ax.legend(labels, loc=4, bbox_to_anchor=(1.3, y), borderaxespad=0., frameon=False) plt.show() circularGraph([30, 30, 20, 40, 20, 20, 40, 20, 20, 40, 20], [30, 30, 20, 40, 20, 20, 40, 20, 20, 40, 20], [’甲硫桿菌’, ’霍爾德曼氏菌屬’, ’Faecali菌屬’, ’瘤胃菌屬’, ’Faecali菌屬’, ’Faecali菌屬’, ’瘤胃菌屬’, ’Faecali菌屬’, ’Faecali菌屬’, ’瘤胃菌屬’, ’Faecali菌屬’], 3)

python畫(huà)環(huán)形圖的方法

更多精彩內(nèi)容請(qǐng)點(diǎn)擊專(zhuān)題: 《python圖片處理操作》

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 行唐县| 明光市| 万源市| 营口市| 墨脱县| 邛崃市| 禹城市| 江源县| 临澧县| 垦利县| 社旗县| 沧州市| 兴业县| 凤山市| 芮城县| 体育| 五寨县| 平阳县| 扶绥县| 晋宁县| 广州市| 江陵县| 高邮市| 乐昌市| 阿鲁科尔沁旗| 平阳县| 临武县| 安泽县| 诸城市| 杭锦后旗| 华池县| 拜城县| 苗栗市| 永顺县| 甘肃省| 波密县| 浦江县| 河津市| 万源市| 姜堰市| 丰都县|