import matplotlib.figure
import matplotlib.cm
import matplotlib.colors
import matplotlayers
import matplotlayers.backends.tk
import Tkinter
import numpy

#matplotlib.colors.colorConverter.set_gray_mode(True)

X = numpy.linspace(0, 5)
Y = numpy.linspace(0, 5)
SINE = numpy.sin(X[numpy.newaxis, :] * Y[:, numpy.newaxis])

x = numpy.linspace(-3, 3)
sine = numpy.sin(x)
arctan = numpy.arctan(x) + 0.5

fig = matplotlib.figure.Figure(frameon=False)

left = matplotlayers.Stack(fig, left=0.15, width=0.3)
left1 = matplotlayers.LayerPlot(x=x, y=sine, linewidth=10)
left2 = matplotlayers.LayerPlot(x=x, y=arctan, linewidth=10)
left.add_layer(left1)
left.add_layer(left2)

right = matplotlayers.Stack(fig, left=0.55, width=0.3)
right1 = matplotlayers.LayerPColorFast(X=X, Y=Y, C=SINE,
    cmap=matplotlib.cm.jet)
right.add_layer(right1)

left.render()
right.render()

tk = Tkinter.Tk()
tk.geometry('+100+200')
backend = matplotlayers.backends.tk.FigureCanvasTk(tk, fig, shape=(1500, 800))

def switch():
    print "Switching ..."
    print "matplotlib.colors.colorConverter.set_gray_mode(True)"
    matplotlib.colors.colorConverter.set_gray_mode(True)
    left1.set_changed()
    left2.set_changed()
    left.render()
    right1.set_changed()
    right.render()
    # Nowmally, when the layers have changed, a .render() would do it.
    backend.update()

matplotlayers.backends.tk.has_mainloop = True
tk.after(4000, switch)
tk.mainloop()
