示例#1
0
    def _plot_default(self):
        # Create a GridContainer to hold all of our plots: 2 rows, 4 columns:
        container = GridContainer(fill_padding=True,
                                  bgcolor="lightgray", use_backbuffer=True,
                                  shape=(2, 4))

        arrangements = [('top left', 'h'),
                        ('top right', 'h'),
                        ('top left', 'v'),
                        ('top right', 'v'),
                        ('bottom left', 'h'),
                        ('bottom right', 'h'),
                        ('bottom left', 'v'),
                        ('bottom right', 'v')]
        orientation_name = {'h': 'horizontal', 'v': 'vertical'}

        pd = ArrayPlotData(image=lena())
        # Plot some bessel functions and add the plots to our container
        for origin, orientation in arrangements:
            plot = Plot(pd, default_origin=origin, orientation=orientation)
            plot.img_plot('image')

            # Attach some tools to the plot
            plot.tools.append(PanTool(plot))
            zoom = ZoomTool(plot, tool_mode="box", always_on=False)
            plot.overlays.append(zoom)

            title = '{0}, {1}'
            plot.title = title.format(orientation_name[orientation],
                                      origin.replace(' ', '-'))

            # Add to the grid container
            container.add(plot)

        return container
示例#2
0
def _create_plot_component():
    # Create a GridContainer to hold all of our plots
    container = GridContainer(padding=20, fill_padding=True,
                              bgcolor="lightgray", use_backbuffer=True,
                              shape=(3,3), spacing=(12,12))

    # Create the initial series of data
    x = linspace(-5, 15.0, 100)
    pd = ArrayPlotData(index = x)

    # Plot some bessel functions and add the plots to our container
    for i in range(9):
        pd.set_data("y" + str(i), jn(i,x))
        plot = Plot(pd)
        plot.plot(("index", "y" + str(i)),
                  color=tuple(COLOR_PALETTE[i]), line_width=2.0,
                  bgcolor = "white", border_visible=True)

        # Tweak some of the plot properties
        plot.border_width = 1
        plot.padding = 10

        # Set each plot's aspect ratio based on its position in the
        # 3x3 grid of plots.
        n,m = divmod(i, 3)
        plot.aspect_ratio = float(n+1) / (m+1)

        # Attach some tools to the plot
        plot.tools.append(PanTool(plot))
        zoom = ZoomTool(plot, tool_mode="box", always_on=False)
        plot.overlays.append(zoom)

        # Add to the grid container
        container.add(plot)
    return container
def _create_plot_component():
    # Create a GridContainer to hold all of our plots: 2 rows, 3 columns:
    container = GridContainer(padding=40,
                              fill_padding=True,
                              bgcolor="lightgray",
                              use_backbuffer=True,
                              shape=(2, 3),
                              spacing=(20, 20))

    # Create the initial series of data
    x = linspace(-5, 15.0, 100)
    pd = ArrayPlotData(index=x)

    # Plot some bessel functions and add the plots to our container
    for i in range(6):
        pd.set_data("y" + str(i), jn(i, x))
        plot = Plot(pd)
        plot.plot(("index", "y" + str(i)),
                  color=tuple(COLOR_PALETTE[i]),
                  line_width=2.0,
                  bgcolor="white",
                  border_visible=True)

        # Tweak some of the plot properties
        plot.border_width = 1
        plot.padding = 0
        plot.padding_top = 30

        # Attach some tools to the plot
        plot.tools.append(PanTool(plot))
        zoom = ZoomTool(plot, tool_mode="box", always_on=False)
        plot.overlays.append(zoom)

        # Add to the grid container (
        container.add(plot)

    # Set the upper-left plot to only be resizable vertically, and to have a
    # fixed horizontal width. This also constrains the width of the first column.
    ul_plot = container.components[0]
    ul_plot.set(resizable="v", width=200)
    ul_plot.overlays.append(
        PlotLabel("Not horizontally resizable", component=ul_plot))

    # Set the bottom center plot to have a fixed width and height.
    # This also constrains the height of the bottom row and the width of
    # the middle column.
    cplot = container.components[4]
    cplot.set(resizable="", bounds=[400, 400])
    cplot.overlays.append(PlotLabel("Not resizable", component=cplot))

    container.padding_top = 50
    container.overlays.append(
        PlotLabel(
            'Resize the window - some plots resize, others cannot '
            '(see source code)',
            component=container,
            font="swiss 16",
            overlay_position="top"))

    return container
