码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 环状分组柱状图 Python


    代码:

    1. import matplotlib.pyplot as plt
    2. import numpy as np
    3. # 数据
    4. np.random.seed(123)
    5. group1 = 100 * np.random.rand(5)
    6. group2 = 100 * np.random.rand(5)
    7. group3 = 100 * np.random.rand(5)
    8. group4 = 100 * np.random.rand(5)
    9. groups = [group1, group2, group3, group4]
    10. group_names = list('ABCD')
    11. group_colors = ['#ff706d', '#7baf06', '#01bfc5', '#cb7bf6']
    12. # 画图
    13. fig = plt.figure(figsize=(8, 8), dpi=300, facecolor='white')
    14. ax = fig.add_subplot(projection='polar')
    15. ax.set_theta_zero_location("N")
    16. ax.set_theta_direction(-1)
    17. radii = [0]
    18. colors = ['white']
    19. for g, c in zip(groups, group_colors):
    20. radii.extend(g)
    21. colors.extend([c]*len(g))
    22. radii.append(0)
    23. colors.append('white')
    24. radii.pop()
    25. colors.pop()
    26. N = len(radii)
    27. r_lim = 180
    28. scale_lim = 100
    29. scale_major = 20
    30. bottom = 40
    31. theta = np.linspace(0.0, 2 * np.pi, N, endpoint=False)
    32. width = 2 * np.pi / (N + 9)
    33. # 画出柱状图
    34. ax.bar(theta, radii, width=width, bottom=bottom, color=colors)
    35. # 画出刻度
    36. def scale(ax, bottom, scale_lim, theta, width):
    37. t = np.linspace(theta-width/2, theta+width/2, 6)
    38. for i in range(int(bottom), int(bottom+scale_lim+scale_major), scale_major):
    39. ax.plot(t, [i]*6, linewidth=0.25, color='gray', alpha=0.8)
    40. # 画出刻度值
    41. def scale_value(ax, bottom, theta, scale_lim):
    42. for i in range(int(bottom), int(bottom+scale_lim+scale_major), scale_major):
    43. ax.text(theta,
    44. i,
    45. f'{i-bottom}',
    46. fontsize=3,
    47. alpha=0.8,
    48. va='center',
    49. ha='center'
    50. )
    51. s_list = []
    52. g_no = 0
    53. aa = ["OA","AA","K","EA","HA"]
    54. for t, r in zip(theta, radii):
    55. if r == 0:
    56. s_list.append(t)
    57. if t == 0:
    58. scale_value(ax, bottom, t, scale_lim)
    59. else:
    60. scale(ax, bottom, scale_lim, t, width)
    61. else:
    62. t2 = np.rad2deg(t)
    63. # 标出每根柱的名称
    64. ax.text(t, r + bottom + scale_major*0.6,
    65. aa[g_no],
    66. fontsize=3,
    67. rotation=90-t2 if t < np.pi else 270-t2,
    68. rotation_mode='anchor',
    69. va='center',
    70. ha='left' if t < np.pi else 'right',
    71. color='black',
    72. clip_on=False
    73. )
    74. if g_no == (len(aa)-1):
    75. g_no = 0
    76. else:
    77. g_no += 1
    78. s_list.append(2 * np.pi)
    79. for i in range(len(s_list)-1):
    80. t = np.linspace(s_list[i]+width, s_list[i+1]-width, 50)
    81. ax.plot(t, [bottom-scale_major*0.4]*50, linewidth=0.5, color='black')
    82. ax.text(s_list[i]+(s_list[i+1]-s_list[i])/2,
    83. bottom-scale_major*1.2,
    84. group_names[i],
    85. va='center',
    86. ha='center',
    87. fontsize=4,
    88. )
    89. ax.set_rlim(0, bottom+scale_lim+scale_major)
    90. ax.axis('off')
    91. plt.show()

  • 相关阅读:
    机器学习——K-means算法详解及python应用
    金仓数据库KingbaseES客户端应用参考手册--18. oid2name
    十一黄金周12306 抢票开源脚本登上热榜!探寻Python自动化与数据交互的无限可能!
    Kafka - 深入了解Kafka基础架构:Kafka的基本概念
    postgreSQL 导出数据、导入
    【数据结构初阶】三、 线性表里的链表(无头+单向+非循环链表)
    UIKit Inside: frame bounds position anchorPoint center
    VMware Horizon 8 运维系列(四)云桌面虚拟机被移除网卡
    为什么Dapr是比SpringCloud和Istio更优雅的微服务框架?
    智能合约语言(eDSL)—— 并行化方案
  • 原文地址:https://blog.csdn.net/qq_45100200/article/details/133190941
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号