如何将matplotlib中的雷达图与类似于饼图的类别相结合

2024-10-02 02:27:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图将matplotlib中的雷达图与饼图相结合,这样我就有了如下示例:

https://agilityhealthradar.com/wp-content/uploads/2016/07/TeamHealth_Web_Detailed_View_934-e1531225843825.png

如你所见,在图表的内部有一个雷达图,你可以在其中输入一些值,而在外部,你有不同的类别和子类别。我试着把matplotlib雷达图和一个饼图相结合,我把分类放在那里。但这失败了。有没有人知道如何在雷达图中添加一些类别,以及雷达图不同部分的子类别?在

谢谢。在

-------------------------编辑--------------------

按照建议,我试着把雷达图和饼图结合起来,但我不明白为什么它看起来不像预期的那样。在

plot example result with radar chart and a pie chart

import numpy as np
import matplotlib.pyplot as plt

fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(8, 8), subplot_kw=dict(polar=True))
sizes = [32, 20, 15, 10, 10, 8, 5]
labels = 'apple', 'banana', 'cherry', 'durian', 'elderberries', 'figs', 'grapes'
d = ax.pie(sizes, labels=labels, radius=1, autopct='%1.1f%%', startangle=90, labeldistance=1.05)
ax.set(aspect="equal")
plt.show()

Tags: httpsimportcom示例labelsmatplotlibaschart
1条回答
网友
1楼 · 发布于 2024-10-02 02:27:15

一种选择是在极坐标图的位置创建饼图。具体如下:

import matplotlib.pyplot as plt

fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(8, 8), subplot_kw=dict(polar=True, zorder=1))
fig.subplots_adjust(left=0.3, right=0.7, top=0.7, bottom=0.3)

sizes = [32, 20, 15, 10, 10, 8, 5]
labels = 'apple', 'banana', 'cherry', 'durian', 'elderberries', 'figs', 'grapes'

ax2 = fig.add_subplot(111, label="pie axes", zorder=0)
d = ax2.pie(sizes, labels=labels, radius=1.75, autopct='%1.1f%%', startangle=90, labeldistance=1.05)
ax2.set(aspect="equal")
plt.show()

enter image description here

相关问题 更多 >

    热门问题