0%

科研绘图记录(玫瑰图)

玫瑰图

玫瑰图的特点

  • 适合对比分析,没有占比意义

  • 数据差异不宜过大

    在玫瑰图中,一般使用圆弧的半径表示数据的大小。尤其适合对比大小相近的数值。当数据差异过大,还是推荐使用柱状图表现数据。

  • 可以反应数据的周期性

    一般情况下,圆形有周期的特性。如果数据恰好来自于一个周期内,比如星期、月份,则可以按照周期的概念划分出玫瑰图的花瓣。

玫瑰图的使用

可以修改扇形的形状,例如修改为长方形,在图表中心进行额外标注(如图1)

图1

还可以修改玫瑰图整体轮廓。例如当数据条数并不太多时,使用扇形玫瑰图会比圆形玫瑰图更加清晰,表现效果更好。(如图2)

图2

为进行更清晰的数据对比,可以将扇形部分分颜色并列,或者将小扇形叠加。(如图3)

图3

利用matplotlib实现玫瑰图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import numpy as np
import matplotlib.pyplot as plt
import random

'''Rose Plot'''
''' This code creates a circle with cirtain part of colored fanwise
y=20
x=np.pi/2
w=np.pi/2
color=(206/255,32/255,69/255)
edgecolor=(206/255,32/255,69/255)

fig = plt.figure(figsize=(13.44,7.5))
ax = fig.add_subplot(111,projection='polar') #建立一个极坐标系
ax.bar(x,y,width=w,bottom=10,color=color,edgecolor=edgecolor)
plt.show()
fig.savefig("D:\_A_GGDD\_A_Research\picturelearning\Rose_plot.png",dpi=400,bbox_inches='tight',transparent=True)
'''

'''Rose Plot'''
'''An example'''
''' We divide the circle into 10 equal parts'''
x1 = [np.pi/10 + np.pi*i/5 for i in range(1,11)]
x2 = [np.pi/20+np.pi*i/5 for i in range(1,11)]
x3 = [3*np.pi/20+np.pi*i/5 for i in range(1,11)]

y1 = [7000 for i in range(0,10)]
y2 = [6000 for i in range(0,10)]
fig=plt.figure(figsize=(13.44,7.5))
ax = fig.add_subplot(111,projection='polar')
ax.axis('off') # Hide the polar axis
ax.bar(x1,y1,width=np.pi/5,color=(220/255,222/255,221/255),edgecolor=(204/255,206/255,205/255))
ax.bar(x1,y2,width = np.pi/5,color='w',edgecolor=(204/255,206/255,205/255))

'''Now we finish the frame of the circle, then we can add data to the circle. For example, we use random data to fill the circle.'''
random.seed(100)
y4 = [random.randint(4000,5500) for i in range(10)]
y5 = [random.randint(3000,5000) for i in range(10)]

ax.bar(x2,y4,width = np.pi/10,color=(206/255,32/255,69/255),edgecolor=(206/255,32/255,69/255))
ax.bar(x3,y5,width = np.pi/10,color=(34/255,66/255,123/255),edgecolor=(34/255,66/255,123/255))

'''We almost finish the circle, but it's not really beautiful. We intend to add a small white circle in the centre'''
y6 = [2000 for i in range(0,10)]
ax.bar(x1,y6,width=np.pi/5,color='w',edgecolor='w')

# Adding text descriptions to the rose plot
# Method 1: Add labels for each section

labels = ['Section 1', 'Section 2', 'Section 3', 'Section 4', 'Section 5',
'Section 6', 'Section 7', 'Section 8', 'Section 9', 'Section 10']

# Add text labels at the outer edge of each section
for i, (angle, label) in enumerate(zip(x1, labels)):
ax.text(angle, 7500, label, rotation=np.degrees(angle)-90,
ha='center', va='center', fontsize=10, fontweight='bold')

# Method 2: Add a title to the plot
ax.set_title('Nightingale Rose Chart Example', pad=20, fontsize=16, fontweight='bold')

# Method 3: Add legend for the different colors
from matplotlib.patches import Patch
legend_elements = [Patch(facecolor=(206/255,32/255,69/255), label='Category A'),
Patch(facecolor=(34/255,66/255,123/255), label='Category B')]
ax.legend(handles=legend_elements, loc='upper right', bbox_to_anchor=(1.3, 1.0))

# Method 4: Add value labels on the bars
for i, (angle, val1, val2) in enumerate(zip(x2, y4, y5)):
# Label for red bars
ax.text(angle, val1 + 200, f'{val1}', ha='center', va='bottom',
fontsize=8, color='darkred', fontweight='bold')
# For blue bars
for i, (angle, val) in enumerate(zip(x3, y5)):
ax.text(angle, val + 200, f'{val}', ha='center', va='bottom',
fontsize=8, color='darkblue', fontweight='bold')

# Method 5: Add a central label
ax.text(0, 0, 'Rose Chart\n2025', ha='center', va='center',
fontsize=14, fontweight='bold',
bbox=dict(boxstyle="round,pad=0.3", facecolor='white', alpha=0.8))

plt.show()
fig.savefig(r"D:\_A_GGDD\_A_Research\PictureLearning\Nightingale_Rose_Chart\Rose_plot(texted).png",dpi=400,bbox_inches='tight',transparent=True)

代码中同时罗列了不同的图表标记方式,现展示中心图表名作为例子,其他效果可以按照描述自行选择。