示例#1
0
def get_cmap_scatter_plot():
    boston = datasets.load_boston()
    prices = boston['target']
    lower_status = boston['data'][:,-1]
    nox = boston['data'][:,4]

    x, y = get_data_sources(x=lower_status, y=prices)
    x_mapper, y_mapper = get_mappers(x, y)

    color_source = ArrayDataSource(nox)
    color_mapper = dc.reverse(dc.RdYlGn)(
        DataRange1D(low=nox.min(), high=nox.max())
    )

    scatter_plot = ColormappedScatterPlot(
        index=x, value=y,
        index_mapper=x_mapper, value_mapper=y_mapper,
        color_data=color_source,
        color_mapper=color_mapper,
        marker='circle',
        title='Color represents nitric oxides concentration',
        render_method='bruteforce',
        **PLOT_DEFAULTS
    )

    add_axes(scatter_plot, x_label='Percent lower status in the population',
             y_label='Median house prices')

    return scatter_plot
示例#2
0
def get_cmap_scatter_plot():
    boston = datasets.load_boston()
    prices = boston['target']
    lower_status = boston['data'][:, -1]
    nox = boston['data'][:, 4]

    x, y = get_data_sources(x=lower_status, y=prices)
    x_mapper, y_mapper = get_mappers(x, y)

    color_source = ArrayDataSource(nox)
    color_mapper = dc.reverse(dc.RdYlGn)(DataRange1D(low=nox.min(),
                                                     high=nox.max()))

    scatter_plot = ColormappedScatterPlot(
        index=x,
        value=y,
        index_mapper=x_mapper,
        value_mapper=y_mapper,
        color_data=color_source,
        color_mapper=color_mapper,
        marker='circle',
        title='Color represents nitric oxides concentration',
        render_method='bruteforce',
        **PLOT_DEFAULTS)

    add_axes(scatter_plot,
             x_label='Percent lower status in the population',
             y_label='Median house prices')

    return scatter_plot
示例#3
0
    def _create_colormap(self):
        if self.colormap_low is None:
            self.colormap_low = self.matrix.min()

        if self.colormap_high is None:
            self.colormap_high = self.matrix.max()

        if self.colormap_low >= 0.0:
            colormap_factory = Reds
        else:
            colormap_factory = reverse(RdBu)

        colormap = colormap_factory(
            DataRange1D(low=self.colormap_low, high=self.colormap_high))

        return colormap
示例#4
0
    def _create_colormap(self):
        if self.colormap_low is None:
            self.colormap_low = self.matrix.min()

        if self.colormap_high is None:
            self.colormap_high = self.matrix.max()

        if self.colormap_low >= 0.0:
            colormap_factory = Reds
        else:
            colormap_factory = reverse(RdBu)

        colormap = colormap_factory(
            DataRange1D(low=self.colormap_low, high=self.colormap_high)
        )

        return colormap
示例#5
0
    def _update(self):

        r = self.series.value.get_bounds()
        func = color_map_name_dict[self.cmap]

        if self.reverse:
            func = reverse(func)

        cm = func(DataRange1D(low_setting=0, high_setting=r[1]))

        for i, p in enumerate(self.graph.plots[self.plotid].plots.itervalues()):
            if i == 0:
                continue

            p = p[0]
            p.color_mapper = cm
            p.bgcolor = cm.color_bands[0]

        self.series.invalidate_and_redraw()
  def _modify_colormap(self):

    #myTP.color_mapper.range.low_setting = 0
    #myTP.color_mapper.range.high_setting = 1000

    # pick out the color map function
    myColorMapperFn = default_colormaps.color_map_name_dict[self.colormapNameTE]

    # reverse the colormap, if req'd
    if self.reversedColormapTB:
      myColorMapperFn = default_colormaps.reverse( myColorMapperFn )

    ## TODO adjust for too low, too high, end cases

    myColorMapperFn = default_colormaps.fix(
        myColorMapperFn,
        (self.colormapLowTR, self.colormapHighTR)
    )
    myColorMapper = myColorMapperFn( self.myDR1D )
    self.myTP.color_mapper = myColorMapper
    self.myTP.request_redraw()
