Exemplo n.º 1
0
 def draw_colorbar(self):
     scatplot=self.scatplot
     cmap_renderer = scatplot.plots["my_plot"][0]
     selection = ColormappedSelectionOverlay(cmap_renderer, fade_alpha=0.35, 
                                             selection_type="range")
     cmap_renderer.overlays.append(selection)
     if self.thresh is not None:
         cmap_renderer.color_data.metadata['selections']=self.thresh
         cmap_renderer.color_data.metadata_changed={'selections':self.thresh}
     # Create the colorbar, handing in the appropriate range and colormap
     colormap=scatplot.color_mapper
     colorbar = ColorBar(index_mapper=LinearMapper(range=DataRange1D(low = 0.0,
                                    high = 1.0)),
                     orientation='v',
                     resizable='v',
                     width=30,
                     padding=20)
     colorbar_selection=RangeSelection(component=colorbar)
     colorbar.tools.append(colorbar_selection)
     ovr=colorbar.overlays.append(RangeSelectionOverlay(component=colorbar,
                                                border_color="white",
                                                alpha=0.8,
                                                fill_color="lightgray",
                                                metadata_name='selections'))
     #ipshell('colorbar, colorbar_selection and ovr available:')
     self.cbar_selection=colorbar_selection
     self.cmap_renderer=cmap_renderer
     colorbar.plot = cmap_renderer
     colorbar.padding_top = scatplot.padding_top
     colorbar.padding_bottom = scatplot.padding_bottom
     self.colorbar=colorbar
     return colorbar
Exemplo n.º 2
0
	def control(self):
		"""
		A drawable control with a color bar.
		"""

		color_map = self.plot_obj.color_mapper
		linear_mapper = LinearMapper(range=color_map.range)
		color_bar = ColorBar(index_mapper=linear_mapper, color_mapper=color_map, plot=self.plot_obj,
				orientation='v', resizable='v', width=30)
		color_bar._axis.tick_label_formatter = self.sci_formatter
		color_bar.padding_top = self.padding_top
		color_bar.padding_bottom = self.padding_bottom
		color_bar.padding_left = 50 # Room for labels.
		color_bar.padding_right = 10

		range_selection = RangeSelection(component=color_bar)
		range_selection.listeners.append(self.plot_obj)
		color_bar.tools.append(range_selection)

		range_selection_overlay = RangeSelectionOverlay(component=color_bar)
		color_bar.overlays.append(range_selection_overlay)

		container = HPlotContainer(use_backbuffer=True)
		container.add(self)
		container.add(color_bar)

		return Window(self.parent, component=container).control
Exemplo n.º 3
0
    def __init__(self):
        # Create some data
        x = np.random.random(N_POINTS)
        y = np.random.random(N_POINTS)
        color = np.exp(-(x**2 + y**2))

        # Create a plot data object and give it this data
        data = ArrayPlotData(index=x, value=y, color=color)

        # Create the plot
        plot = Plot(data)
        plot.plot(("index", "value", "color"), type="cmap_scatter",
                  color_mapper=jet)

        # Create the colorbar, handing in the appropriate range and colormap
        colormap = plot.color_mapper
        colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                            color_mapper=colormap,
                            orientation='v',
                            resizable='v',
                            width=30,
                            padding=20)

        colorbar.padding_top = plot.padding_top
        colorbar.padding_bottom = plot.padding_bottom

        # Create a container to position the plot and the colorbar side-by-side
        container = HPlotContainer(plot, colorbar)
        self.plot = container
Exemplo n.º 4
0
    def _hist2d_default(self):
        plot = Plot(self.hist2d_data, padding=(20, 0, 0, 40))
        plot.img_plot("H", xbounds=self.xedges, ybounds=self.yedges, colormap=jet)
        plot.index_axis.title = "Voxel dist."
        plot.value_axis.title = "Root Square Error"

        # Create a colorbar
        colormap = plot.color_mapper
        colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                            color_mapper=colormap,
                            plot=plot,
                            orientation='v',
                            resizable='v',
                            width=20,
                            padding=(20, 30, 0, 0))
        colorbar.padding_top = plot.padding_top
        colorbar.padding_bottom = plot.padding_bottom

        # Create a container to position the plot and the colorbar side-by-side
        container = HPlotContainer(use_backbuffer=True, padding=0)
        container.add(colorbar)
        container.add(plot)
        container.bgcolor = "lightgray"

        return container
  def _plot_default(self):
    plot = Plot(self.plotdata)
    plot.title = "Simplex on the Rosenbrock function"

    plot.img_plot("background",
                  name="background",
                  xbounds=(0,1.5),
                  ybounds=(0,1.5),
                  colormap=jet(DataRange1D(low=0,high=100)),
                  )

    plot.plot(("values_x", "values_y"), type="scatter", color="red")

    background = plot.plots["background"][0]

    colormap = background.color_mapper
    colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                        color_mapper=colormap,
                        plot=background,
                        orientation='v',
                        resizable='v',
                        width=30,
                        padding=20)
    colorbar.padding_top = plot.padding_top
    colorbar.padding_bottom = plot.padding_bottom

    container = HPlotContainer(use_backbuffer = True)
    container.add(plot)
    container.add(colorbar)
    container.bgcolor = "lightgray"
    return container