示例#4
0
 def test_nonresizable_container(self):
     cont = GridContainer(shape=(1, 1), resizable="")
     comp1 = StaticPlotComponent([200, 300])
     cont.add(comp1)
     cont.do_layout()
     self.assert_tuple(comp1.position, (0, 0))
     self.assert_tuple(comp1.bounds, (200, 300))
     return
 def test_nonresizable_container(self):
     cont = GridContainer(shape=(1,1), resizable="")
     comp1 = StaticPlotComponent([200,300])
     cont.add(comp1)
     cont.do_layout()
     self.assert_tuple(comp1.position, (0,0))
     self.assert_tuple(comp1.bounds, (200,300))
     return
 def test_single_cell(self):
     cont = GridContainer(shape=(1,1))
     comp1 = StaticPlotComponent([200,300])
     cont.add(comp1)
     cont.do_layout()
     # it would be nice to make all boolean tests here trigger
     # assert failures, maybe using Pypy?
     self.assert_tuple(comp1.position, (0,0))
     self.assert_tuple(comp1.bounds, (200,300))
     return
示例#7
0
 def test_single_cell(self):
     cont = GridContainer(shape=(1, 1))
     comp1 = StaticPlotComponent([200, 300])
     cont.add(comp1)
     cont.do_layout()
     # it would be nice to make all boolean tests here trigger
     # assert failures, maybe using Pypy?
     self.assert_tuple(comp1.position, (0, 0))
     self.assert_tuple(comp1.bounds, (200, 300))
     return
示例#8
0
def _create_plot_component():
    # Create a GridContainer to hold all of our plots: 2 rows, 3 columns:
    container = GridContainer(padding=40, fill_padding=True,
                              bgcolor="lightgray", use_backbuffer=True,
                              shape=(2,3), spacing=(20,20))

    # Create the initial series of data
    x = linspace(-5, 15.0, 100)
    pd = ArrayPlotData(index = x)

    # Plot some bessel functions and add the plots to our container
    for i in range(6):
        pd.set_data("y" + str(i), jn(i,x))
        plot = Plot(pd)
        plot.plot(("index", "y" + str(i)),
                  color=tuple(COLOR_PALETTE[i]), line_width=2.0,
                  bgcolor = "white", border_visible=True)

        # Tweak some of the plot properties
        plot.border_width = 1
        plot.padding = 0
        plot.padding_top = 30

        # Attach some tools to the plot
        plot.tools.append(PanTool(plot))
        zoom = ZoomTool(plot, tool_mode="box", always_on=False)
        plot.overlays.append(zoom)

        # Add to the grid container (
        container.add(plot)

    # Set the upper-left plot to only be resizable vertically, and to have a
    # fixed horizontal width. This also constrains the width of the first column.
    ul_plot = container.components[0]
    ul_plot.set(resizable="v", width=200)
    ul_plot.overlays.append(PlotLabel("Not horizontally resizable",
                                      component=ul_plot))

    # Set the bottom center plot to have a fixed width and height.
    # This also constrains the height of the bottom row and the width of
    # the middle column.
    cplot = container.components[4]
    cplot.set(resizable="", bounds=[400,400])
    cplot.overlays.append(PlotLabel("Not resizable", component=cplot))

    container.padding_top = 50
    container.overlays.append(
        PlotLabel('Resize the window - some plots resize, others cannot '
                  '(see source code)',
                  component=container,
                  font = "swiss 16",
                  overlay_position = "top"))
        
    return container
示例#9
0
    def updateImageContainer(self):
            
        container = GridContainer(bgcolor="transparent", shape=(1,1), 
                                    use_backbuffer=True)
        self.imagecontainer = container

        cont = getattr(self.pyxda, 'imageplot')
        if cont in container._components:
            container.remove(cont)
        
        container.add(cont)
        
        container.get_preferred_size()
        container.invalidate_draw()
        return
示例#10
0
	def get_plots(self):
		#return [p.plothandle for p in self.plots]
		gc = GridContainer(padding=20, fill_padding=True,
			bgcolor='lightgray', use_backbuffer=True, 
			shape=(3,3), spacing=(10,10))
		[gc.add(p.plothandle) for p in self.plots]
		return gc
