gpt4 book ai didi

python - 在 python 中创建一个圆形条形图

转载 作者:太空狗 更新时间:2023-10-30 01:52:50 24 4
gpt4 key购买 nike

我对在我的项目中使用圆形条形图可视化很感兴趣,但不知道如何在 Python 中生成它。请在下面查看我所说的“圆形条形图”的示例。数据将以 Pandas 系列的形式出现——下面的虚拟示例模糊地反射(reflect)了情节:

A 33
B 62
C 56
D 70

有什么想法吗?

here, using R

最佳答案

您还可以使用 dismissed donut chart :

import matplotlib.pyplot as plt
from matplotlib import cm
from math import log10

labels = list("ABCDEFG")
data = [21, 57, 88, 14, 76, 91, 26]
#number of data points
n = len(data)
#find max value for full ring
k = 10 ** int(log10(max(data)))
m = k * (1 + max(data) // k)

#radius of donut chart
r = 1.5
#calculate width of each ring
w = r / n

#create colors along a chosen colormap
colors = [cm.terrain(i / n) for i in range(n)]

#create figure, axis
fig, ax = plt.subplots()
ax.axis("equal")

#create rings of donut chart
for i in range(n):
#hide labels in segments with textprops: alpha = 0 - transparent, alpha = 1 - visible
innerring, _ = ax.pie([m - data[i], data[i]], radius = r - i * w, startangle = 90, labels = ["", labels[i]], labeldistance = 1 - 1 / (1.5 * (n - i)), textprops = {"alpha": 0}, colors = ["white", colors[i]])
plt.setp(innerring, width = w, edgecolor = "white")

plt.legend()
plt.show()

输出:

enter image description here

关于python - 在 python 中创建一个圆形条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49729748/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com