Exemplo n.º 6
0
    def _SmoothPlot_default(self):

        plotdata = ArrayPlotData(imagedata=self.Smooth)
        plot = Plot(plotdata, width=500, height=500, resizable='hv')
        SmoothImage = plot.img_plot(
            'imagedata',
            colormap=gray,
            xbounds=(self.X[0], self.X[-1]),
            ybounds=(self.Y[0], self.Y[-1]),
        )[0]
        SmoothImage.x_mapper.domain_limits = (self.X[0], self.X[-1])
        SmoothImage.y_mapper.domain_limits = (self.Y[0], self.Y[-1])
        SmoothImage.overlays.append(ZoomTool(SmoothImage))

        colormap = SmoothImage.color_mapper
        colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                            color_mapper=colormap,
                            plot=plot,
                            orientation='v',
                            resizable='v',
                            width=10,
                            padding=20)
        colorbar.padding_top = plot.padding_top
        colorbar.padding_bottom = plot.padding_bottom

        self.SmoothImage = SmoothImage

        container = HPlotContainer(padding=20,
                                   fill_padding=True,
                                   use_backbuffer=True)
        container.add(colorbar)
        container.add(plot)

        return container
    def control(self):
        """
		A drawable control with a color bar.
		"""

        color_map = self.plot_obj.color_mapper
        linear_mapper = LinearMapper(range=color_map.range)
        color_bar = ColorBar(index_mapper=linear_mapper,
                             color_mapper=color_map,
                             plot=self.plot_obj,
                             orientation='v',
                             resizable='v',
                             width=30)
        color_bar._axis.tick_label_formatter = self.sci_formatter
        color_bar.padding_top = self.padding_top
        color_bar.padding_bottom = self.padding_bottom
        color_bar.padding_left = 50  # Room for labels.
        color_bar.padding_right = 10

        range_selection = RangeSelection(component=color_bar)
        range_selection.listeners.append(self.plot_obj)
        color_bar.tools.append(range_selection)

        range_selection_overlay = RangeSelectionOverlay(component=color_bar)
        color_bar.overlays.append(range_selection_overlay)

        container = HPlotContainer(use_backbuffer=True)
        container.add(self)
        container.add(color_bar)

        return Window(self.parent, component=container).control
def _create_plot_component(model):

    # Create a plot data object and give it the model's data array.
    pd = ArrayPlotData()
    pd.set_data("imagedata", model.data)

    # Create the "main" Plot.
    plot = Plot(pd, padding=50)

    # Use a TransformColorMapper for the color map.
    tcm = TransformColorMapper.from_color_map(jet)

    # Create the image plot renderer in the main plot.
    renderer = plot.img_plot("imagedata",
                             xbounds=model.x_array,
                             ybounds=model.y_array,
                             colormap=tcm)[0]

    # Create the colorbar.
    lm = LinearMapper(range=renderer.value_range,
                      domain_limits=(renderer.value_range.low,
                                     renderer.value_range.high))
    colorbar = ColorBar(index_mapper=lm,
                        plot=plot,
                        orientation='v',
                        resizable='v',
                        width=30,
                        padding=20)

    colorbar.padding_top = plot.padding_top
    colorbar.padding_bottom = plot.padding_bottom

    # Add pan and zoom tools to the colorbar.
    colorbar.tools.append(
        PanTool(colorbar, constrain_direction="y", constrain=True))
    zoom_overlay = ZoomTool(colorbar,
                            axis="index",
                            tool_mode="range",
                            always_on=True,
                            drag_button="right")
    colorbar.overlays.append(zoom_overlay)

    # Create a container to position the plot and the colorbar side-by-side
    container = HPlotContainer(use_backbuffer=True)
    container.add(plot)
    container.add(colorbar)

    return container