示例#11
0
def _create_plot_component():
    # Create a GridContainer to hold all of our plots
    container = GridContainer(padding=40, fill_padding=True,
                              bgcolor="lightgray", use_backbuffer=True,
                              shape=(2,3), spacing=(20,20))

    # Create the initial series of data
    x = linspace(-5, 15.0, 100)
    pd = ArrayPlotData(index = x)

    # Plot some bessel functions and add the plots to our container
    for i in range(6):
        pd.set_data("y" + str(i), jn(i,x))
        plot = Plot(pd)
        plot.plot(("index", "y" + str(i)),
                  color=tuple(COLOR_PALETTE[i]), line_width=2.0,
                  bgcolor = "white", border_visible=True)

        # Tweak some of the plot properties
        plot.border_width = 1
        plot.padding = 0

        # Attach some tools to the plot
        plot.tools.append(PanTool(plot))
        zoom = ZoomTool(plot, tool_mode="box", always_on=False)
        plot.overlays.append(zoom)

        # Add to the grid container
        container.add(plot)

    # Set the upper-left plot to only be resizable vertically, and to have
    # a fixed horizontal width
    ul_plot = container.components[0]
    ul_plot.set(resizable="v", padding_top=30, width=200)
    ul_plot.overlays.append(PlotLabel("Vertically resizable",
                                      component=ul_plot))

    # Set the bottom center plot to have a fixed width and height
    cplot = container.components[4]
    cplot.set(resizable="", padding_top = 30, bounds=[400,400])
    cplot.overlays.append(PlotLabel("Not resizable", component=cplot))
    return container
def _create_plot_component():
    # Create a GridContainer to hold all of our plots
    container = GridContainer(padding=20,
                              fill_padding=True,
                              bgcolor="lightgray",
                              use_backbuffer=True,
                              shape=(3, 3),
                              spacing=(12, 12))

    # Create the initial series of data
    x = linspace(-5, 15.0, 100)
    pd = ArrayPlotData(index=x)

    # Plot some bessel functions and add the plots to our container
    for i in range(9):
        pd.set_data("y" + str(i), jn(i, x))
        plot = Plot(pd)
        plot.plot(("index", "y" + str(i)),
                  color=tuple(COLOR_PALETTE[i]),
                  line_width=2.0,
                  bgcolor="white",
                  border_visible=True)

        # Tweak some of the plot properties
        plot.border_width = 1
        plot.padding = 10

        # Set each plot's aspect ratio based on its position in the
        # 3x3 grid of plots.
        n, m = divmod(i, 3)
        plot.aspect_ratio = float(n + 1) / (m + 1)

        # Attach some tools to the plot
        plot.tools.append(PanTool(plot))
        zoom = ZoomTool(plot, tool_mode="box", always_on=False)
        plot.overlays.append(zoom)

        # Add to the grid container
        container.add(plot)
    return container
示例#13
0
    def test_row(self):
        cont = GridContainer(shape=(1,3), halign="center", valign="center")
        c1 = StaticPlotComponent([50,50])
        c2 = StaticPlotComponent([30,30])
        c3 = StaticPlotComponent([0,0], resizable="hv")
        cont.add(c1, c2, c3)
        cont.bounds = list(cont.get_preferred_size())
        cont.do_layout()
        self.assert_tuple(c1.position, (0,0))
        self.assert_tuple(c1.bounds, (50,50))
        self.assert_tuple(c2.position, (50,10))
        self.assert_tuple(c2.bounds, (30,30))
        self.assert_tuple(c3.position, (80,0))
        self.assert_tuple(c3.bounds, (0,50))

        cont.bounds = [100, 50]
        cont.do_layout()
        self.assert_tuple(c1.position, (0,0))
        self.assert_tuple(c1.bounds, (50,50))
        self.assert_tuple(c2.position, (50,10))
        self.assert_tuple(c2.bounds, (30,30))
        self.assert_tuple(c3.position, (80,0))
        self.assert_tuple(c3.bounds, (20,50))
        return
