FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib/examples/statistics/boxplot_vs_violin_demo.py at master · feisuo/matplotlib · GitHub
feisuo
matplotlib
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib
/
examples
/
statistics
/
boxplot_vs_violin_demo.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
39 lines (32 loc) · 1.17 KB
Breadcrumbs
matplotlib
/
examples
/
statistics
/
boxplot_vs_violin_demo.py
Copy path
File metadata and controls
39 lines (32 loc) · 1.17 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
# Box plot - violin plot comparison
#
# Note that although violin plots are closely related to Tukey's (1977) box plots,
# they add useful information such as the distribution of the sample data (density trace).
#
# By default, box plots show data points outside 1.5 x the inter-quartile range as outliers
# above or below the whiskers wheras violin plots show the whole range of the data.
#
# Violin plots require matplotlib >= 1.4.
import
matplotlib
.
pyplot
as
plt
import
numpy
as
np
fig
,
axes
=
plt
.
subplots
(
nrows
=
1
,
ncols
=
2
,
figsize
=
(
12
,
5
))
# generate some random test data
all_data
=
[
np
.
random
.
normal
(
0
,
std
,
100
)
for
std
in
range
(
6
,
10
)]
# plot violin plot
axes
[
0
].
violinplot
(
all_data
,
showmeans
=
False
,
showmedians
=
True
)
axes
[
0
].
set_title
(
'violin plot'
)
# plot box plot
axes
[
1
].
boxplot
(
all_data
)
axes
[
1
].
set_title
(
'box plot'
)
# adding horizontal grid lines
for
ax
in
axes
:
ax
.
yaxis
.
grid
(
True
)
ax
.
set_xticks
([
y
+
1
for
y
in
range
(
len
(
all_data
))])
ax
.
set_xlabel
(
'xlabel'
)
ax
.
set_ylabel
(
'ylabel'
)
# add x-tick labels
plt
.
setp
(
axes
,
xticks
=
[
y
+
1
for
y
in
range
(
len
(
all_data
))],
xticklabels
=
[
'x1'
,
'x2'
,
'x3'
,
'x4'
])
plt
.
show
()
Back
|
FazBrowse Home
|
New Git URL