Created
May 31, 2013 02:49
-
-
Save joferkington/5682690 to your computer and use it in GitHub Desktop.
Simple pcolormesh data explorer
This file contains hidden or 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 | |
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