def _create_plot_component(model):

    # Create a plot data object and give it the model's data array.
    pd = ArrayPlotData()
    pd.set_data("imagedata", model.data)

    # Create the "main" Plot.
    plot = Plot(pd, padding=50)

    # Use a TransformColorMapper for the color map.
    tcm = TransformColorMapper.from_color_map(jet)

    # Create the image plot renderer in the main plot.
    renderer = plot.img_plot("imagedata", 
                    xbounds=model.x_array,
                    ybounds=model.y_array,
                    colormap=tcm)[0]

    # Create the colorbar.
    lm = LinearMapper(range=renderer.value_range,
                      domain_limits=(renderer.value_range.low,
                                     renderer.value_range.high))
    colorbar = ColorBar(index_mapper=lm,
                        plot=plot,
                        orientation='v',
                        resizable='v',
                        width=30,
                        padding=20)

    colorbar.padding_top = plot.padding_top
    colorbar.padding_bottom = plot.padding_bottom

    # Add pan and zoom tools to the colorbar.
    colorbar.tools.append(PanTool(colorbar,
                                  constrain_direction="y",
                                  constrain=True))
    zoom_overlay = ZoomTool(colorbar, axis="index", tool_mode="range",
                            always_on=True, drag_button="right")
    colorbar.overlays.append(zoom_overlay)

    # Create a container to position the plot and the colorbar side-by-side
    container = HPlotContainer(use_backbuffer = True)
    container.add(plot)
    container.add(colorbar)

    return container
Exemplo n.º 10
0
    def _RegionsPlot_default(self):

        plotdata = ArrayPlotData(imagedata=self.RegionsAndLabels[0],
                                 x=self.XPositions,
                                 y=self.YPositions)
        plot = Plot(plotdata, width=500, height=500, resizable='hv')
        RegionsImage = plot.img_plot(
            'imagedata',
            colormap=gray,
            xbounds=(self.X[0], self.X[-1]),
            ybounds=(self.Y[0], self.Y[-1]),
        )[0]
        RegionsImage.x_mapper.domain_limits = (self.X[0], self.X[-1])
        RegionsImage.y_mapper.domain_limits = (self.Y[0], self.Y[-1])
        RegionsImage.overlays.append(ZoomTool(RegionsImage))

        scatterplot = plot.plot(('x', 'y'),
                                type='scatter',
                                marker='plus',
                                color='yellow')

        colormap = RegionsImage.color_mapper
        colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                            color_mapper=colormap,
                            plot=plot,
                            orientation='v',
                            resizable='v',
                            width=10,
                            padding=20)
        colorbar.padding_top = plot.padding_top
        colorbar.padding_bottom = plot.padding_bottom

        self.RegionsData = plotdata
        self.RegionsImage = RegionsImage

        container = HPlotContainer(padding=20,
                                   fill_padding=True,
                                   use_backbuffer=True)
        container.add(colorbar)
        container.add(plot)

        return container
Exemplo n.º 11
0
    def _container_default(self):
        plot = self.plot
        colormap = plot.color_mapper
        colorbar = ColorBar(index_mapper = LinearMapper(range=colormap.range),
                            color_mapper = colormap,
                            plot = plot,
                            orientation = 'v', resizable = 'v',
                            width = 30, padding = 20)
        colorbar.padding_top = plot.padding_top
        colorbar.padding_bottom = plot.padding_bottom

        container = HPlotContainer(bgcolor = 'lightgray',
                                   use_backbuffer = True)
        container.add(plot)
        container.add(colorbar)

        inspector = plot.plots['image'][0].tools[0]
        overlay = ImageInspectorOverlay(component = container,
                                        image_inspector = inspector,
                                        bgcolor = 'white',
                                        border_visible = True)
        container.overlays.append(overlay)

        return container
Exemplo n.º 12
0
def _create_plot_component_cmap(signals):

    nSignal, nSample = np.shape(signals)

    xbounds = (1, nSample, nSample)
    ybounds = (1, nSignal, nSignal)
    z = signals

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("imagedata", z)

    # Create the plot
    plot = Plot(pd)
    plot.img_plot("imagedata",
                  name="my_plot",
                  xbounds=xbounds[:2],
                  ybounds=ybounds[:2],
                  colormap=jet)

    # Tweak some of the plot properties
    plot.title = "Selectable Image Plot"
    # plot.padding = 50

    # Right now, some of the tools are a little invasive, and we need the
    # actual CMapImage object to give to them
    my_plot = plot.plots["my_plot"][0]

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

    # Create the colorbar, handing in the appropriate range and colormap
    colormap = my_plot.color_mapper
    colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                        color_mapper=colormap,
                        plot=my_plot,
                        orientation='v',
                        resizable='v',
                        width=30,
                        padding=20)
    colorbar.padding_top = plot.padding_top
    colorbar.padding_bottom = plot.padding_bottom

    # create a range selection for the colorbar
    range_selection = RangeSelection(component=colorbar)
    colorbar.tools.append(range_selection)
    colorbar.overlays.append(RangeSelectionOverlay(component=colorbar,
                                                   border_color="white",
                                                   alpha=0.8,
                                                   fill_color="lightgray"))

    # we also want to the range selection to inform the cmap plot of
    # the selection, so set that up as well
    range_selection.listeners.append(my_plot)

    # Create a container to position the plot and the colorbar side-by-side
    container = HPlotContainer(use_backbuffer=True)
    container.add(plot)
    container.add(colorbar)
    container.bgcolor = "lightgray"

    return container
