In [1]:
%matplotlib inline
from IPython.html import widgets
import matplotlib.pylab as plt
import numpy as np
In [2]:
x=np.random.rand(100) * np.ones((100,100))
y=np.random.rand(100) * np.ones((100,100))
plt.imshow(x)
Out[2]:
In [3]:
plt.imshow(y)
Out[3]:
In [4]:
#some fits data to work with
from astropy.io import fits
space=fits.getdata('iabf01bzq_flt.fits')
z=space[0:x.shape[0],0:x.shape[1]]
plt.imshow(z,cmap=plt.cm.gray)
Out[4]:
In [5]:
images=[x,y]
def on_click(blink_image):
plt.imshow(images[blink_image],cmap=plt.cm.gray)
widgets.interact(on_click, blink_image = widgets.ToggleButtonWidget(min=0,max=2))
Out[5]:
In [6]:
#view images in a list with a slider
ims=[x,y,z]
def slide_image(images):
num=len(ims)
def view_image(i):
plt.imshow(images[i],cmap=plt.cm.gray)
widgets.interact(view_image,i=(0,num-1))
slide_image(ims)
I don't know why the slider wideget below is mostly ignoring the limits I gave it, it could be the versions I wrote this example with or I've missed something. I'll try this in the latest versions of widgets with python3 to see if it goes away
In [7]:
#now lets try scaling the image live
scaled = widgets.IntSliderWidget(description="Scale", value=1,min=1,max=15,step=1)
#simplistic, level of std scaling
def scale_image(image):
middle=np.median(image)
std=np.std(image)
def view_image(amount) :
_imin=middle-std*amount
_imax=middle+std*amount
plt.imshow(image,vmin=_imin, vmax=_imax,cmap=plt.cm.gray)
widgets.interact(view_image,amount=(scaled.value))
scale_image(z)
In [7]: