import
matplotlib.pyplot as plt
import
numpy as np
summer_rain
=
[[
3
,
5
,
7
], [
15
,
17
,
12
,
12
,
15
],
[
26
,
21
,
15
]]
winter_rain
=
[[
16
,
14
,
12
], [
31
,
20
,
25
,
23
,
28
],
[
29
,
31
,
35
,
41
]]
ticks
=
[
'Low'
,
'Mid'
,
'High'
]
summer_rain_plot
=
plt.boxplot(summer_rain,
positions
=
np.array(
np.arange(
len
(summer_rain)))
*
2.0
-
0.35
,
widths
=
0.6
)
winter_rain_plot
=
plt.boxplot(winter_rain,
positions
=
np.array(
np.arange(
len
(winter_rain)))
*
2.0
+
0.35
,
widths
=
0.6
)
def
define_box_properties(plot_name, color_code, label):
for
k, v
in
plot_name.items():
plt.setp(plot_name.get(k), color
=
color_code)
plt.plot([], c
=
color_code, label
=
label)
plt.legend()
define_box_properties(summer_rain_plot,
'#D7191C'
,
'Summer'
)
define_box_properties(winter_rain_plot,
'#2C7BB6'
,
'Winter'
)
plt.xticks(np.arange(
0
,
len
(ticks)
*
2
,
2
), ticks)
plt.xlim(
-
2
,
len
(ticks)
*
2
)
plt.ylim(
0
,
50
)
plt.title(
'Grouped boxplot using matplotlib'
)