-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathradar_chart_subplot.py
More file actions
122 lines (104 loc) · 3.48 KB
/
Copy pathradar_chart_subplot.py
File metadata and controls
122 lines (104 loc) · 3.48 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
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python
# coding: utf-8
"""Radar (Spider) Charts with Python and Matplotlib
Author: Polina Lemenkova
ORCID: https://orcid.org/0000-0002-5759-1089
Archive: https://doi.org/10.13140/RG.2.2.31562.82883
License: MIT
See README.md for details.
"""
import os
from math import pi
import matplotlib.artist as martist
import matplotlib.pylab as pylab
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
from matplotlib.offsetbox import AnchoredText
os.chdir(os.path.dirname(os.path.abspath(__file__)))
df = pd.read_csv("Tab-Morph.csv")
params = {'figure.figsize': (10, 5),
'figure.dpi': 300,
'figure.titlesize': 14,
'font.family': 'Palatino',
'axes.grid': True,
'axes.labelsize': 8,
'polaraxes.grid': True,
}
pylab.rcParams.update(params)
def add_at(ax, t, loc=2):
fp = dict(size=11)
_at = AnchoredText(t, loc=loc, prop=fp)
ax.add_artist(_at)
return _at
# show 6 different variables on our radar chart, so take them out and set as a np.array.
labels = np.array(['Median', 'Max', '1stQ', '3rdQ', 'Min', 'Mean'])
stats1 = df.loc[1, labels].values
stats2 = df.loc[5, labels].values
stats3 = df.loc[12, labels].values
stats4 = df.loc[15, labels].values
stats5 = df.loc[18, labels].values
stats6 = df.loc[23, labels].values
# close the plot
angles = np.linspace(0, 2*np.pi, len(labels), endpoint=False)
angles = np.concatenate((angles, [angles[0]]))
stats1 = np.concatenate((stats1, [stats1[0]]))
stats2 = np.concatenate((stats2, [stats2[0]]))
stats3 = np.concatenate((stats3, [stats3[0]]))
stats4 = np.concatenate((stats4, [stats4[0]]))
stats5 = np.concatenate((stats5, [stats5[0]]))
stats6 = np.concatenate((stats6, [stats6[0]]))
fig = plt.figure()
fig.suptitle('Radar chart for the bathymetry of the Mariana Trench',
x=0.5, y=0.99)
# subplot 1
ax = fig.add_subplot(231, polar=True)
ax.plot(angles, stats1, 'o-', linewidth=2)
ax.fill(angles, stats1, c='g', alpha=0.2)
ax.set_thetagrids(angles * 180/np.pi, labels)
plt.title('profile (nr.1)')
# ax.annotate('(A)', xy=(1.02, .90), xycoords="axes fraction")
add_at(ax, "A")
# subplot 2
ax = fig.add_subplot(232, polar=True)
ax.plot(angles, stats2, 'o-', linewidth=2)
ax.fill(angles, stats2, c='#a0d8ef', alpha=0.4)
ax.set_thetagrids(angles * 180/np.pi, labels)
plt.title('profile (nr.5)')
add_at(ax, "B")
# subplot 3
ax = fig.add_subplot(233, polar=True)
ax.plot(angles, stats3, 'o-', linewidth=2)
ax.fill(angles, stats3, c='#ee827c', alpha=0.4)
ax.set_thetagrids(angles * 180/np.pi, labels)
plt.title('profile (nr.12)')
add_at(ax, "C")
# subplot 4
ax = fig.add_subplot(234, polar=True)
ax.plot(angles, stats4, 'o-', linewidth=2)
ax.fill(angles, stats4, c='plum', alpha=0.4)
ax.set_thetagrids(angles * 180/np.pi, labels)
plt.title('profile (nr.15)')
add_at(ax, "D")
# subplot 5
ax = fig.add_subplot(235, polar=True)
ax.plot(angles, stats5, 'o-', linewidth=2)
ax.fill(angles, stats5, c='#ffd900', alpha=0.2)
ax.set_thetagrids(angles * 180/np.pi, labels)
plt.title('profile (nr.19)')
add_at(ax, "E")
# subplot 6
ax = fig.add_subplot(236, polar=True)
ax.plot(angles, stats6, 'o-', linewidth=2)
ax.fill(angles, stats6, c='#c3d825', alpha=0.4)
ax.set_thetagrids(angles * 180/np.pi, labels)
plt.title('profile 24')
add_at(ax, "F")
plt.tight_layout()
plt.subplots_adjust(top=0.85, bottom=0.08,
left=0.10, right=0.95,
hspace=0.25, wspace=0.35
)
fig.savefig('plot_RadarChart.png', dpi=300)
plt.show()