Exemplo n.º 13
0
def _create_plot_component():

    # Create some data
    numpts = 1000
    x = sort(random(numpts))
    y = random(numpts)
    color = exp(-(x**2 + y**2))

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("index", x)
    pd.set_data("value", y)
    pd.set_data("color", color)

    # Create the plot
    plot = Plot(pd)
    plot.plot(("index", "value", "color"),
              type="cmap_scatter",
              name="my_plot",
              color_mapper=gist_earth,
              marker="square",
              fill_alpha=0.5,
              marker_size=8,
              outline_color="black",
              border_visible=True,
              bgcolor="white")

    # Tweak some of the plot properties
    plot.title = "Colormapped Scatter Plot with Pan/Zoom Color Bar"
    plot.padding = 50
    plot.x_grid.visible = False
    plot.y_grid.visible = False
    plot.x_axis.font = "modern 16"
    plot.y_axis.font = "modern 16"

    # Add pan and zoom to the plot
    plot.tools.append(PanTool(plot, constrain_key="shift"))
    zoom = ZoomTool(plot)
    plot.overlays.append(zoom)

    # Create the colorbar, handing in the appropriate range and colormap
    colorbar = ColorBar(
        index_mapper=LinearMapper(range=plot.color_mapper.range),
        color_mapper=plot.color_mapper,
        orientation='v',
        resizable='v',
        width=30,
        padding=20)
    colorbar.plot = plot
    colorbar.padding_top = plot.padding_top
    colorbar.padding_bottom = plot.padding_bottom

    # Add pan and zoom tools to the colorbar
    colorbar.tools.append(
        PanTool(colorbar, constrain_direction="y", constrain=True))
    zoom_overlay = ZoomTool(colorbar,
                            axis="index",
                            tool_mode="range",
                            always_on=True,
                            drag_button="right")
    colorbar.overlays.append(zoom_overlay)

    # Create a container to position the plot and the colorbar side-by-side
    container = HPlotContainer(plot,
                               colorbar,
                               use_backbuffer=True,
                               bgcolor="lightgray")

    return container
Exemplo n.º 14
0
def _create_plot_component():

    # Create some data
    numpts = 1000
    x = sort(random(numpts))
    y = random(numpts)
    color = exp(-(x**2 + y**2))

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("index", x)
    pd.set_data("value", y)
    pd.set_data("color", color)

    # Create the plot
    plot = Plot(pd)
    plot.plot(("index", "value", "color"),
              type="cmap_scatter",
              name="my_plot",
              color_mapper=gist_earth,
              marker = "square",
              fill_alpha = 0.5,
              marker_size = 8,
              outline_color = "black",
              border_visible = True,
              bgcolor = "white")

    # Tweak some of the plot properties
    plot.title = "Colormapped Scatter Plot with Pan/Zoom Color Bar"
    plot.padding = 50
    plot.x_grid.visible = False
    plot.y_grid.visible = False
    plot.x_axis.font = "modern 16"
    plot.y_axis.font = "modern 16"

    # Add pan and zoom to the plot
    plot.tools.append(PanTool(plot, constrain_key="shift"))
    zoom = ZoomTool(plot)
    plot.overlays.append(zoom)

    # Create the colorbar, handing in the appropriate range and colormap
    colorbar = ColorBar(index_mapper=LinearMapper(range=plot.color_mapper.range),
                        color_mapper=plot.color_mapper,
                        orientation='v',
                        resizable='v',
                        width=30,
                        padding=20)
    colorbar.plot = plot
    colorbar.padding_top = plot.padding_top
    colorbar.padding_bottom = plot.padding_bottom

    # Add pan and zoom tools to the colorbar
    colorbar.tools.append(PanTool(colorbar, constrain_direction="y", constrain=True))
    zoom_overlay = ZoomTool(colorbar, axis="index", tool_mode="range",
                            always_on=True, drag_button="right")
    colorbar.overlays.append(zoom_overlay)

    # Create a container to position the plot and the colorbar side-by-side
    container = HPlotContainer(plot, colorbar, use_backbuffer=True, bgcolor="lightgray")

    return container
