Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
uol-msc-ds
data-vis
Commits
f326c075
Commit
f326c075
authored
Jan 04, 2022
by
Jamie Forth
Browse files
add example code notebooks
parent
c8309469
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
topics/resources/notebooks/05/nominals/nominals.ipynb
0 → 100644
View file @
f326c075
This diff is collapsed.
Click to expand it.
topics/resources/notebooks/05/nominals/social-media.csv
0 → 100644
View file @
f326c075
id,gender,pref_service,age,happiness
0,female,Facebook,35,happy
1,female,Facebook,51,very happy
2,female,Facebook,43,sad
3,female,Facebook,27,very sad
4,female,Facebook,18,very sad
5,female,Facebook,54,happy
6,female,Facebook,57,neutral
7,female,Facebook,18,sad
8,female,Facebook,65,very sad
9,female,Facebook,34,very sad
10,female,Facebook,79,sad
11,female,Instagram,32,very sad
12,female,Instagram,24,very sad
13,female,Instagram,37,sad
14,female,Instagram,28,very sad
15,female,Instagram,28,sad
16,female,Instagram,28,very happy
17,female,Instagram,26,very sad
18,female,Instagram,32,sad
19,female,Instagram,33,very happy
20,female,Instagram,30,sad
21,female,Instagram,42,very happy
22,female,Instagram,18,sad
23,female,Instagram,23,neutral
24,female,Instagram,34,sad
25,female,Instagram,18,sad
26,female,Mastodon,39,happy
27,female,Mastodon,31,very happy
28,female,Mastodon,23,neutral
29,female,Mastodon,30,very sad
30,female,Mastodon,20,very happy
31,female,Mastodon,18,neutral
32,female,Twitter,46,neutral
33,female,Twitter,47,very happy
34,female,Twitter,36,sad
35,female,Twitter,35,very happy
36,female,Twitter,18,neutral
37,female,Twitter,24,sad
38,female,Twitter,29,neutral
39,female,Twitter,38,very sad
40,female,Twitter,53,happy
41,female,Twitter,28,neutral
42,female,Other,21,neutral
43,female,Other,39,neutral
44,female,Other,28,very sad
45,male,Facebook,19,very happy
46,male,Facebook,58,happy
47,male,Facebook,27,neutral
48,male,Facebook,32,very sad
49,male,Facebook,24,sad
50,male,Facebook,45,very happy
51,male,Facebook,56,neutral
52,male,Facebook,34,very sad
53,male,Facebook,46,neutral
54,male,Facebook,33,happy
55,male,Facebook,75,very happy
56,male,Facebook,63,neutral
57,male,Facebook,31,happy
58,male,Instagram,31,happy
59,male,Instagram,35,sad
60,male,Instagram,30,very happy
61,male,Instagram,21,very sad
62,male,Instagram,26,neutral
63,male,Instagram,33,sad
64,male,Instagram,31,sad
65,male,Instagram,20,sad
66,male,Instagram,31,neutral
67,male,Instagram,19,very sad
68,male,Instagram,18,sad
69,male,Mastodon,27,sad
70,male,Mastodon,34,very happy
71,male,Mastodon,29,neutral
72,male,Twitter,54,neutral
73,male,Twitter,58,happy
74,male,Twitter,40,very happy
75,male,Twitter,27,neutral
76,male,Twitter,34,neutral
77,male,Twitter,18,very sad
78,male,Twitter,35,sad
79,male,Twitter,34,happy
80,male,Twitter,37,very happy
81,male,Twitter,49,very happy
82,male,Twitter,18,very sad
83,male,Twitter,45,sad
84,male,Twitter,28,happy
85,male,Twitter,45,very sad
86,male,Twitter,37,happy
87,male,Twitter,22,very happy
88,male,Twitter,46,very happy
89,male,Other,22,neutral
90,male,Other,34,very sad
91,male,Other,23,very sad
92,male,Other,24,very happy
93,nonbinary,Mastodon,26,very sad
94,nonbinary,Other,48,neutral
95,prefer not to say,Twitter,44,neutral
topics/resources/notebooks/05/numerical-categorical/numerical-categorical.ipynb
0 → 100644
View file @
f326c075
This diff is collapsed.
Click to expand it.
topics/resources/notebooks/05/numerical-categorical/social-media.csv
0 → 100644
View file @
f326c075
id,gender,pref_service,age,happiness
0,female,Facebook,35,happy
1,female,Facebook,51,very happy
2,female,Facebook,43,sad
3,female,Facebook,27,very sad
4,female,Facebook,18,very sad
5,female,Facebook,54,happy
6,female,Facebook,57,neutral
7,female,Facebook,18,sad
8,female,Facebook,65,very sad
9,female,Facebook,34,very sad
10,female,Facebook,79,sad
11,female,Instagram,32,very sad
12,female,Instagram,24,very sad
13,female,Instagram,37,sad
14,female,Instagram,28,very sad
15,female,Instagram,28,sad
16,female,Instagram,28,very happy
17,female,Instagram,26,very sad
18,female,Instagram,32,sad
19,female,Instagram,33,very happy
20,female,Instagram,30,sad
21,female,Instagram,42,very happy
22,female,Instagram,18,sad
23,female,Instagram,23,neutral
24,female,Instagram,34,sad
25,female,Instagram,18,sad
26,female,Mastodon,39,happy
27,female,Mastodon,31,very happy
28,female,Mastodon,23,neutral
29,female,Mastodon,30,very sad
30,female,Mastodon,20,very happy
31,female,Mastodon,18,neutral
32,female,Twitter,46,neutral
33,female,Twitter,47,very happy
34,female,Twitter,36,sad
35,female,Twitter,35,very happy
36,female,Twitter,18,neutral
37,female,Twitter,24,sad
38,female,Twitter,29,neutral
39,female,Twitter,38,very sad
40,female,Twitter,53,happy
41,female,Twitter,28,neutral
42,female,Other,21,neutral
43,female,Other,39,neutral
44,female,Other,28,very sad
45,male,Facebook,19,very happy
46,male,Facebook,58,happy
47,male,Facebook,27,neutral
48,male,Facebook,32,very sad
49,male,Facebook,24,sad
50,male,Facebook,45,very happy
51,male,Facebook,56,neutral
52,male,Facebook,34,very sad
53,male,Facebook,46,neutral
54,male,Facebook,33,happy
55,male,Facebook,75,very happy
56,male,Facebook,63,neutral
57,male,Facebook,31,happy
58,male,Instagram,31,happy
59,male,Instagram,35,sad
60,male,Instagram,30,very happy
61,male,Instagram,21,very sad
62,male,Instagram,26,neutral
63,male,Instagram,33,sad
64,male,Instagram,31,sad
65,male,Instagram,20,sad
66,male,Instagram,31,neutral
67,male,Instagram,19,very sad
68,male,Instagram,18,sad
69,male,Mastodon,27,sad
70,male,Mastodon,34,very happy
71,male,Mastodon,29,neutral
72,male,Twitter,54,neutral
73,male,Twitter,58,happy
74,male,Twitter,40,very happy
75,male,Twitter,27,neutral
76,male,Twitter,34,neutral
77,male,Twitter,18,very sad
78,male,Twitter,35,sad
79,male,Twitter,34,happy
80,male,Twitter,37,very happy
81,male,Twitter,49,very happy
82,male,Twitter,18,very sad
83,male,Twitter,45,sad
84,male,Twitter,28,happy
85,male,Twitter,45,very sad
86,male,Twitter,37,happy
87,male,Twitter,22,very happy
88,male,Twitter,46,very happy
89,male,Other,22,neutral
90,male,Other,34,very sad
91,male,Other,23,very sad
92,male,Other,24,very happy
93,nonbinary,Mastodon,26,very sad
94,nonbinary,Other,48,neutral
95,prefer not to say,Twitter,44,neutral
topics/resources/notebooks/05/numerical-numerical/numerical-numerical.ipynb
0 → 100644
View file @
f326c075
This diff is collapsed.
Click to expand it.
topics/resources/notebooks/05/ordinals/generosity.csv
0 → 100644
View file @
f326c075
"experience","faith","cause","values"
"not at all","not at all","not at all","not at all"
"not at all","not at all","not at all","not at all"
"not at all","not at all","not at all","not at all"
"not at all","not at all","not at all","a little"
"not at all","not at all","not at all","a little"
"not at all","not at all","not at all","a little"
"not at all","not at all","a little","neutral"
"not at all","not at all","a little","neutral"
"a little","not at all","neutral","a little"
"a little","not at all","a little","a little"
"a little","not at all","a little","a little"
"a little","not at all","a little","a little"
"a little","not at all","a little","strongly"
"a little","not at all","a little","strongly"
"a little","not at all","strongly","strongly"
"a little","not at all","very strongly","strongly"
"a little","not at all","neutral","very strongly"
"a little","a little","strongly","strongly"
"a little","a little","strongly","strongly"
"a little","a little","strongly","strongly"
"neutral","neutral","neutral","neutral"
"neutral","neutral","neutral","neutral"
"neutral","neutral","neutral","neutral"
"neutral","neutral","neutral","neutral"
"neutral","neutral","neutral","neutral"
"neutral","neutral","strongly","neutral"
"neutral","neutral","neutral","very strongly"
"strongly","a little","strongly","strongly"
"strongly","a little","strongly","strongly"
"strongly","a little","strongly","very strongly"
"strongly","a little","strongly","very strongly"
"strongly","a little","very strongly","very strongly"
"strongly","strongly","very strongly","very strongly"
"strongly","strongly","very strongly","very strongly"
"very strongly","strongly","very strongly","very strongly"
"very strongly","very strongly","very strongly","very strongly"
"very strongly","very strongly","very strongly","very strongly"
topics/resources/notebooks/05/ordinals/ordinals.ipynb
0 → 100644
View file @
f326c075
This diff is collapsed.
Click to expand it.
topics/resources/notebooks/10/Plotting in 3D - Vispy.ipynb
0 → 100644
View file @
f326c075
%% Cell type:code id: tags:
```
python
%
matplotlib
inline
```
%% Cell type:code id: tags:
```
python
import
numpy
as
np
import
matplotlib
as
mpl
import
matplotlib.pyplot
as
plt
import
vispy
from
vispy
import
app
,
visuals
,
scene
from
vispy.visuals.transforms
import
STTransform
from
vispy.util.filter
import
gaussian_filter
print
(
vispy
.
sys_info
())
```
%% Cell type:markdown id: tags:
# 3D line with Matplotlib and VisPy
%% Cell type:code id: tags:
```
python
# Prepare data.
n
=
60
x
=
np
.
sin
(
np
.
linspace
(
-
2
,
2
,
n
)
*
np
.
pi
)
y
=
np
.
cos
(
np
.
linspace
(
-
2
,
2
,
n
)
*
np
.
pi
)
z
=
np
.
linspace
(
-
2
,
2
,
n
)
# Create a matplotlib figure manually.
fig
=
plt
.
figure
()
# Add a 3D axes subplot.
ax
=
fig
.
add_subplot
(
projection
=
'3d'
)
ax
.
plot
(
x
,
y
,
z
)
plt
.
show
()
```
%% Cell type:code id: tags:
```
python
# Prepare data.
n
=
60
x
=
np
.
sin
(
np
.
linspace
(
-
2
,
2
,
n
)
*
np
.
pi
)
y
=
np
.
cos
(
np
.
linspace
(
-
2
,
2
,
n
)
*
np
.
pi
)
z
=
np
.
linspace
(
-
2
,
2
,
n
)
# Combine x, y and z into a numpy matrix.
pos
=
np
.
c_
[
x
,
y
,
z
]
# Build visuals.
Plot3D
=
scene
.
visuals
.
create_visual_node
(
visuals
.
LinePlotVisual
)
# Build canvas.
canvas
=
scene
.
SceneCanvas
(
keys
=
'interactive'
,
title
=
'plot3d'
)
# Add a ViewBox to let the user zoom/rotate.
view
=
canvas
.
central_widget
.
add_view
()
view
.
camera
=
'turntable'
view
.
camera
.
fov
=
45
view
.
camera
.
distance
=
6
# Plot.
Plot3D
(
pos
,
width
=
2.0
,
color
=
'red'
,
edge_color
=
'w'
,
symbol
=
'o'
,
face_color
=
(
0.2
,
0.2
,
1
,
0.8
),
parent
=
view
.
scene
)
canvas
.
show
()
app
.
run
()
```
%% Cell type:markdown id: tags:
# 3D surface with Matplotlib and VisPy
%% Cell type:code id: tags:
```
python
# https://matplotlib.org/gallery/mplot3d/surface3d.html
fig
=
plt
.
figure
(
figsize
=
(
6
,
6
))
ax
=
fig
.
add_subplot
(
projection
=
'3d'
)
# Make data.
x
=
np
.
arange
(
-
5
,
5
,
0.25
)
y
=
np
.
arange
(
-
5
,
5
,
0.25
)
# Combine coordinate vectors into coordinate matrices.
xx
,
yy
=
np
.
meshgrid
(
x
,
y
)
# Compute the surface equation.
r
=
np
.
sqrt
(
xx
**
2
+
yy
**
2
)
z
=
np
.
sin
(
r
)
# Plot the surface.
surf
=
ax
.
plot_surface
(
xx
,
yy
,
z
,
cmap
=
mpl
.
cm
.
coolwarm
)
# Customize the z axis.
ax
.
set_zlim
(
-
1
,
1
)
plt
.
show
()
```
%% Cell type:code id: tags:
```
python
# Prepare the data.
n
=
250
x
=
np
.
linspace
(
-
5
,
5
,
n
)
y
=
np
.
linspace
(
-
5
,
5
,
n
)
x
,
y
=
np
.
meshgrid
(
x
,
y
)
r
=
np
.
sqrt
(
x
**
2
+
y
**
2
)
z
=
np
.
sin
(
r
)
*
100
# Build the canvas.
canvas
=
scene
.
SceneCanvas
(
keys
=
'interactive'
,
bgcolor
=
'w'
)
# Set up the camera.
view
=
canvas
.
central_widget
.
add_view
()
view
.
camera
=
scene
.
TurntableCamera
(
up
=
'z'
,
fov
=
60
,
scale_factor
=
2
)
# Build the visuals.
p1
=
scene
.
visuals
.
SurfacePlot
(
z
=
z
,
color
=
(
0.3
,
0.3
,
1
,
1
))
p1
.
transform
=
scene
.
transforms
.
MatrixTransform
()
p1
.
transform
.
scale
([
1
/
249.
,
1
/
249.
,
1
/
249.
])
p1
.
transform
.
translate
([
-
0.5
,
-
0.5
,
0
])
view
.
add
(
p1
)
xax
=
scene
.
Axis
(
pos
=
[[
-
0.5
,
-
0.5
],
[
0.5
,
-
0.5
]],
tick_direction
=
(
0
,
-
1
),
font_size
=
16
,
axis_color
=
'k'
,
tick_color
=
'k'
,
text_color
=
'k'
,
parent
=
view
.
scene
,
axis_label
=
'x'
)
xax
.
transform
=
scene
.
STTransform
(
translate
=
(
0
,
0
,
-
0.2
))
yax
=
scene
.
Axis
(
pos
=
[[
-
0.5
,
-
0.5
],
[
-
0.5
,
0.5
]],
tick_direction
=
(
-
1
,
0
),
font_size
=
16
,
axis_color
=
'k'
,
tick_color
=
'k'
,
text_color
=
'k'
,
parent
=
view
.
scene
,
axis_label
=
'y'
)
yax
.
transform
=
scene
.
STTransform
(
translate
=
(
0
,
0
,
-
0.2
))
# Add a 3D axis to keep us oriented.
axis
=
scene
.
visuals
.
XYZAxis
(
parent
=
view
.
scene
)
canvas
.
show
()
app
.
run
()
```
topics/resources/notebooks/10/mri.npz
0 → 100644
View file @
f326c075
File added
topics/resources/notebooks/10/vispy-isosurface-mri.py
0 → 100644
View file @
f326c075
# Simplified version of: http://api.vispy.org/en/v0.4.0/examples/basics/scene/volume.html
import
sys
import
numpy
as
np
from
vispy
import
app
,
scene
# Prepare canvas.
canvas
=
scene
.
SceneCanvas
(
keys
=
'interactive'
,
size
=
(
800
,
600
))
# Set up a viewbox to display the image with interactive pan/zoom.
view
=
canvas
.
central_widget
.
add_view
()
# Load MRI data.
mri
=
np
.
load
(
'./mri.npz'
)[
'data'
]
mri
=
np
.
flipud
(
np
.
rollaxis
(
mri
,
1
))
surface
=
scene
.
visuals
.
Isosurface
(
mri
,
# Choose level to visualise as surface.
level
=
mri
.
mean
(),
color
=
(
0.5
,
0.6
,
1
,
1
),
shading
=
'smooth'
,
parent
=
view
.
scene
)
surface
.
transform
=
scene
.
transforms
.
STTransform
(
translate
=
(
-
100
,
-
100
,
-
100
))
cam
=
scene
.
cameras
.
TurntableCamera
(
parent
=
view
.
scene
,
fov
=
60
,
distance
=
300
,
name
=
'Turntable'
,
elevation
=
90
,
azimuth
=-
80
)
view
.
camera
=
cam
if
__name__
==
'__main__'
:
canvas
.
show
()
if
sys
.
flags
.
interactive
==
0
:
app
.
run
()
topics/resources/notebooks/10/vispy-isosurface.py
0 → 100644
View file @
f326c075
# http://api.vispy.org/en/v0.4.0/examples/basics/scene/isosurface.html
import
sys
import
numpy
as
np
from
vispy
import
app
,
scene
# Create a canvas with a 3D viewport.
canvas
=
scene
.
SceneCanvas
()
view
=
canvas
.
central_widget
.
add_view
()
# Define a scalar field from which we will generate an isosurface.
def
psi
(
i
,
j
,
k
,
offset
=
(
25
,
25
,
50
)):
x
=
i
-
offset
[
0
]
y
=
j
-
offset
[
1
]
z
=
k
-
offset
[
2
]
th
=
np
.
arctan2
(
z
,
(
x
**
2
+
y
**
2
)
**
0.5
)
r
=
(
x
**
2
+
y
**
2
+
z
**
2
)
**
0.5
a0
=
1
ps
=
((
1.
/
81.
)
*
1.
/
(
6.
*
np
.
pi
)
**
0.5
*
(
1.
/
a0
)
**
(
3
/
2
)
*
(
r
/
a0
)
**
2
*
np
.
exp
(
-
r
/
(
3
*
a0
))
*
(
3
*
np
.
cos
(
th
)
**
2
-
1
))
return
ps
data
=
np
.
abs
(
np
.
fromfunction
(
psi
,
(
50
,
50
,
100
)))
# Create isosurface visual.
surface
=
scene
.
visuals
.
Isosurface
(
data
,
level
=
data
.
max
()
/
4.
,
color
=
(
0.5
,
0.6
,
1
,
1
),
shading
=
'smooth'
,
parent
=
view
.
scene
)
surface
.
transform
=
scene
.
transforms
.
STTransform
(
translate
=
(
-
25
,
-
25
,
-
50
))
# Add a 3D axis to keep us oriented.
axis
=
scene
.
visuals
.
XYZAxis
(
parent
=
view
.
scene
)
# Use a 3D camera.
# Manual bounds; Mesh visual does not provide bounds yet.
# Note how you can set bounds before assigning the camera to the viewbox.
cam
=
scene
.
TurntableCamera
(
elevation
=
30
,
azimuth
=
30
)
cam
.
set_range
((
-
10
,
10
),
(
-
10
,
10
),
(
-
10
,
10
))
view
.
camera
=
cam
if
__name__
==
'__main__'
:
canvas
.
show
()
if
sys
.
flags
.
interactive
==
0
:
app
.
run
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment