public
Created

Simple pcolormesh data explorer

  • Download Gist
slice_explorer.py
Python
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
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()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.