Exemplo n.º 15
0
def _create_plot_component():
    # Create a scalar field to colormap# Create a scalar field to colormap
    xbounds = (-2 * pi, 2 * pi, 600)
    ybounds = (-1.5 * pi, 1.5 * pi, 300)
    xs = linspace(*xbounds)
    ys = linspace(*ybounds)
    x, y = meshgrid(xs, ys)
    z = jn(2, x) * y * x

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("imagedata", z)

    # Create the plot
    plot = Plot(pd)
    plot.img_plot(
        "imagedata",
        name="my_plot",
        xbounds=xbounds[:2],
        ybounds=ybounds[:2],
        colormap=jet)

    # Tweak some of the plot properties
    plot.title = "Selectable Image Plot"
    plot.padding = 50

    # Right now, some of the tools are a little invasive, and we need the
    # actual CMapImage object to give to them
    my_plot = plot.plots["my_plot"][0]

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

    # Create the colorbar, handing in the appropriate range and colormap
    colormap = my_plot.color_mapper
    colorbar = ColorBar(
        index_mapper=LinearMapper(range=colormap.range),
        color_mapper=colormap,
        plot=my_plot,
        orientation='v',
        resizable='v',
        width=30,
        padding=20)
    colorbar.padding_top = plot.padding_top
    colorbar.padding_bottom = plot.padding_bottom

    # create a range selection for the colorbar
    range_selection = RangeSelection(component=colorbar)
    colorbar.tools.append(range_selection)
    colorbar.overlays.append(
        RangeSelectionOverlay(
            component=colorbar,
            border_color="white",
            alpha=0.8,
            fill_color="lightgray"))

    # we also want to the range selection to inform the cmap plot of
    # the selection, so set that up as well
    range_selection.listeners.append(my_plot)

    # Create a container to position the plot and the colorbar side-by-side
    container = HPlotContainer(use_backbuffer=True)
    container.add(plot)
    container.add(colorbar)
    container.bgcolor = "lightgray"

    #my_plot.set_value_selection((-1.3, 6.9))

    return container
Exemplo n.º 16
0
  def _myTIC_default( self ):

    # create an interesting scalar field for the image plot
    # Eggholder function
    limitF = 500.0
    xA = linspace(-limitF, limitF, 600)
    yA = linspace(-limitF, limitF, 600)
    ( xMG,yMG ) = meshgrid( xA,yA )
    zMG = -(yMG + 47) * sin( sqrt(abs(yMG + xMG/2 + 47 )))
    zMG = zMG - xMG * sin( sqrt(abs(xMG - (yMG + 47))))

    # Create an ArrayPlotData object and give it this data
    myAPD = ArrayPlotData()
    myAPD.set_data( "Z", zMG )
    myAPD.set_data( "X",xA )
    myAPD.set_data( "Y",yA )

    # Create the plot
    myTP = Plot( myAPD )

    # contains a dict of default colormaps and their functions. We have to
    # pass the colormapper the data range of interest to set up the private
    # attributes
    default_colormaps.color_map_name_dict

    # the colormap method needs the range of the image data that we want to
    # plot. We first put the image data (zMG) into an ImageData object. We
    # then use DataRange1D on the ImageData instance to produce a DataRange1D
    # instance describing the ImageData data. Finally, we feed the DataRange1D
    # instance into the colormapper to produce a working colormapper.
    myID = ImageData( )
    myID.set_data( zMG )
    myDR1D = DataRange1D( myID )

    # pick a colormap
    myColorMapperFn = default_colormaps.color_map_name_dict['copper']

    # choose one or more modifications to the colormap function
    #myColorMapperFn = default_colormaps.reverse( myColorMapperFn )
    #myColorMapperFn = default_colormaps.center( myColorMapperFn,500 )
    #myColorMapperFn = default_colormaps.fix( myColorMapperFn,(-500,500) )

    # finally, build the colormapper function
    myColorMapper = myColorMapperFn( myDR1D )

    # add the image plot to this plot object
    # specify the colormap explicitly
    myTP.img_plot(
        "Z",
        xbounds = (xA[0],xA[-1]),
        ybounds = (yA[0],yA[-1]),
        colormap = myColorMapper,
    )

    # add the title and padding around the plot
    myTP.title = "Eggholder Function"
    myTP.padding = 50

    # grids, fonts, etc
    myTP.x_axis.title = "X"
    myTP.y_axis.title = "Y"

    # generate a ColorBar. pulls its colormapper from the myTP Plot object
    myTCB = ColorBar(
      plot = myTP,
      index_mapper = LinearMapper( range = myTP.color_mapper.range ),
      orientation = 'v',
      resizable = 'v',
      width = 40,
      padding = 30,
    )

    # set the padding of the ColorBar to match the padding of the plot
    myTCB.padding_top = myTP.padding_top
    myTCB.padding_bottom = myTP.padding_bottom

    # range of the colormapper. Changes the min/max values that are mapped
    # to the ends of the color range. Try +/-2000 for poor contrast and +/-200 for
    # saturated. Asymmetrical values work as well.
    #myTP.color_mapper.range.low_setting = 0
    #myTP.color_mapper.range.high_setting = 1000

    # build up a single container for the colorbar and the image
    myHPC = HPlotContainer( use_backbuffer = True )
    myHPC.add( myTP )
    myHPC.add( myTCB )

    return( myHPC )
Exemplo n.º 17
0
    def create_plot_component(self):# Create a scalar field to colormap
        # Create the plot
        self.pd = ArrayPlotData()
        self.pd.set_data("imagedata", self.fxydata())
        plot = Plot(self.pd)
        cmap = default_colormaps.color_map_name_dict[self.colormap]
        if self.rev_cmap:
            cmap = default_colormaps.reverse(cmap)
        img_plot = plot.img_plot("imagedata",
                                 xbounds = self.xbounds,
                                 ybounds = self.ybounds,
                                 colormap=cmap,

                                 )[0]

        # Tweak some of the plot properties
        plot.title = self.title
        plot.padding = 50

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

        csr = CursorTool(img_plot,
                          drag_button='left',
                          color='white',
                          line_width=2.0
                          )
        self.cursor = csr

        csr.current_position = np.mean(self.xbounds), np.mean(self.ybounds)
        img_plot.overlays.append(csr)

        imgtool = ImageInspectorTool(img_plot)
        img_plot.tools.append(imgtool)

        overlay = ImageInspectorOverlay(component=img_plot, image_inspector=imgtool,
                                        bgcolor="white", border_visible=True,)

        #img_plot.overlays.append(overlay)
        colorbar = ColorBar(index_mapper=LinearMapper(range=plot.color_mapper.range),
                            color_mapper=plot.color_mapper,
                            orientation='v',
                            resizable='v',
                            width=30,
                            padding=20)
        colorbar.plot = plot
        colorbar.padding_top = plot.padding_top + 10
        colorbar.padding_bottom = plot.padding_bottom

        # Add pan and zoom tools to the colorbar
        colorbar.tools.append(PanTool(colorbar, constrain_direction="y", constrain=True))
        zoom_overlay = ZoomTool(colorbar, axis="index", tool_mode="range",
                                always_on=True, drag_button="right")
        colorbar.overlays.append(zoom_overlay)

        # Create a container to position the plot and the colorbar side-by-side
        container = HPlotContainer(plot, colorbar, use_backbuffer=True, bgcolor="transparent",)
        container.overlays.append(overlay)
        #self.plot = plot
        self.plot = container
Exemplo n.º 18
0
def _create_plot_component():

    # Create a scalar field to colormap
    x_extents = (-2*pi, 2*pi)
    y_extents = (-1.5*pi, 1.5*pi)
    xs = linspace(-2*pi, 2*pi, 200)
    ys = linspace(-1.5*pi, 1.5*pi, 100)
    x, y = meshgrid(xs,ys)
    zs = sin(log(abs((x+1)**4)+0.05))*cos(y)*1.1*(-y) + \
            sin(((x+1)**2 + y**2)/4)

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("imagedata", zs)

    # Create the left plot, a colormap and simple contours
    lplot = Plot(pd)
    lplot.img_plot("imagedata",
                   name="cm_plot",
                   xbounds=x_extents,
                   ybounds=y_extents,
                   colormap=gmt_drywet)
    lplot.contour_plot("imagedata",
                       type="line",
                       xbounds=x_extents,
                       ybounds=y_extents)

    # Tweak some of the plot properties
    lplot.title = "Colormap and contours"
    lplot.padding = 20
    lplot.bg_color = "white"
    lplot.fill_padding = True

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

    # Right now, some of the tools are a little invasive, and we need the
    # actual CMapImage object to give to them
    cm_plot = lplot.plots["cm_plot"][0]

    # Create the colorbar, handing in the appropriate range and colormap
    colormap = cm_plot.color_mapper
    colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                        color_mapper=colormap,
                        plot=cm_plot,
                        orientation='v',
                        resizable='v',
                        width=30,
                        padding=20)
    colorbar.padding_top = lplot.padding_top
    colorbar.padding_bottom = lplot.padding_bottom

    # Create the left plot, contours of varying color and width
    rplot = Plot(pd, range2d=lplot.range2d)
    rplot.contour_plot("imagedata",
                       type="line",
                       xbounds=x_extents,
                       ybounds=y_extents,
                       bgcolor="black",
                       levels=15,
                       styles="solid",
                       widths=list(linspace(4.0, 0.1, 15)),
                       colors=gmt_drywet)

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

    # Tweak some of the plot properties
    rplot.title = "Varying contour lines"
    rplot.padding = 20
    rplot.bg_color = "white"
    rplot.fill_padding = True

    # Create a container and add our plots
    container = HPlotContainer(padding=40, fill_padding=True,
                               bgcolor = "white", use_backbuffer=True)
    container.add(colorbar)
    container.add(lplot)
    container.add(rplot)
    return container
