# this demos and locks in the functionality of the 2-D interpolate function.  
# I expect this will break soon, as Autoplot picks a strange order for these plots: 
# the plotElements ids are 1,2,3 and the plot ids are 4,3,2.

print 'here in interpolate.jy'

ds= ripples( 20,20 )

setLayout(2,2)
waitUntilIdle()

plot( 0, ds )
print 'plot 0'

xx= linspace( 2,18,100 )
yy= linspace( 1,17,100 )

plot( 1, interpolateGrid( ds, xx, yy ), title='plot 1' )
print 'plot 1'

xx= linspace( 4,22,100 )
yy= linspace( 3,21,100 )

plot( 3, interpolateGrid( ds, xx, yy ), title='plot 3' )
print 'plot 3'

xx= linspace( 1,19,100 )
yy= linspace( 0,18,100 )

plot( 2, xx, interpolate( ds, xx, yy ), title='plot 2' )
print 'plot 2'

#plot( 4, xx, yy, interpolate( ds, xx, yy ) )
(plot5,pe)= plot( 4, xx, yy, linewidth=0.2, symbol='none' )
print 'plot 4'

# the following 3 lines make an overplot on the upper left panel.
zrange= dom.plots[4].zaxis.range   # kludge, a future version won't affect zrange
dom.plotElements[4].plotId= 'plot_1'
dom.plots[4].zaxis.range= zrange

print 'zrange'

dom.controller.delete( plot5 )

print 'deletePlot'

dom.canvases[0].marginRow.bottom='100%-3em'
dom.canvases[0].marginColumn.right='100.00%-7.0em'

print 'layout:'
print ' marginRow:', dom.canvases[0].marginRow.top,dom.canvases[0].marginRow.bottom
print ' marginColumn: ', dom.canvases[0].marginColumn.left,dom.canvases[0].marginColumn.right

writeToPng('test037_interpolate.png')
print 'wrote to png, done.'