In [1]:
%matplotlib notebook


/Users/david/anaconda3/lib/python3.6/site-packages/matplotlib/font_manager.py:279: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
  'Matplotlib is building the font cache using fc-list. '

In [3]:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button, RadioButtons

fig, ax = plt.subplots()
plt.subplots_adjust(left=0.25, bottom=0.25)
t = np.arange(0.0, 1.0, 0.001)
a0 = 5
f0 = 3
s = a0*np.sin(2*np.pi*f0*t)
l, = plt.plot(t, s, lw=2, color='red')
plt.axis([0, 1, -10, 10])

axcolor = 'lightgoldenrodyellow'
axfreq = plt.axes([0.25, 0.1, 0.65, 0.03], facecolor=axcolor)
axamp = plt.axes([0.25, 0.15, 0.65, 0.03], facecolor=axcolor)

sfreq = Slider(axfreq, 'Freq', 0.1, 30.0, valinit=f0)
samp = Slider(axamp, 'Amp', 0.1, 10.0, valinit=a0)


def update(val):
    amp = samp.val
    freq = sfreq.val
    l.set_ydata(amp*np.sin(2*np.pi*freq*t))
    fig.canvas.draw_idle()
sfreq.on_changed(update)
samp.on_changed(update)

resetax = plt.axes([0.8, 0.025, 0.1, 0.04])
button = Button(resetax, 'Reset', color=axcolor, hovercolor='0.975')


def reset(event):
    sfreq.reset()
    samp.reset()
button.on_clicked(reset)

rax = plt.axes([0.025, 0.5, 0.15, 0.15], facecolor=axcolor)
radio = RadioButtons(rax, ('red', 'blue', 'green'), active=0)


def colorfunc(label):
    l.set_color(label)
    fig.canvas.draw_idle()
radio.on_clicked(colorfunc)


Out[3]:
0

In [3]:
import matplotlib.colors

In [5]:
from matplotlib.widgets import TextBox

In [12]:
fig, ax = plt.subplots()
fig.subplots_adjust(left=0.25, bottom=0.25)
t = np.random.rand(512, 512)
a0 = t.max()
g0 = 1
# s = a0*np.sin(2*np.pi*g0*t)
l = ax.matshow(t)
# plt.axis([0, 1, -10, 10])
axgamma = fig.add_axes([0.25, 0.15, 0.65, 0.03])
axgamma2 = fig.add_axes([0.15, 0.15, 0.1, 0.03])
axvmax = fig.add_axes([0.25, 0.1, 0.65, 0.03])

sgamma = Slider(axgamma, '', 0.0, 3.0, valinit=g0, dragging=False)
svmax = Slider(axvmax, 'Max', t.min(), t.max(), valinit=a0)
tgamma = TextBox(axgamma2, "Gamma")

def update(val):
    vmax = svmax.val
    gamma = sgamma.val
    l.set_norm(matplotlib.colors.PowerNorm(gamma, vmax=vmax))
    fig.canvas.draw_idle()
sgamma.on_changed(update)
svmax.on_changed(update)
def update2(val):
    sgamma.set_val(float(tgamma.text))
tgamma.on_submit(update2)

resetax = plt.axes([0.8, 0.025, 0.1, 0.04])
button = Button(resetax, 'Reset', hovercolor='g')


def reset(event):
    sgamma.reset()
    svmax.reset()
button.on_clicked(reset)

rax = plt.axes([0.025, 0.5, 0.15, 0.15], facecolor=axcolor)
radio = RadioButtons(rax, ('red', 'blue', 'green'), active=0)


def colorfunc(label):
    l.set_color(label)
    fig.canvas.draw_idle()
radio.on_clicked(colorfunc)