Exemplo n.º 19
0
    def _brain_default(self):
        plot = Plot(self.brain_data, padding=0)
        plot.width = self.brain_voxels.shape[1]
        plot.height = self.brain_voxels.shape[0]
        plot.aspect_ratio = 1.
        plot.index_axis.visible = False
        plot.value_axis.visible = False
        renderer = plot.img_plot("axial", colormap=gray)[0]
        plot.color_mapper.range = DataRange1D(low=0., high=1.0)
        plot.bgcolor = 'pink'

        # Brain tools
        plot.tools.append(PanTool(plot, drag_button="right"))
        plot.tools.append(ZoomTool(plot))
        imgtool = ImageInspectorTool(renderer)
        renderer.tools.append(imgtool)
        overlay = ImageInspectorOverlay(component=renderer, image_inspector=imgtool,
                                        bgcolor="white", border_visible=True)
        renderer.overlays.append(overlay)

        # Brain track cursor
        self.cursor = CursorTool2D(renderer, drag_button='left', color='red', line_width=2.0)
        #self.cursor.on_trait_change(self.update_stackedhist, 'current_index')
        self.cursor.current_positionyou = (0., 0.)
        renderer.overlays.append(self.cursor)

        # Brain colorbar
        colormap = plot.color_mapper
        colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                            color_mapper=colormap,
                            plot=plot,
                            orientation='v',
                            resizable='v',
                            width=20,
                            padding=(30, 0, 0, 0))
        colorbar.padding_top = plot.padding_top
        colorbar.padding_bottom = plot.padding_bottom

        # Noisy brain
        plot2 = Plot(self.brain_data, padding=0)
        plot2.width = self.brain_voxels.shape[1]
        plot2.height = self.brain_voxels.shape[0]
        plot2.aspect_ratio = 1.
        plot2.index_axis.visible = False
        plot2.value_axis.visible = False
        renderer2 = plot2.img_plot("noisy_axial", colormap=gray)[0]
        plot2.color_mapper.range = DataRange1D(low=0., high=1.0)
        plot2.bgcolor = 'pink'
        plot2.range2d = plot.range2d

        # Brain_map tools
        plot2.tools.append(PanTool(plot2, drag_button="right"))
        plot2.tools.append(ZoomTool(plot2))
        imgtool2 = ImageInspectorTool(renderer2)
        renderer2.tools.append(imgtool2)
        overlay2 = ImageInspectorOverlay(component=renderer2, image_inspector=imgtool2,
                                         bgcolor="white", border_visible=True)
        renderer2.overlays.append(overlay2)

        # Brain_map track cursor
        self.cursor2 = CursorTool2D(renderer2, drag_button='left', color='red', line_width=2.0)
        #self.cursor2.on_trait_change(self.cursor2_changed, 'current_index')
        self.cursor2.current_position = (0., 0.)
        renderer2.overlays.append(self.cursor2)

        # Brain_map colorbar
        colormap2 = plot2.color_mapper
        colorbar2 = ColorBar(index_mapper=LinearMapper(range=colormap2.range),
                             color_mapper=colormap2,
                             plot=plot2,
                             orientation='v',
                             resizable='v',
                             width=20,
                             padding=(30, 0, 0, 0))
        colorbar2.padding_top = plot2.padding_top
        colorbar2.padding_bottom = plot2.padding_bottom

        # Create a container to position the plot and the colorbar side-by-side
        container = HPlotContainer(use_backbuffer=True, padding=(0, 0, 10, 10))
        container.add(plot)
        container.add(colorbar)
        container.bgcolor = "lightgray"

        container2 = HPlotContainer(use_backbuffer=True, padding=(0, 0, 10, 10))
        container2.add(plot2)
        container2.add(colorbar2)
        container2.bgcolor = "lightgray"

        Hcontainer = HPlotContainer(use_backbuffer=True)
        Hcontainer.add(container)
        Hcontainer.add(container2)
        Hcontainer.bgcolor = "lightgray"

        return Hcontainer
