Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bae3a10

Browse filesBrowse files
committed
Image slice example: make sure ind is an integer
1 parent 88d90f2 commit bae3a10
Copy full SHA for bae3a10

File tree

Expand file treeCollapse file tree

1 file changed

+6
-8
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-8
lines changed
+6-8Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import print_function
22
import numpy
3-
from matplotlib.pyplot import figure, show
3+
import matplotlib.pyplot as plt
44

55

66
class IndexTracker(object):
@@ -10,18 +10,17 @@ def __init__(self, ax, X):
1010

1111
self.X = X
1212
rows, cols, self.slices = X.shape
13-
self.ind = self.slices/2
13+
self.ind = int(self.slices/2)
1414

1515
self.im = ax.imshow(self.X[:, :, self.ind])
1616
self.update()
1717

1818
def onscroll(self, event):
1919
print("%s %s" % (event.button, event.step))
2020
if event.button == 'up':
21-
self.ind = numpy.clip(self.ind + 1, 0, self.slices - 1)
21+
self.ind = int(numpy.clip(self.ind + 1, 0, self.slices - 1))
2222
else:
23-
self.ind = numpy.clip(self.ind - 1, 0, self.slices - 1)
24-
23+
self.ind = int(numpy.clip(self.ind - 1, 0, self.slices - 1))
2524
self.update()
2625

2726
def update(self):
@@ -30,13 +29,12 @@ def update(self):
3029
self.im.axes.figure.canvas.draw()
3130

3231

33-
fig = figure()
34-
ax = fig.add_subplot(111)
32+
fig, ax = plt.subplots(1, 1)
3533

3634
X = numpy.random.rand(20, 20, 40)
3735

3836
tracker = IndexTracker(ax, X)
3937

4038

4139
fig.canvas.mpl_connect('scroll_event', tracker.onscroll)
42-
show()
40+
plt.show()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.