Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Simple pcolormesh data explorer
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
def main():
data = np.random.random((10,10,10))
ex = Explorer(data)
ex.show()
class Explorer(object):
def __init__(self, data):
self.data = data
nz = self.data.shape[0] - 1
self.fig, self.ax = plt.subplots()
self.ax.set_title('Slices along the first axes')
self.sliderax = self.fig.add_axes([0.2, 0.02, 0.65, 0.04])
self.slider = Slider(self.sliderax, 'Slice', 0, nz, valinit=0)
self.slider.on_changed(self.update)
self.im = self.ax.pcolormesh(data[0,:,:], vmin=data.min(), vmax=data.max())
def update(self, i):
self.im.set_array(self.data[int(i),:,:].ravel())
self.fig.canvas.draw()
def show(self):
plt.show()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment