-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathradar_chart.py
More file actions
112 lines (89 loc) · 2.11 KB
/
radar_chart.py
File metadata and controls
112 lines (89 loc) · 2.11 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"""Examples of different radar charts."""
import os
import openpyxl as xl
import pandas as pd
from sql2excel.chart import RadarChart
fields = [
"Agricultural Sciences",
"Engineering",
"Health Sciences",
"Humanities",
"Natural Sciences",
"Social Sciences",
]
data = {
"Field": fields,
"2003-2012": (1.2, 0.5, 1.5, 2, 0.9, 1.3),
"2013-2022": (1.5, 0.95, 1.1, 1.8, 0.7, 1.2),
}
df = pd.DataFrame(data=data)
chart = RadarChart()
wb = xl.Workbook()
ws = wb.active
# Default
chart.plot(
df,
ws,
section_heading="Default: Relative Field Strength - Dummy Data",
width=12,
height=12,
)
# Filled
chart.plot(
df,
ws,
chart_type="filled",
section_heading="Filled: Relative Field Strength - Dummy Data",
width=12,
height=12,
)
# Adding a reference (baseline)
average = pd.Series([1] * 6, name="Average")
df = pd.concat((df, average), axis=1)
chart.plot(
df,
ws,
section_heading="With reference or baseline: Relative Field Strength - Dummy Data",
width=12,
height=12,
)
# Radar unit (y-axis major unit): you can also set the unit manually
chart.plot(
df,
ws,
section_heading="Radar Unit (= 1): Relative Field Strength - Dummy Data",
width=12,
height=12,
radar_unit=1,
)
chart.plot(
df,
ws,
section_heading="Radar Unit (= 0.5): Relative Field Strength - Dummy Data",
width=12,
height=12,
radar_unit=0.5,
)
# Radar unit steps: lower values lead to lower number of levels (rings)
chart.plot(
df,
ws,
section_heading="Radar Unit Steps: Relative Field Strength - Dummy Data",
width=12,
height=12,
radar_unit_steps=1.8,
)
# y-axis major unit = (max(df) - min(df)) / radar_unit_steps
# Yet another example with radar unit steps: lower values lead to lower number of levels (rings)
chart.plot(
df,
ws,
section_heading="Yet another example with radar unit steps: Relative Field Strength - Dummy Data",
width=12,
height=12,
radar_unit_steps=7,
)
file_name = os.path.join(
os.path.dirname(os.path.dirname(__file__)), "data", "radar_chart.xlsx"
)
wb.save(file_name)