DDR爱好者之家 Design By 杰米
本文实例为大家分享了python画环形图的具体代码,供大家参考,具体内容如下
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 则为绿色渐变,小于则为蓝色渐变
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
# 获取绿色的个数,standardRedIndex为要将那个颜色改为红色
def listGreen(number, standardRedIndex):
colors = []
for i in range(number):
if i == standardRedIndex - 1:
colors.append('r')
else:
colors.append('#6CAD4F')
return colors
# 画环形图
def circularGraph(outerData, innerData, labels, standardRedIndex):
data = pd.DataFrame([outerData, innerData], columns=labels)
# 设置字体这样才可以显示中文
plt.rcParams['font.sans-serif'] = 'Microsoft YaHei'
plt.rcParams['axes.unicode_minus'] = False
plt.figure(figsize=(8, 5))
colors = gradual(len(labels))
# 数据内环
plt.pie(data.iloc[1, :], radius=0.65, wedgeprops=dict(width=0.3, edgecolor='w'), colors=colors)
# 数据外环
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是位置坐标,borderaxespad将图例放外面 frameon=False去掉图例边框
# bbox_to_anchor 的y坐标
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图片处理操作》
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米
暂无评论...
更新日志
2025年10月29日
2025年10月29日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]
