-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_plots.py
101 lines (82 loc) · 2.11 KB
/
example_plots.py
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
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 8 17:18:17 2022
@author: 3980723
"""
#%%
# external libraries
import seaborn as sns # sns.__version__ == '0.11.0'
import matplotlib.pyplot as plt # matplotlib.__version__ == '3.5.0'
import fancyplots as fp
# get builtin data
data = sns.load_dataset("exercise")
order = ['rest', 'walking', 'running']
hue_order = ['1 min', '15 min', '30 min']
#%% Plain connected stripplot with three categories
fig, ax = plt.subplots(dpi=300)
# add connected points (shows individual data points and connects pairs)
fp.connected_stripplot(
data= data,
x='kind', order=order,
y='pulse',
connect_by='id',
ax=ax
)
plt.show()
#%% Plain connected stripplot with three categories split across three other categories
fig, ax = plt.subplots(dpi=300)
# add connected points (shows individual data points and connects pairs)
fp.connected_stripplot(
data= data,
x='kind', order=order,
y='pulse',
hue='time', hue_order=hue_order,
connect_by='id',
connectorzorder=10,
ax=ax,
)
plt.show()
#%% Combined with a violin plot
# create a figure and axes
fig, ax = plt.subplots(dpi=300)
# create the violin plot (shows smoothed distribution)
sns.violinplot(
data= data,
x='kind', order=order,
y='pulse',
ax=ax
)
# add connected points (shows individual data points and connects pairs)
fp.connected_stripplot(
data= data,
x='kind', order=order,
y='pulse',
connect_by='id',
connectorzorder=10,
markercolor='k',
ax=ax,
)
plt.show()
#%% Combined with a violin plot with hues
# create a figure and axes
fig, ax = plt.subplots(dpi=300)
# create the violin plot (shows smoothed distribution)
sns.violinplot(
data= data,
x='kind', order=order,
y='pulse',
hue='time', hue_order=hue_order,
ax=ax
)
# add connected points (shows individual data points and connects pairs)
fp.connected_stripplot(
data= data,
x='kind', order=order,
y='pulse',
hue='time', hue_order=hue_order,
connect_by='id',
connectorzorder=10,
markercolor='k',
ax=ax,
)
plt.show()