Exemplo n.º 20
0
def _create_plot_component():

    # Create a scalar field to colormap
    x_extents = (-2 * pi, 2 * pi)
    y_extents = (-1.5 * pi, 1.5 * pi)
    xs = linspace(-2 * pi, 2 * pi, 200)
    ys = linspace(-1.5 * pi, 1.5 * pi, 100)
    x, y = meshgrid(xs, ys)
    zs = sin(log(abs((x+1)**4)+0.05))*cos(y)*1.1*(-y) + \
            sin(((x+1)**2 + y**2)/4)

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("imagedata", zs)

    # Create the left plot, a colormap and simple contours
    lplot = Plot(pd)
    lplot.img_plot("imagedata",
                   name="cm_plot",
                   xbounds=x_extents,
                   ybounds=y_extents,
                   colormap=gmt_drywet)
    lplot.contour_plot("imagedata",
                       type="line",
                       xbounds=x_extents,
                       ybounds=y_extents)

    # Tweak some of the plot properties
    lplot.title = "Colormap and contours"
    lplot.padding = 20
    lplot.bg_color = "white"
    lplot.fill_padding = True

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

    # Right now, some of the tools are a little invasive, and we need the
    # actual CMapImage object to give to them
    cm_plot = lplot.plots["cm_plot"][0]

    # Create the colorbar, handing in the appropriate range and colormap
    colormap = cm_plot.color_mapper
    colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                        color_mapper=colormap,
                        plot=cm_plot,
                        orientation='v',
                        resizable='v',
                        width=30,
                        padding=20)
    colorbar.padding_top = lplot.padding_top
    colorbar.padding_bottom = lplot.padding_bottom

    # Create the left plot, contours of varying color and width
    rplot = Plot(pd, range2d=lplot.range2d)
    rplot.contour_plot("imagedata",
                       type="line",
                       xbounds=x_extents,
                       ybounds=y_extents,
                       bgcolor="black",
                       levels=15,
                       styles="solid",
                       widths=list(linspace(4.0, 0.1, 15)),
                       colors=gmt_drywet)

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

    # Tweak some of the plot properties
    rplot.title = "Varying contour lines"
    rplot.padding = 20
    rplot.bg_color = "white"
    rplot.fill_padding = True

    # Create a container and add our plots
    container = HPlotContainer(padding=40,
                               fill_padding=True,
                               bgcolor="white",
                               use_backbuffer=True)
    container.add(colorbar)
    container.add(lplot)
    container.add(rplot)
    return container
Exemplo n.º 21
0
def _create_plot_component():

    # Create some data
    numpts = 500
    x1 = random(numpts)
    y1 = random(numpts)
    x2 = x1 + standard_normal(numpts) * 0.05
    y2 = y1 + standard_normal(numpts) * 0.05
    color = exp(-(x1**2 + y2**2))
    widths = random(numpts)

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("index", column_stack([x1, x2]).reshape(-1))
    pd.set_data("value", column_stack([y1, y2]).reshape(-1))
    pd.set_data("color", color)
    pd.set_data("widths", widths)

    # Create the plot
    plot = Plot(pd)
    plot.plot(("index", "value", "color", "widths"),
              type="cmap_segment",
              name="my_plot",
              color_mapper=viridis,
              border_visible=True,
              render_style='cubic',
              bgcolor="white",
              size_min=0.5,
              size_max=5.0)

    # Tweak some of the plot properties
    plot.title = "Colormapped Segment Plot with variable widths"
    plot.padding = 50
    plot.x_grid.visible = False
    plot.y_grid.visible = False
    plot.x_axis.font = "modern 16"
    plot.y_axis.font = "modern 16"

    # Right now, some of the tools are a little invasive, and we need the
    # actual ColomappedSegmentPlot object to give to them
    cmap_renderer = plot.plots["my_plot"][0]

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

    # Create the colorbar, handing in the appropriate range and colormap
    colorbar = ColorBar(
        index_mapper=LinearMapper(range=plot.color_mapper.range),
        color_mapper=plot.color_mapper,
        orientation='v',
        resizable='v',
        width=30,
        padding=20)
    colorbar.plot = cmap_renderer
    colorbar.padding_top = plot.padding_top
    colorbar.padding_bottom = plot.padding_bottom

    # Create a container to position the plot and the colorbar side-by-side
    container = HPlotContainer(use_backbuffer=True)
    container.add(plot)
    container.add(colorbar)
    container.bgcolor = "lightgray"
    return container