示例#14
0
    def test_row(self):
        cont = GridContainer(shape=(1, 3), halign="center", valign="center")
        c1 = StaticPlotComponent([50, 50])
        c2 = StaticPlotComponent([30, 30])
        c3 = StaticPlotComponent([0, 0], resizable="hv")
        cont.add(c1, c2, c3)
        cont.bounds = list(cont.get_preferred_size())
        cont.do_layout()
        self.assert_tuple(c1.position, (0, 0))
        self.assert_tuple(c1.bounds, (50, 50))
        self.assert_tuple(c2.position, (50, 10))
        self.assert_tuple(c2.bounds, (30, 30))
        self.assert_tuple(c3.position, (80, 0))
        self.assert_tuple(c3.bounds, (0, 50))

        cont.bounds = [100, 50]
        cont.do_layout()
        self.assert_tuple(c1.position, (0, 0))
        self.assert_tuple(c1.bounds, (50, 50))
        self.assert_tuple(c2.position, (50, 10))
        self.assert_tuple(c2.bounds, (30, 30))
        self.assert_tuple(c3.position, (80, 0))
        self.assert_tuple(c3.bounds, (20, 50))
        return
示例#15
0
    def build_plot(self):
        global plotdata  # FIXME: Don't use global!
        onearray = Array
        onearray = sp.ones(self.indata.shape[0])
        minuses = onearray * (-1.)

        # Define index array for fit function:
        self.mod_x = sp.arange(self.line_center - 50.,
                               self.line_center + 50., .01)
        self.Model = sp.zeros(self.mod_x.shape[0])

        # Establish continuum array in a way that opens for other, more
        #   elaborate continua.
        self.contarray = sp.ones(self.mod_x.shape[0]) * \
                self.Components['Contin']
        self.y = {}

        for comp in self.CompoList:
            self.y[comp] = stats.norm.pdf(
                self.mod_x,
                self.Components[comp][0] + self.line_center,
                self.Components[comp][1]
            ) * self.Components[comp][1] * sp.sqrt(2. * sp.pi) * \
                    self.Components[comp][2]
        self.Model = self.contarray + self.y[self.select]

        broca = BroadcasterTool()

        # Define the part of the data to show in initial view:
        plotrange = sp.where((self.x > self.line_center - 20) &
                             (self.x < self.line_center + 20))
        # Define the y axis max value in initial view (can be panned/zoomed):
        maxval = float(self.indata[plotrange].max() * 1.1)
        minval = maxval / 15.
        maxerr = self.errs[plotrange].max() * 1.3
        resmin = max(self.Resids[plotrange].max(), 5.) * 1.2
        cenx = sp.array([self.line_center, self.line_center])
        ceny = sp.array([-minval, maxval])
        cenz = sp.array([-maxval, maxval])
        # Build plot of data and model
        plotdata = ArrayPlotData(
            wl=self.x,
            data=self.indata,
            xs=self.mod_x,
            cont=self.contarray,
            ones=onearray,
            minus=minuses,
            model=self.Model,
            errors=self.errs,
            ceny=ceny,
            cenz=cenz,
            cenx=cenx,
            Residuals=self.Resids,
        )
        for comp in self.CompoList:
            plotdata.set_data(comp, self.y[comp])
        olplot = GridContainer(shape=(2, 1), padding=10,
                               fill_padding=True,
                               bgcolor='transparent',
                               spacing=(5, 10))
        plot = Plot(plotdata)
        plot.y_axis.title = 'Flux density'
        resplot = Plot(plotdata, tick_visible=True, y_auto=True)
        resplot.x_axis.title = u'Wavelength [Å]'
        resplot.y_axis.title = u'Residuals/std. err.'

        # Create initial plot: Spectrum data, default first component,
        #   default total line profile.
        self.comprenders = []
        self.datarender = plot.plot(('wl', 'data'), color='black',
                                    name='Data',
                                    render_style='connectedhold')
        self.contrender = plot.plot(('xs', 'cont'), color='darkgray',
                                    name='Cont')
        self.modlrender = plot.plot(('xs', 'model'), color='blue',
                                    line_width=1.6, name='Model')
        self.centrender = plot.plot(('cenx', 'ceny'),
                                    color='black',
                                    type='line',
                                    line_style='dot',
                                    name='Line center',
                                    line_width=1.)

        # There may be an arbitrary number of gaussian components, so:
        for comp in self.CompoList:
            self.comprenders.append(
                plot.plot(('xs', comp),
                          type='line',
                          #color='auto',
                          color=tuple(COLOR_PALETTE[self.CompNum]),
                          line_style='dash',
                          name=comp)
            )

        # Create panel with residuals:
        resplot.plot(('wl', 'Residuals'), color='black', name='Resids')
        resplot.plot(('wl', 'ones'), color='green')
        resplot.plot(('wl', 'minus'), color='green')
        resplot.plot(('cenx', 'cenz'), color='red',
                     type='line',
                     line_style='dot',
                     line_width=.5)
        plot.x_axis.visible = False

        # Set ranges to change automatically when plot values change.
        plot.value_range.low_setting,\
            plot.value_range.high_setting = (-minval, maxval)
        plot.index_range.low_setting,\
            plot.index_range.high_setting = (self.line_center - 20.,
                                             self.line_center + 20.)
        resplot.value_range.low_setting,\
            resplot.value_range.high_setting = (-resmin, resmin)
        resplot.index_range.low_setting,\
            resplot.index_range.high_setting = (plot.index_range.low_setting,
                                                plot.index_range.high_setting)
        #resplot.index_range = plot.index_range  # Yes or no? FIXME
        plot.overlays.append(ZoomTool(plot, tool_mode='box',
                                      drag_button='left',
                                      always_on=False))

        resplot.overlays.append(ZoomTool(resplot, tool_mode='range',
                                         drag_button='left',
                                         always_on=False))

        # List of renderers to tell the legend what to write
        self.plots['Contin'] = self.contrender
        self.plots['Center'] = self.centrender
        self.plots['Model'] = self.modlrender
        for i in sp.arange(len(self.comprenders)):
            self.plots[self.CompoList[i]] = self.comprenders[i]

        # Build Legend:
        legend = Legend(component=plot, padding=10, align="ur")
        legend.tools.append(LegendTool(legend, drag_button="right"))
        legend.plots = self.plots
        plot.overlays.append(legend)
        olplot.tools.append(broca)
        pan = PanTool(plot)
        respan = PanTool(resplot, constrain=True, constrain_direction='x')
        broca.tools.append(pan)
        broca.tools.append(respan)
        plot.overlays.append(ZoomTool(plot, tool_mode='box',
                                      always_on=False))
        olplot.add(plot)
        olplot.add(resplot)
        olplot.components[0].set(resizable='hv', bounds=[500, 400])
        olplot.components[1].set(resizable='h', bounds=[500, 100])
        self.plot = plot
        self.resplot = resplot
        self.plwin = olplot
        self.legend = legend
        self.plotrange = plotrange
示例#16
0
def _create_plot_component():
	container = GridContainer(padding=40, fill_padding=True,
		bgcolor="lightgray", use_backbuffer=True,
		shape=(3,3), spacing=(10,10))

	x = arange(100)
	y = arange(100)
	plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-5,90))
	plot.padding = 50
	plot.fill_padding = True
	plot.bgcolor = "white"
	left, bottom = add_default_axes(plot, vtitle="Roll (degrees)", htitle="Time (s)")
	hgrid, vgrid = add_default_grids(plot)
	bottom.tick_interval = 20.0
	vgrid.grid_interval = 10.0
	container.add(plot)
	
	x = arange(100)
	y = arange(100)
	plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-5,90))
	plot.padding = 50
	plot.fill_padding = True
	plot.bgcolor = "white"
	left, bottom = add_default_axes(plot, vtitle="Pitch (degrees)", htitle="Time (s)")
	hgrid, vgrid = add_default_grids(plot)
	bottom.tick_interval = 20.0
	vgrid.grid_interval = 10.0
	container.add(plot)
	
	x = arange(100)
	y = arange(100)
	plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-5,365))
	plot.padding = 50
	plot.fill_padding = True
	plot.bgcolor = "white"
	left, bottom = add_default_axes(plot, vtitle="Yaw (degrees)", htitle="Time (s)")
	hgrid, vgrid = add_default_grids(plot)
	bottom.tick_interval = 20.0
	vgrid.grid_interval = 10.0
	container.add(plot)
	
	x = arange(100)
	y = arange(100)
	plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-100,100))
	plot.padding = 50
	plot.fill_padding = True
	plot.bgcolor = "white"
	left, bottom = add_default_axes(plot, vtitle="Gyro X", htitle="Time (s)")
	hgrid, vgrid = add_default_grids(plot)
	bottom.tick_interval = 20.0
	vgrid.grid_interval = 10.0
	container.add(plot)
	
	x = arange(100)
	y = arange(100)
	plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-100,100))
	plot.padding = 50
	plot.fill_padding = True
	plot.bgcolor = "white"
	left, bottom = add_default_axes(plot, vtitle="Gyro Y", htitle="Time (s)")
	hgrid, vgrid = add_default_grids(plot)
	bottom.tick_interval = 20.0
	vgrid.grid_interval = 10.0
	container.add(plot)
	
	x = arange(100)
	y = arange(100)
	plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-100,100))
	plot.padding = 50
	plot.fill_padding = True
	plot.bgcolor = "white"
	left, bottom = add_default_axes(plot, vtitle="Gyro Z", htitle="Time (s)")
	hgrid, vgrid = add_default_grids(plot)
	bottom.tick_interval = 20.0
	vgrid.grid_interval = 10.0
	container.add(plot)
	
	x = arange(100)
	y = arange(100)
	plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-1,35))
	plot.padding = 50
	plot.fill_padding = True
	plot.bgcolor = "white"
	left, bottom = add_default_axes(plot, vtitle="Battery Voltage (V)", htitle="Time (s)")
	hgrid, vgrid = add_default_grids(plot)
	bottom.tick_interval = 20.0
	vgrid.grid_interval = 10.0
	container.add(plot)

	return container