示例#7
0
def get_4d_scatter_plot():
    boston = datasets.load_boston()
    prices = boston['target']
    lower_status = boston['data'][:, -1]
    tax = boston['data'][:, 9]
    nox = boston['data'][:, 4]

    x, y = get_data_sources(x=lower_status, y=prices)
    x_mapper, y_mapper = get_mappers(x, y)

    color_source = ArrayDataSource(nox)
    color_mapper = dc.reverse(dc.RdYlGn)(DataRange1D(low=nox.min(),
                                                     high=nox.max()))

    # normalize between 0 and 10
    marker_size = tax / tax.max() * 10.

    scatter_plot = ColormappedScatterPlot(
        index=x,
        value=y,
        index_mapper=x_mapper,
        value_mapper=y_mapper,
        color_data=color_source,
        color_mapper=color_mapper,
        fill_alpha=0.8,
        marker='circle',
        marker_size=marker_size,
        title='Size represents property-tax rate, '
        'color nitric oxides concentration',
        render_method='bruteforce',
        **PLOT_DEFAULTS)

    add_axes(scatter_plot,
             x_label='Percent lower status in the population',
             y_label='Median house prices')

    return scatter_plot
示例#8
0
def get_4d_scatter_plot():
    boston = datasets.load_boston()
    prices = boston['target']
    lower_status = boston['data'][:,-1]
    tax = boston['data'][:,9]
    nox = boston['data'][:,4]

    x, y = get_data_sources(x=lower_status, y=prices)
    x_mapper, y_mapper = get_mappers(x, y)

    color_source = ArrayDataSource(nox)
    color_mapper = dc.reverse(dc.RdYlGn)(
        DataRange1D(low=nox.min(), high=nox.max())
    )

    # normalize between 0 and 10
    marker_size = tax / tax.max() * 10.

    scatter_plot = ColormappedScatterPlot(
        index=x, value=y,
        index_mapper=x_mapper, value_mapper=y_mapper,
        color_data=color_source,
        color_mapper=color_mapper,
        fill_alpha = 0.8,
        marker='circle',
        marker_size=marker_size,
        title='Size represents property-tax rate, '
              'color nitric oxides concentration',
        render_method='bruteforce',
        **PLOT_DEFAULTS
    )

    add_axes(scatter_plot, x_label='Percent lower status in the population',
             y_label='Median house prices')

    return scatter_plot
示例#9
0
    def create_plot_component(self):
        if not self.data.size:
            return

        self.pd = ArrayPlotData()
        self.shape = self.data.shape
        self.pd.set_data("imagedata", self.data)
        self.pd.set_data("left_line", self.data[:, self.shape[0]//2])
        self.pd.set_data("top_line", self.data[self.shape[1]//2,:])

        plot = Plot(self.pd)
        cmap = default_colormaps.color_map_name_dict[self.colormap]

        if self.rev_cmap:
            cmap = default_colormaps.reverse(cmap)

        drange = DataRange1D(ImageData(data=self.data, value_depth=1))



        self.ccmap = cmap_constant_range(cmap, drange)(drange)

            #from copy import copy
        self.img_plot = plot.img_plot("imagedata",
                                 colormap=cmap,
                                 #xbounds=self.xbounds,
                                 #ybounds=self.ybounds,
                                 )[0]
        self.cmap = self.img_plot.value_mapper
        if not self.autoscale:
            self.img_plot.value_mapper = self.ccmap
        # Tweak some of the plot properties
        plot.title = self.title
        plot.padding = 10

        # 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(self.img_plot,
                          drag_button='right',
                          color='white',
                          line_width=2.0
                          )
        self.cursor = csr

        csr.current_index = self.shape[0]//2, self.shape[1]//2
        self.img_plot.overlays.append(csr)

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

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

        self.img_plot.overlays.append(overlay)
        self.plot = plot

        self.cross_plot = Plot(self.pd,resizable='h')
        self.cross_plot.height = 40
        self.cross_plot.padding = 15
        self.cross_plot.plot("top_line",
                             line_style="dot")


        self.cross_plot.index_range = self.img_plot.index_range.x_range


        self.cross_plot2 = Plot(self.pd, width=40, orientation="v",
                                padding=15, padding_bottom=10, resizable='v')
        self.cross_plot2.plot("left_line",
                              line_style="dot")


        self.cross_plot2.index_range = self.img_plot.index_range.y_range

        # Create a container and add components
        #self.container = HPlotContainer(padding=10, fill_padding=False,
        #                                bgcolor="none", use_backbuffer=False)
        #inner_cont = VPlotContainer(padding=0, use_backbuffer=True, bgcolor="none")
        #inner_cont.add(self.plot)
        #inner_cont.add(self.cross_plot)
        self.container = GridPlotContainer(padding=20, fill_padding=False,
                                      bgcolor="none", use_backbuffer=True,
                                      shape=(2, 2), spacing=(12, 20))

        #self.container.add(self.colorbar)
        self.container.add(self.plot)
        self.container.add(self.cross_plot2)
        self.container.add(self.cross_plot)
示例#10
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