Esempio n. 1
0
def _render_scatter_overlay(base_plot, array_plot_data,
                            marker="circle", fill_alpha=0.5,
                            marker_size=6, tools=[]):
    #if 'index' not in array_plot_data.arrays:
        #return base_plot, None
    
    scatter_plot = Plot(array_plot_data, aspect_ratio = base_plot.aspect_ratio, 
                default_origin="top left")
    
    if "color" in array_plot_data.arrays:
        scatter_plot.plot(("index", "value", "color"),
                      type="cmap_scatter",
                      name="scatter_plot",
                      color_mapper=jet,
                      marker = marker,
                      fill_alpha = fill_alpha,
                      marker_size = marker_size,
                      )
        scatter_renderer = scatter_plot.plots['scatter_plot'][0]
        colorbar = _create_colorbar(scatter_plot.color_mapper, tools=tools)
        colorbar.plot = scatter_renderer
        #colorbar.padding_top = scatter_renderer.padding_top
        #colorbar.padding_bottom = scatter_renderer.padding_bottom
        if 'colorbar' in tools:
            # this part is for making the colormapped points fade when they
            #  are not selected by the threshold.
            # The renderer is the actual class that does the rendering - 
            # the Plot class calls this other class.  When we say 
            #   plots['scatter_plot']
            # we are getting the named plot that we created above.
            # The extra [0] on the end is because we get a list - in case
            # there is more than one plot named "scatter_plot"
            selection = ColormappedSelectionOverlay(scatter_renderer, 
                                                    fade_alpha=0.35, 
                                                    selection_type="range")
            scatter_renderer.overlays.append(selection)
    else:
        colorbar = None
    if 'inspector' in tools:
        # Attach the inspector and its overlay
        scatter_renderer = scatter_plot.plots['scatter_plot'][0]
        #scatter_plot.tools.append(PeakSelectionTool(scatter_renderer))
        selection = ColormappedSelectionOverlay(scatter_renderer, 
                                                fade_alpha=0.35, 
                                                selection_type="mask")
        scatter_plot.overlays.append(selection)
    scatter_plot.x_grid.visible = False
    scatter_plot.y_grid.visible = False
    scatter_plot.range2d = base_plot.range2d
    return scatter_plot, colorbar
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 _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. 4
0
def create_plot():

    # Create some data
    numpts = 200
    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"

    # Set colors
    #plot.title_color = "white"
    #for axis in plot.x_axis, plot.y_axis:
    #    axis.trait_set(title_color="white", tick_label_color="white")

    # 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)
    plot.tools.append(MoveTool(plot, drag_button="right"))
    return plot
Esempio n. 5
0
    def generate_colorbar(self, desc):
        """ Generate the colorbar to display along side the plot.
        """
        super(CmapScatterPlotFactory, self).generate_colorbar(desc)

        colorbar = self.colorbar
        cmap_renderer = self._get_cmap_renderer()
        select_tool = "colorbar_selector" in self.plot_tools
        if select_tool:
            selection = ColormappedSelectionOverlay(cmap_renderer,
                                                    fade_alpha=0.35,
                                                    selection_type="mask")
            cmap_renderer.overlays.append(selection)

            colorbar.tools.append(RangeSelection(component=colorbar))
            overlay = RangeSelectionOverlay(component=colorbar,
                                            border_color="white",
                                            alpha=0.8,
                                            fill_color="lightgray")
            colorbar.overlays.append(overlay)