示例#17
0
    def build_plot(self):
        print 'Building plot...'
        fitrange = self.fitrange  # Just for convenience
        onearray = Array
        onearray = sp.ones(self.indata.shape[0])
        minuses = onearray * (-1.)

        # Define index array for fit function:
        self.mod_x = sp.arange(self.line_center - 50., self.line_center + 50.,
                               .01)
        self.Model = sp.zeros(self.mod_x.shape[0])

        # Establish continuum array in a way that opens for other, more
        #   elaborate continua.
        self.contarray = sp.ones(self.mod_x.shape[0]) * \
                self.Components['Contin'][0]
        self.y = {}

        for comp in self.CompoList:
            self.y[comp] = gauss(  # x, mu, sigma, amplitude
                self.mod_x, self.Components[comp][0] + self.line_center,
                self.Components[comp][1], self.Components[comp][2])

        self.Model = self.contarray + self.y[self.select]

        broca = BroadcasterTool()

        # Define the part of the data to show in initial view:
        plotrange = sp.where((self.x > self.line_center - 30)
                             & (self.x < self.line_center + 30))
        # Define the y axis max value in initial view (can be panned/zoomed):
        maxval = float(self.indata[fitrange].max() * 1.2)
        minval = maxval / 15.
        minval = abs(np.median(self.indata[fitrange])) * 1.5
        maxerr = self.errs[fitrange].max() * 1.3
        resmin = max(sp.absolute(self.Resids[self.fitrange]).max(), 5.) * 1.2
        cenx = sp.array([self.line_center, self.line_center])
        ceny = sp.array([-minval, maxval])
        cenz = sp.array([-maxval, maxval])
        # Gray shading of ignored ranges
        rangelist = np.array(self.rangelist)
        grayx = np.array(rangelist.flatten().repeat(2))
        grayx = np.hstack((self.x.min(), grayx, self.x.max()))
        grayy = np.ones_like(grayx) * self.indata.max() * 2.
        grayy[1::4] = -grayy[1::4]
        grayy[2::4] = -grayy[2::4]
        grayy = np.hstack((grayy[-1], grayy[:-1]))

        # Build plot of data and model
        self.plotdata = ArrayPlotData(
            wl=self.x,
            data=self.indata,
            xs=self.mod_x,
            cont=self.contarray,
            ones=onearray,
            minus=minuses,
            model=self.Model,
            errors=self.errs,
            ceny=ceny,
            cenz=cenz,
            cenx=cenx,
            Residuals=self.Resids,
            grayx=grayx,
            grayy=grayy,
        )

        # Add dynamically created components to plotdata
        for comp in self.CompoList:
            self.plotdata.set_data(comp, self.y[comp])
        olplot = GridContainer(shape=(2, 1),
                               padding=10,
                               fill_padding=True,
                               bgcolor='transparent',
                               spacing=(5, 10))
        plot = Plot(self.plotdata)
        plot.y_axis.title = 'Flux density'
        resplot = Plot(self.plotdata, tick_visible=True, y_auto=True)
        resplot.x_axis.title = u'Wavelength [Å]'
        resplot.y_axis.title = u'Residuals/std. err.'

        # Create initial plot: Spectrum data, default first component,
        #   default total line profile.

        self.comprenders = []

        self.datarender = plot.plot(('wl', 'data'),
                                    color='black',
                                    name='Data',
                                    render_style='connectedhold')

        self.contrender = plot.plot(('xs', 'cont'),
                                    color='darkgray',
                                    name='Cont')

        self.modlrender = plot.plot(('xs', 'model'),
                                    color='blue',
                                    line_width=1.6,
                                    name='Model')

        self.centrender = plot.plot(('cenx', 'ceny'),
                                    color='black',
                                    type='line',
                                    line_style='dot',
                                    name='Line center',
                                    line_width=1.)

        self.rangrender = plot.plot(
            ('grayx', 'grayy'),
            type='polygon',
            face_color='lightgray',
            edge_color='gray',
            face_alpha=0.3,
            alpha=0.3,
        )

        # There may be an arbitrary number of gaussian components, so:
        print 'Updating model'
        for comp in self.CompoList:
            self.comprenders.append(
                plot.plot(
                    ('xs', comp),
                    type='line',
                    color=Paired[self.Components[comp]
                                 [3]],  # tuple(COLOR_PALETTE[self.CompNum]),
                    line_color=Paired[self.Components[comp][
                        3]],  # tuple(COLOR_PALETTE[self.CompNum]),
                    line_style='dash',
                    name=comp))

        # Create panel with residuals:
        resplot.plot(('wl', 'Residuals'), color='black', name='Resids')
        resplot.plot(('wl', 'ones'), color='green')
        resplot.plot(('wl', 'minus'), color='green')
        resplot.plot(('cenx', 'cenz'),
                     color='red',
                     type='line',
                     line_style='dot',
                     line_width=.5)
        resplot.plot(
            ('grayx', 'grayy'),  # Yes, that one again
            type='polygon',
            face_color='lightgray',
            edge_color='gray',
            face_alpha=0.3,
            alpha=0.3,
        )
        plot.x_axis.visible = False

        # Set ranges to change automatically when plot values change.
        plot.value_range.low_setting,\
            plot.value_range.high_setting = (-minval, maxval)
        plot.index_range.low_setting,\
            plot.index_range.high_setting = (self.line_center - 30.,
                                             self.line_center + 30.)
        resplot.value_range.low_setting,\
            resplot.value_range.high_setting = (-resmin, resmin)
        resplot.index_range.low_setting,\
            resplot.index_range.high_setting = (plot.index_range.low_setting,
                                                plot.index_range.high_setting)
        #resplot.index_range = plot.index_range  # Yes or no? FIXME
        plot.overlays.append(
            ZoomTool(plot,
                     tool_mode='box',
                     drag_button='left',
                     always_on=False))

        resplot.overlays.append(
            ZoomTool(resplot,
                     tool_mode='range',
                     drag_button='left',
                     always_on=False))

        # List of renderers to tell the legend what to write
        self.plots['Contin'] = self.contrender
        self.plots['Center'] = self.centrender
        self.plots['Model'] = self.modlrender
        for i in sp.arange(len(self.comprenders)):
            self.plots[self.CompoList[i]] = self.comprenders[i]

        # Build Legend:
        legend = Legend(component=plot, padding=10, align="ur")
        legend.tools.append(LegendTool(legend, drag_button="right"))
        legend.plots = self.plots
        plot.overlays.append(legend)
        olplot.tools.append(broca)
        pan = PanTool(plot)
        respan = PanTool(resplot, constrain=True, constrain_direction='x')
        broca.tools.append(pan)
        broca.tools.append(respan)
        plot.overlays.append(ZoomTool(plot, tool_mode='box', always_on=False))
        olplot.add(plot)
        olplot.add(resplot)
        olplot.components[0].set(resizable='hv', bounds=[500, 400])
        olplot.components[1].set(resizable='h', bounds=[500, 100])
        self.plot = plot
        self.resplot = resplot
        self.plwin = olplot
        self.legend = legend
        self.plotrange = plotrange