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
def _create_plot_component():

    # Create some data
    numpts = 1000
    x = sort(random(numpts))
    y = random(numpts)
    color = randint(0, 7, numpts)

    # 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=accent,
              marker="square",
              fill_alpha=0.5,
              marker_size=6,
              outline_color="black",
              border_visible=True,
              bgcolor="white")

    # Tweak some of the plot properties
    plot.title = "Colormapped Scatter Plot with Range-selectable Data Points"
    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 ColomappedScatterPlot 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)
    selection = ColormappedSelectionOverlay(cmap_renderer,
                                            fade_alpha=0.35,
                                            selection_type="mask")
    cmap_renderer.overlays.append(selection)

    # Create the colorbar, handing in the appropriate range and colormap
    colorbar = create_colorbar(plot.color_mapper)
    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
Esempio n. 3
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
Esempio n. 4
0
def _create_plot_component():
    # Load state data
    states = pandas.read_csv('states.csv')
    lon = (states['longitude'] + 180.) / 360.
    lat = numpy.radians(states['latitude'])
    lat = (1 - (1. - numpy.log(numpy.tan(lat) +
                               (1. / numpy.cos(lat))) / numpy.pi) / 2.0)

    populations = pandas.read_csv('state_populations.csv')
    data = populations['2010']
    lon = lon.view(numpy.ndarray)
    lat = lat.view(numpy.ndarray)
    data = data.view(numpy.ndarray)

    plot = Plot(ArrayPlotData(index=lon, value=lat, color=data))
    renderers = plot.plot(
        ("index", "value", "color"),
        type="cmap_scatter",
        name="unfunded",
        color_mapper=OrRd,
        marker="circle",
        outline_color='lightgray',
        line_width=1.,
        marker_size=10,
    )

    tile_cache = MBTileManager(filename='./map.mbtiles',
                               min_level=2,
                               max_level=4)
    # Need a better way add the overlays
    cmap = renderers[0]

    map = Map(cmap, tile_cache=tile_cache, zoom_level=3)
    cmap.underlays.append(map)

    plot.title = "2010 Population"
    plot.tools.append(PanTool(plot))
    plot.tools.append(ZoomTool(plot))

    plot.index_axis.title = "Longitude"
    plot.index_axis.tick_label_formatter = convert_lon
    plot.value_axis.title = "Latitude"
    plot.value_axis.tick_label_formatter = convert_lat

    cmap.overlays.append(
        ColormappedSelectionOverlay(cmap,
                                    fade_alpha=0.35,
                                    selection_type="mask"))

    colorbar = create_colorbar(plot.color_mapper)
    colorbar.plot = cmap
    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
Esempio n. 5
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=jet,
              marker = "square",
              fill_alpha = 0.5,
              marker_size = 6,
              outline_color = "black",
              border_visible = True,
              bgcolor = "white")

    # Tweak some of the plot properties
    plot.title = "Colormapped Scatter Plot"
    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 ColomappedScatterPlot 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)
    selection = ColormappedSelectionOverlay(cmap_renderer, fade_alpha=0.35,
                                            selection_type="mask")
    cmap_renderer.overlays.append(selection)

    # Create the colorbar, handing in the appropriate range and colormap
    colorbar = create_colorbar(plot.color_mapper)
    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
Esempio n. 6
0
def _create_plot_component():
    # Load state data
    states = pandas.read_csv('states.csv')
    lon = (states['longitude'] + 180.) / 360.
    lat = numpy.radians(states['latitude'])
    lat = (1 - (1. - numpy.log(numpy.tan(lat) +
                               (1./numpy.cos(lat)))/numpy.pi)/2.0)

    populations = pandas.read_csv('state_populations.csv')
    data = populations['2010']
    lon = lon.view(numpy.ndarray)
    lat = lat.view(numpy.ndarray)
    data = data.view(numpy.ndarray)

    plot = Plot(ArrayPlotData(index = lon, value=lat, color=data))
    renderers = plot.plot(("index", "value", "color"),
              type = "cmap_scatter",
              name = "unfunded",
              color_mapper = OrRd,
              marker = "circle",
              outline_color = 'lightgray',
              line_width = 1.,
              marker_size = 10,
              )

    tile_cache = MBTileManager(filename = './map.mbtiles',
                               min_level = 2,
                               max_level = 4)
    # Need a better way add the overlays
    cmap = renderers[0]

    map = Map(cmap, tile_cache=tile_cache, zoom_level=3)
    cmap.underlays.append(map)
    
    plot.title = "2010 Population"
    plot.tools.append(PanTool(plot))
    plot.tools.append(ZoomTool(plot))

    plot.index_axis.title = "Longitude"
    plot.index_axis.tick_label_formatter = convert_lon
    plot.value_axis.title = "Latitude"
    plot.value_axis.tick_label_formatter = convert_lat

    cmap.overlays.append(
            ColormappedSelectionOverlay(cmap, fade_alpha=0.35,
                          selection_type="mask"))

    colorbar = create_colorbar(plot.color_mapper)
    colorbar.plot = cmap
    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
Esempio n. 7
0
def _create_plot_component(max_pop, index_ds, value_ds, color_ds, paths):

    tile_cache = HTTPTileManager(min_level=2, max_level=4,
                                 server='tile.cloudmade.com',
                                 url='/1a1b06b230af4efdbb989ea99e9841af/20760/256/%(zoom)d/%(col)d/%(row)d.png')  # noqa

    color_range = DataRange1D(color_ds, low_setting=0)

    choro = ChoroplethPlot(
              index=index_ds,
              value=value_ds,
              color_data=color_ds,
              index_mapper=LinearMapper(range=DataRange1D(index_ds)),
              value_mapper=LinearMapper(range=DataRange1D(value_ds)),
              color_mapper=colormap(range=color_range),
              outline_color='white',
              line_width=1.5,
              fill_alpha=1.,
              compiled_paths=paths,

              tile_cache=tile_cache,
              zoom_level=3,
              )

    container = OverlayPlotContainer(
        bgcolor='sys_window', padding=50, fill_padding=False,
        border_visible=True,
    )
    container.add(choro)

    for dir in ['left']:
        axis = PlotAxis(tick_label_formatter=convert_lat,
                        mapper=choro.value_mapper, component=container,
                        orientation=dir)
        container.overlays.append(axis)
    for dir in ['top', 'bottom']:
        axis = PlotAxis(tick_label_formatter=convert_lon,
                        mapper=choro.index_mapper, component=container,
                        orientation=dir)
        container.overlays.append(axis)

    choro.tools.append(PanTool(choro))
    choro.tools.append(ZoomTool(choro))

    colorbar = create_colorbar(choro)
    colorbar.padding_top = container.padding_top
    colorbar.padding_bottom = container.padding_bottom

    plt = HPlotContainer(use_backbuffer=True)
    plt.add(container)
    plt.add(colorbar)
    plt.bgcolor = "sys_window"

    return plt
Esempio n. 8
0
 def add_colorbar(self, desc):
     """ Colorbar generated: embed it together with plot & replace in desc.
     """
     plot = desc["plot"]
     container = HPlotContainer(
         **self.plot_style.container_style.to_traits())
     container.add(plot, self.colorbar)
     container.padding_right = sum(
         [comp.padding_right for comp in container.components])
     container.bgcolor = "transparent"
     desc["plot"] = container
Esempio n. 9
0
    def regenerate_plots(self, including_colorbar=False):
        """Function to regenerate entire plot (because many parts of each
        renderer must be updated when product_component or time slice changes)
        """
        active_anim_data = self.active_anim_data

        # first plot
        column_conc_plot = self.contour_plot_from_data(
            active_anim_data,
            COLUMN_CONC_PLOT_ARRAY_NAMES,
            style_dict=COLUMN_CONC_PLOT_STYLE_DICT)

        # second plot
        liq_conc_plot = self.contour_plot_from_data(
            active_anim_data,
            LIQ_CONC_PLOT_ARRAY_NAMES,
            style_dict=LIQ_CONC_PLOT_STYLE_DICT)

        # Add colorbar to plot 2
        if including_colorbar:
            self._colorbar_liquid = self._color_bar_gen(
                liq_conc_plot, LIQ_CONC_COLOR_BAR_STYLE_DICT)

        # third plot
        bound_conc_plot = self.contour_plot_from_data(
            active_anim_data,
            BOUND_CONC_PLOT_ARRAY_NAMES,
            style_dict=BOUND_CONC_PLOT_STYLE_DICT)

        # Add colorbar to plot 3
        if including_colorbar:
            self._colorbar_bound = self._color_bar_gen(
                bound_conc_plot, BOUND_CONC_COLOR_BAR_STYLE_DICT)

        container = HPlotContainer(column_conc_plot, self._colorbar_liquid,
                                   liq_conc_plot, self._colorbar_bound,
                                   bound_conc_plot)

        container.bgcolor = "transparent"
        return container
Esempio n. 10
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
Esempio n. 11
0
def _create_plot_component(max_pop, index_ds, value_ds, color_ds, paths):

    tile_cache = HTTPTileManager(
        min_level=2,
        max_level=4,
        server='tile.cloudmade.com',
        url=
        '/1a1b06b230af4efdbb989ea99e9841af/20760/256/%(zoom)d/%(row)d/%(col)d.png'
    )

    color_range = DataRange1D(color_ds,
                              low_setting=0)  #, high_setting=max_pop)

    choro = ChoroplethPlot(
        index=index_ds,
        value=value_ds,
        color_data=color_ds,
        index_mapper=LinearMapper(range=DataRange1D(index_ds)),
        value_mapper=LinearMapper(range=DataRange1D(value_ds)),
        color_mapper=colormap(range=color_range),
        outline_color='white',
        line_width=1.5,
        fill_alpha=1.,
        compiled_paths=paths,
        tile_cache=tile_cache,
        zoom_level=3,
    )

    container = OverlayPlotContainer(
        bgcolor='sys_window',
        padding=50,
        fill_padding=False,
        border_visible=True,
    )
    container.add(choro)

    for dir in ['left']:
        axis = PlotAxis(tick_label_formatter=convert_lat,
                        mapper=choro.value_mapper,
                        component=container,
                        orientation=dir)
        container.overlays.append(axis)
    for dir in ['top', 'bottom']:
        axis = PlotAxis(tick_label_formatter=convert_lon,
                        mapper=choro.index_mapper,
                        component=container,
                        orientation=dir)
        container.overlays.append(axis)

    choro.tools.append(PanTool(choro))
    choro.tools.append(ZoomTool(choro))

    colorbar = create_colorbar(choro)
    colorbar.padding_top = container.padding_top
    colorbar.padding_bottom = container.padding_bottom

    plt = HPlotContainer(use_backbuffer=True)
    plt.add(container)
    plt.add(colorbar)
    plt.bgcolor = "sys_window"

    return plt
    def _create_plot_component(self):

        # Create a plot data object and give it this data
        self.pd = ArrayPlotData()
        self.pd.set_data("imagedata", self.data[self.data_name])

        # find dimensions
        xdim = self.data[self.data_name].shape[1]
        ydim = self.data[self.data_name].shape[0]

        # Create the plot
        self.tplot = Plot(self.pd, default_origin="top left")
        self.tplot.x_axis.orientation = "top"
        self.tplot.img_plot("imagedata",
                            name="my_plot",
                            xbounds=(0.5, xdim + 0.5),
                            ybounds=(0.5, ydim + 0.5),
                            colormap=jet)

        # Tweak some of the plot properties
        self.tplot.title = "Connection Matrix for %s" % self.data_name
        self.tplot.padding = 80

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

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

        # my custom tool to get the connection information
        self.custtool = CustomTool(self.tplot)
        self.tplot.tools.append(self.custtool)

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

        self.colorbar.padding_top = self.tplot.padding_top
        self.colorbar.padding_bottom = self.tplot.padding_bottom

        # create a range selection for the colorbar
        self.range_selection = RangeSelection(component=self.colorbar)
        self.colorbar.tools.append(self.range_selection)
        self.colorbar.overlays.append(
            RangeSelectionOverlay(component=self.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
        self.range_selection.listeners.append(self.my_plot)

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

        return container
Esempio n. 13
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
Esempio n. 14
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
 def _create_plot_component(self):
     
     # Create a plot data object and give it this data
     self.pd = ArrayPlotData()
     self.pd.set_data("imagedata", self.data[self.data_name])
 
     # find dimensions
     xdim = self.data[self.data_name].shape[1]
     ydim = self.data[self.data_name].shape[0]
 
     # Create the plot
     self.tplot = Plot(self.pd, default_origin="top left")
     self.tplot.x_axis.orientation = "top"
     self.tplot.img_plot("imagedata", 
                   name="my_plot",
                   xbounds=(0.5,xdim + 0.5),
                   ybounds=(0.5,ydim + 0.5),
                   colormap=jet)
 
     # Tweak some of the plot properties
     self.tplot.title = "Connection Matrix for %s" % self.data_name
     self.tplot.padding = 80
 
     # Right now, some of the tools are a little invasive, and we need the 
     # actual CMapImage object to give to them
     self.my_plot = self.tplot.plots["my_plot"][0]
 
     # Attach some tools to the plot
     self.tplot.tools.append(PanTool(self.tplot))
     zoom = ZoomTool(component=self.tplot, tool_mode="box", always_on=False)
     self.tplot.overlays.append(zoom)
     
     # my custom tool to get the connection information
     self.custtool = CustomTool(self.tplot)
     self.tplot.tools.append(self.custtool)
 
     # Create the colorbar, handing in the appropriate range and colormap
     colormap = self.my_plot.color_mapper
     self.colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                         color_mapper=colormap,
                         plot=self.my_plot,
                         orientation='v',
                         resizable='v',
                         width=30,
                         padding=20)
         
     self.colorbar.padding_top = self.tplot.padding_top
     self.colorbar.padding_bottom = self.tplot.padding_bottom
     
     # create a range selection for the colorbar
     self.range_selection = RangeSelection(component=self.colorbar)
     self.colorbar.tools.append(self.range_selection)
     self.colorbar.overlays.append(RangeSelectionOverlay(component=self.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
     self.range_selection.listeners.append(self.my_plot)
 
     # Create a container to position the plot and the colorbar side-by-side
     container = HPlotContainer(use_backbuffer = True)
     container.add(self.tplot)
     container.add(self.colorbar)
     container.bgcolor = "white"
 
     return container
Esempio n. 16
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
Esempio n. 17
0
 def _create_plot_component(self):
     
     # we need the matrices!
     # start with the currently selected one
     #nr_nodes = self.matrix_data_ref[curr_edge].shape[0]
     
     # Create a plot data obect and give it this data
     self.pd = ArrayPlotData()
     self.pd.set_data("imagedata", self.matrix_data_ref[self.curr_edge])
 
     # Create the plot
     self.tplot = Plot(self.pd, default_origin="top left")
     self.tplot.x_axis.orientation = "top"
     self.tplot.img_plot("imagedata", 
                   name="my_plot",
                   #xbounds=(0,nr_nodes),
                   #ybounds=(0,nr_nodes),
                   colormap=jet)
 
     # Tweak some of the plot properties
     self.tplot.title = self.curr_edge
     self.tplot.padding = 50
 
     # Right now, some of the tools are a little invasive, and we need the 
     # actual CMapImage object to give to them
     self.my_plot = self.tplot.plots["my_plot"][0]
 
     # Attach some tools to the plot
     self.tplot.tools.append(PanTool(self.tplot))
     zoom = ZoomTool(component=self.tplot, tool_mode="box", always_on=False)
     self.tplot.overlays.append(zoom)
     
     # my custom tool to get the connection information
     self.custtool = CustomTool(self.tplot)
     self.tplot.tools.append(self.custtool)
 
     # Create the colorbar, handing in the appropriate range and colormap
     colormap = self.my_plot.color_mapper
     self.colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                         color_mapper=colormap,
                         plot=self.my_plot,
                         orientation='v',
                         resizable='v',
                         width=30,
                         padding=20)
         
     self.colorbar.padding_top = self.tplot.padding_top
     self.colorbar.padding_bottom = self.tplot.padding_bottom
     
     # TODO: the range selection gives a Segmentation Fault,
     # but why, the matrix_viewer.py example works just fine!
     # create a range selection for the colorbar
     self.range_selection = RangeSelection(component=self.colorbar)
     self.colorbar.tools.append(self.range_selection)
     self.colorbar.overlays.append(RangeSelectionOverlay(component=self.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
     #self.range_selection.listeners.append(self.my_plot)
 
     # Create a container to position the plot and the colorbar side-by-side
     container = HPlotContainer(use_backbuffer = True)
     container.add(self.tplot)
     container.add(self.colorbar)
     container.bgcolor = "white"
 
     # my_plot.set_value_selection((-1.3, 6.9))
 
     return container
Esempio n. 18
0
    def _create_plot_component(self):

        # we need the matrices!
        # start with the currently selected one
        #nr_nodes = self.matrix_data_ref[curr_edge].shape[0]

        # Create a plot data obect and give it this data
        self.pd = ArrayPlotData()
        self.pd.set_data("imagedata", self.matrix_data_ref[self.curr_edge])

        # Create the plot
        self.tplot = Plot(self.pd, default_origin="top left")
        self.tplot.x_axis.orientation = "top"
        self.tplot.img_plot(
            "imagedata",
            name="my_plot",
            #xbounds=(0,nr_nodes),
            #ybounds=(0,nr_nodes),
            colormap=jet)

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

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

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

        # my custom tool to get the connection information
        self.custtool = CustomTool(self.tplot)
        self.tplot.tools.append(self.custtool)

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

        self.colorbar.padding_top = self.tplot.padding_top
        self.colorbar.padding_bottom = self.tplot.padding_bottom

        # TODO: the range selection gives a Segmentation Fault,
        # but why, the matrix_viewer.py example works just fine!
        # create a range selection for the colorbar
        self.range_selection = RangeSelection(component=self.colorbar)
        self.colorbar.tools.append(self.range_selection)
        self.colorbar.overlays.append(
            RangeSelectionOverlay(component=self.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
        #self.range_selection.listeners.append(self.my_plot)

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

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

        return container