Created
September 21, 2018 09:04
-
-
Save markloyman/cf871781f29d7df9f6c51143d5912071 to your computer and use it in GitHub Desktop.
prototype for interactive 3d volume visualization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
class VolumeViz: | |
def __init__(self, fig, volume): | |
self.volume = volume | |
self.figure = fig | |
self.ax1 = fig.add_subplot(121) | |
self.ax2 = fig.add_subplot(122) | |
self.ax1.set_title('click') | |
self.ax1.imshow(self.volume[:, :, 0]) | |
self.cid = self.figure.canvas.mpl_connect('button_press_event', self) | |
self.figure.canvas.draw() | |
def __call__(self, event): | |
if event.inaxes!=self.ax1: | |
return | |
print('%s click: button=%d, x=%d, y=%d, xdata=%f, ydata=%f' % | |
('double' if event.dblclick else 'single', event.button, | |
event.x, event.y, event.xdata, event.ydata)) | |
self.ax2.cla() | |
self.ax2.plot(self.volume[np.round(event.xdata).astype('int'), np.round(event.ydata).astype('int'), :]) | |
self.figure.canvas.draw() | |
data = np.random.randn(300, 250, 200) | |
fig = plt.figure() | |
VolumeViz(fig, volume=data) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment