最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2020年03月25日 10:26:31   作者:goacademic  
這篇文章主要為大家詳細(xì)介紹了python畫環(huán)形圖的相關(guān)代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

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

import os
 
import pandas as pd
import matplotlib.pyplot as plt
import random
import numpy as np
 
 
# 獲取漸變色的list
def 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
 
 
# 獲取綠色的個數(shù),standardRedIndex為要將那個顏色改為紅色
def listGreen(number, standardRedIndex):
 colors = []
 for i in range(number):
  if i == standardRedIndex - 1:
   colors.append('r')
  else:
   colors.append('#6CAD4F')
 return colors
 
 
# 畫環(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)

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

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

鱼台县| 平南县| 铜川市| 淄博市| 怀柔区| 清水河县| 甘孜| 文化| 无极县| 泊头市| 友谊县| 龙门县| 平乐县| 灵川县| 巴彦县| 土默特左旗| 扎囊县| 昭平县| 库尔勒市| 宣威市| 江门市| 政和县| 永清县| 保康县| 射阳县| 棋牌| 会东县| 南康市| 正镶白旗| 永昌县| 延津县| 枣强县| 龙口市| 万山特区| 罗田县| 武功县| 湖州市| 南木林县| 池州市| 晴隆县| 赤城县|