-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathplotting.py
More file actions
78 lines (59 loc) · 2.14 KB
/
plotting.py
File metadata and controls
78 lines (59 loc) · 2.14 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
# -*- coding: utf-8 -*-
"""Usefull methods for patch and image visualization.
"""
# Author: Taibou BIRGUI SEKOU <taibou.birgui_sekou@insa-cvl.fr>
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button
def plot_images(images, nrows=None, ncols=None,
title='', figsize=(4.2, 4), cmap=None):
plt.figure(figsize=figsize)
c = np.ceil(np.sqrt(len(images))) if ncols is None else ncols
l = len(images)//c if nrows is None else nrows
for i, im in enumerate(images):
plt.subplot(l, c, i+1)
plt.imshow(np.squeeze(im), cmap=cmap)
plt.xticks(())
plt.yticks(())
plt.suptitle(title)
plt.subplots_adjust(0.08, 0.02, 0.92, 0.85, 0.08, 0.23)
plt.show()
def plot_3D(data):
fig, ax = plt.subplots()
plt.subplots_adjust( bottom=0.25)
plt.imshow(data[10])
axcolor = 'lightgoldenrodyellow'
axZ = plt.axes([0.15, 0.1, 0.65, 0.03], facecolor=axcolor)
sZ = Slider(axZ, 'Z', 1, data.shape[0], valinit=0)
def update(val):
Z = int(sZ.val)
ax.imshow(data[Z])
sZ.on_changed(update)
resetax = plt.axes([0.8, 0.025, 0.1, 0.04])
button = Button(resetax, 'Reset', color=axcolor, hovercolor='0.975')
def reset(event):
sZ.reset()
button.on_clicked(reset)
plt.show()
def plot_4D(data):
fig, ax = plt.subplots()
plt.subplots_adjust( bottom=0.25)
plt.imshow(data[10, 10])
axcolor = 'lightgoldenrodyellow'
axZ = plt.axes([0.15, 0.1, 0.65, 0.03], facecolor=axcolor)
axT = plt.axes([0.15, 0.15, 0.65, 0.03], facecolor=axcolor)
sZ = Slider(axZ, 'Z', 1, data.shape[1], valinit=0)
sT = Slider(axT, 'T', 1, data.shape[0], valinit=0)
def update(val):
T = int(sT.val)
Z = int(sZ.val)
ax.imshow(data[T, Z])
sZ.on_changed(update)
sT.on_changed(update)
resetax = plt.axes([0.8, 0.025, 0.1, 0.04])
button = Button(resetax, 'Reset', color=axcolor, hovercolor='0.975')
def reset(event):
sZ.reset()
sT.reset()
button.on_clicked(reset)
plt.show()