Пример #1
0
    def set_data_in_plot(self):
        
        if self.data is None or self.map_container is None:
            return
            
        selected_data = self.data[self.data_selector]
        imagedata = np.mean(selected_data[self.tstart:self.tend,:,:], axis=0)
        self.rfdata.set_data('image', imagedata)
        self.rfdata.set_data('coastlon', self.coastlon)
        self.rfdata.set_data('coastlat', self.coastlat)

        self.plot_title = 'CERES RF DATA %d months average since %04d-%02d-01' % (self.nmonth, self.show_year, self.month_start)
        self.map_plot.title = self.plot_title
        
        if 'model - measurements' in self.data_selector:
            cmin, cmax = -80, 80
        elif self.data_selector.startswith('Shortwave'):
            cmin, cmax = 0, 250
        elif self.data_selector.startswith('Longwave'):
            cmin, cmax = 0, 400
        else:
            cmin, cmax = -50, 50
        self.map_img.color_mapper.range.set_bounds(cmin,cmax)
        
        self.map_colorbar._axis.title = self.data_selector
        
        if 'model - measurements' in self.data_selector or 'Impact' in self.data_selector:
            self.map_img.color_mapper = chaco.RdBu(self.map_img.color_mapper.range)
            self.map_img.color_mapper.reverse_colormap()
        else:
            self.map_img.color_mapper = chaco.jet(self.map_img.color_mapper.range)
    def setUp(self):
        self.index = ArrayDataSource(arange(10))
        self.value = ArrayDataSource(arange(10))
        self.color_data = ArrayDataSource(arange(10))
        self.size_data = arange(10)

        self.index_range = DataRange1D()
        self.index_range.add(self.index)
        self.index_mapper = LinearMapper(range=self.index_range)

        self.value_range = DataRange1D()
        self.value_range.add(self.value)
        self.value_mapper = LinearMapper(range=self.value_range)

        self.color_range = DataRange1D()
        self.color_range.add(self.color_data)
        self.color_mapper = jet(self.color_range)

        self.scatterplot = ColormappedScatterPlot(
            index=self.index,
            value=self.value,
            index_mapper=self.index_mapper,
            value_mapper=self.value_mapper,
            color_data=self.color_data,
            marker_size=self.size_data,
            color_mapper=self.color_mapper,
        )
        self.scatterplot.outer_bounds = [50, 50]
        self.gc = PlotGraphicsContext((50, 50))
    def setUp(self):
        self.index = ArrayDataSource(arange(10))
        self.value = ArrayDataSource(arange(10))
        self.color_data = ArrayDataSource(arange(10))
        self.size_data = arange(10)

        self.index_range = DataRange1D()
        self.index_range.add(self.index)
        self.index_mapper = LinearMapper(range=self.index_range)

        self.value_range = DataRange1D()
        self.value_range.add(self.value)
        self.value_mapper = LinearMapper(range=self.value_range)

        self.color_range = DataRange1D()
        self.color_range.add(self.color_data)
        self.color_mapper = jet(self.color_range)

        self.scatterplot = ColormappedScatterPlot(
            index=self.index,
            value=self.value,
            index_mapper=self.index_mapper,
            value_mapper=self.value_mapper,
            color_data=self.color_data,
            marker_size=self.size_data,
            color_mapper=self.color_mapper,
        )
        self.scatterplot.outer_bounds = [50, 50]
        self.gc = PlotGraphicsContext((50, 50))
  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 = numpy.arange(0, numpts)
    y = numpy.random.random(numpts)
    marker_size = numpy.random.normal(4.0, 4.0, numpts)
    color = numpy.random.random(numpts)

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

    # Because this is a non-standard renderer, we can't call plot.plot, which
    # sets up the array data sources, mappers and default index/value ranges.
    # So, its gotta be done manually for now.

    index_ds = ArrayDataSource(x)
    value_ds = ArrayDataSource(y)
    color_ds = ArrayDataSource(color)

    # Create the plot
    plot = Plot(pd)
    plot.index_range.add(index_ds)
    plot.value_range.add(value_ds)

    # Create the index and value mappers using the plot data ranges
    imapper = LinearMapper(range=plot.index_range)
    vmapper = LinearMapper(range=plot.value_range)

    # Create the scatter renderer
    scatter = ColormappedScatterPlot(
        index=index_ds,
        value=value_ds,
        color_data=color_ds,
        color_mapper=jet(range=DataRange1D(
            low=0.0, high=1.0)),
        fill_alpha=0.4,
        index_mapper=imapper,
        value_mapper=vmapper,
        marker='circle',
        marker_size=marker_size)

    # Append the renderer to the list of the plot's plots
    plot.add(scatter)
    plot.plots['var_size_scatter'] = [scatter]

    # Tweak some of the plot properties
    plot.title = "Variable Size and Color Scatter Plot"
    plot.line_width = 0.5
    plot.padding = 50

    # 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)

    return plot
Пример #6
0
def _create_plot_component():

    # Create some data
    numpts = 1000
    x = numpy.arange(0, numpts)
    y = numpy.random.random(numpts)
    marker_size = numpy.random.normal(4.0, 4.0, numpts)
    color = numpy.random.random(numpts)

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

    # Because this is a non-standard renderer, we can't call plot.plot, which
    # sets up the array data sources, mappers and default index/value ranges.
    # So, its gotta be done manually for now.

    index_ds = ArrayDataSource(x)
    value_ds = ArrayDataSource(y)
    color_ds = ArrayDataSource(color)

    # Create the plot
    plot = Plot(pd)
    plot.index_range.add(index_ds)
    plot.value_range.add(value_ds)

    # Create the index and value mappers using the plot data ranges
    imapper = LinearMapper(range=plot.index_range)
    vmapper = LinearMapper(range=plot.value_range)

    # Create the scatter renderer
    scatter = ColormappedScatterPlot(
                    index=index_ds,
                    value=value_ds,
                    color_data=color_ds,
                    color_mapper=jet(range=DataRange1D(low=0.0, high=1.0)),
                    fill_alpha=0.4,
                    index_mapper = imapper,
                    value_mapper = vmapper,
                    marker='circle',
                    marker_size=marker_size)

    # Append the renderer to the list of the plot's plots
    plot.add(scatter)
    plot.plots['var_size_scatter'] = [scatter]

    # Tweak some of the plot properties
    plot.title = "Variable Size and Color Scatter Plot"
    plot.line_width = 0.5
    plot.padding = 50

    # 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)

    return plot
Пример #7
0
 def render_scatplot(self):
     peakdata=ArrayPlotData()
     peakdata.set_data("index",self.peaks[self.img_idx][:,0])
     peakdata.set_data("value",self.peaks[self.img_idx][:,1])
     peakdata.set_data("color",self.peaks[self.img_idx][:,2])
     scatplot=Plot(peakdata,aspect_ratio=self.img_plot.aspect_ratio,default_origin="top left")
     scatplot.plot(("index", "value", "color"),
                   type="cmap_scatter",
                   name="my_plot",
                   color_mapper=jet(DataRange1D(low = 0.0,
                                    high = 1.0)),
                   marker = "circle",
                   fill_alpha = 0.5,
                   marker_size = 6,
                   )
     scatplot.x_grid.visible = False
     scatplot.y_grid.visible = False
     scatplot.range2d=self.img_plot.range2d
     self.scatplot=scatplot
     self.peakdata=peakdata
     return scatplot
    def __init__(self, x, y, z):
        super(ImagePlot, self).__init__()
        self.pd_all = ArrayPlotData(imagedata=z)
        #self.pd_horiz = ArrayPlotData(x=x, horiz=z[4, :])
        #self.pd_vert = ArrayPlotData(y=y, vert=z[:,5])

        self._imag_index = GridDataSource(xdata=x,
                                          ydata=y,
                                          sort_order=("ascending",
                                                      "ascending"))
        index_mapper = GridMapper(range=DataRange2D(self._imag_index))
        self._imag_index.on_trait_change(self._metadata_changed,
                                         "metadata_changed")
        self._image_value = ImageData(data=z, value_depth=1)
        color_mapper = jet(DataRange1D(self._image_value))

        self.color_plot = CMapImagePlot(index=self._imag_index,
                                        index_mapper=index_mapper,
                                        value=self._image_value,
                                        value_mapper=color_mapper,
                                        padding=20,
                                        use_backbuffer=True,
                                        unified_draw=True)

        #Add axes to image plot
        left = PlotAxis(orientation='left',
                        title="Frequency (GHz)",
                        mapper=self.color_plot.index_mapper._ymapper,
                        component=self.color_plot)

        self.color_plot.overlays.append(left)

        bottom = PlotAxis(orientation='bottom',
                          title="Time (us)",
                          mapper=self.color_plot.index_mapper._xmapper,
                          component=self.color_plot)
        self.color_plot.overlays.append(bottom)

        self.color_plot.tools.append(
            PanTool(self.color_plot, constrain_key="shift"))
        self.color_plot.overlays.append(
            ZoomTool(component=self.color_plot,
                     tool_mode="box",
                     always_on=False))

        #Add line inspector tool for horizontal and vertical
        self.color_plot.overlays.append(
            LineInspector(component=self.color_plot,
                          axis='index_x',
                          inspect_mode="indexed",
                          write_metadata=True,
                          is_listener=True,
                          color="white"))

        self.color_plot.overlays.append(
            LineInspector(component=self.color_plot,
                          axis='index_y',
                          inspect_mode="indexed",
                          write_metadata=True,
                          color="white",
                          is_listener=True))

        myrange = DataRange1D(low=amin(z), high=amax(z))
        cmap = jet
        self.colormap = cmap(myrange)

        # Create a colorbar
        cbar_index_mapper = LinearMapper(range=myrange)
        self.colorbar = ColorBar(index_mapper=cbar_index_mapper,
                                 plot=self.color_plot,
                                 padding_top=self.color_plot.padding_top,
                                 padding_bottom=self.color_plot.padding_bottom,
                                 padding_right=40,
                                 resizable='v',
                                 width=30)  #, ytitle="Magvec (mV)")

        #create horizontal line plot
        self.horiz_cross_plot = Plot(self.pd_horiz, resizable="h")
        self.horiz_cross_plot.height = 100
        self.horiz_cross_plot.padding = 20
        self.horiz_cross_plot.plot(("x", "horiz"))  #,
        #line_style="dot")
        #        self.cross_plot.plot(("scatter_index","scatter_value","scatter_color"),
        #                             type="cmap_scatter",
        #                             name="dot",
        #                             color_mapper=self._cmap(image_value_range),
        #                             marker="circle",
        #                             marker_size=8)

        self.horiz_cross_plot.index_range = self.color_plot.index_range.x_range

        #create vertical line plot
        self.vert_cross_plot = Plot(self.pd_vert,
                                    width=140,
                                    orientation="v",
                                    resizable="v",
                                    padding=20,
                                    padding_bottom=160)
        self.vert_cross_plot.plot(("y", "vert"))  #,
        #                             line_style="dot")
        # self.vert_cross_plot.xtitle="Magvec (mV)"
        #       self.vertica_cross_plot.plot(("vertical_scatter_index",
        #                              "vertical_scatter_value",
        #                              "vertical_scatter_color"),
        #                            type="cmap_scatter",
        #                            name="dot",
        #                            color_mapper=self._cmap(image_value_range),
        #                            marker="circle",
        #                           marker_size=8)

        self.vert_cross_plot.index_range = self.color_plot.index_range.y_range

        # Create a container and add components
        self.container = HPlotContainer(padding=40,
                                        fill_padding=True,
                                        bgcolor="white",
                                        use_backbuffer=False)
        inner_cont = VPlotContainer(padding=0, use_backbuffer=True)
        inner_cont.add(self.horiz_cross_plot)
        inner_cont.add(self.color_plot)
        self.container.add(self.colorbar)
        self.container.add(inner_cont)
        self.container.add(self.vert_cross_plot)
    def __init__(self, x,y,z):
        super(ImagePlot, self).__init__()
        self.pd_all = ArrayPlotData(imagedata = z)
        #self.pd_horiz = ArrayPlotData(x=x, horiz=z[4, :])
        #self.pd_vert = ArrayPlotData(y=y, vert=z[:,5])

        self._imag_index = GridDataSource(xdata=x, ydata=y, sort_order=("ascending","ascending"))
        index_mapper = GridMapper(range=DataRange2D(self._imag_index))
        self._imag_index.on_trait_change(self._metadata_changed,
                                          "metadata_changed")
        self._image_value = ImageData(data=z, value_depth=1)
        color_mapper = jet(DataRange1D(self._image_value))

        self.color_plot= CMapImagePlot(
            index=self._imag_index,
            index_mapper=index_mapper,
            value=self._image_value,
            value_mapper=color_mapper,
            padding=20,
            use_backbuffer=True,
            unified_draw=True)

        #Add axes to image plot
        left = PlotAxis(orientation='left',
                        title= "Frequency (GHz)",
                        mapper=self.color_plot.index_mapper._ymapper,
                        component=self.color_plot)

        self.color_plot.overlays.append(left)

        bottom = PlotAxis(orientation='bottom',
                        title= "Time (us)",
                        mapper=self.color_plot.index_mapper._xmapper,
                        component=self.color_plot)
        self.color_plot.overlays.append(bottom)

        self.color_plot.tools.append(PanTool(self.color_plot,
                                           constrain_key="shift"))
        self.color_plot.overlays.append(ZoomTool(component=self.color_plot,
                                            tool_mode="box", always_on=False))

        #Add line inspector tool for horizontal and vertical
        self.color_plot.overlays.append(LineInspector(component=self.color_plot,
                                               axis='index_x',
                                               inspect_mode="indexed",
                                               write_metadata=True,
                                               is_listener=True,
                                               color="white"))

        self.color_plot.overlays.append(LineInspector(component=self.color_plot,
                                               axis='index_y',
                                               inspect_mode="indexed",
                                               write_metadata=True,
                                               color="white",
                                               is_listener=True))

        myrange = DataRange1D(low=amin(z),
                              high=amax(z))
        cmap=jet
        self.colormap = cmap(myrange)

        # Create a colorbar
        cbar_index_mapper = LinearMapper(range=myrange)
        self.colorbar = ColorBar(index_mapper=cbar_index_mapper,
                                 plot=self.color_plot,
                                 padding_top=self.color_plot.padding_top,
                                 padding_bottom=self.color_plot.padding_bottom,
                                 padding_right=40,
                                 resizable='v',
                                 width=30)#, ytitle="Magvec (mV)")

        #create horizontal line plot
        self.horiz_cross_plot = Plot(self.pd_horiz, resizable="h")
        self.horiz_cross_plot.height = 100
        self.horiz_cross_plot.padding = 20
        self.horiz_cross_plot.plot(("x", "horiz"))#,
                             #line_style="dot")
#        self.cross_plot.plot(("scatter_index","scatter_value","scatter_color"),
#                             type="cmap_scatter",
#                             name="dot",
#                             color_mapper=self._cmap(image_value_range),
#                             marker="circle",
#                             marker_size=8)

        self.horiz_cross_plot.index_range = self.color_plot.index_range.x_range

        #create vertical line plot
        self.vert_cross_plot = Plot(self.pd_vert, width = 140, orientation="v",
                                resizable="v", padding=20, padding_bottom=160)
        self.vert_cross_plot.plot(("y", "vert"))#,
#                             line_style="dot")
       # self.vert_cross_plot.xtitle="Magvec (mV)"
 #       self.vertica_cross_plot.plot(("vertical_scatter_index",
 #                              "vertical_scatter_value",
 #                              "vertical_scatter_color"),
 #                            type="cmap_scatter",
 #                            name="dot",
 #                            color_mapper=self._cmap(image_value_range),
 #                            marker="circle",
  #                           marker_size=8)

        self.vert_cross_plot.index_range = self.color_plot.index_range.y_range

        # Create a container and add components
        self.container = HPlotContainer(padding=40, fill_padding=True,
                                        bgcolor = "white", use_backbuffer=False)
        inner_cont = VPlotContainer(padding=0, use_backbuffer=True)
        inner_cont.add(self.horiz_cross_plot)
        inner_cont.add(self.color_plot)
        self.container.add(self.colorbar)
        self.container.add(inner_cont)
        self.container.add(self.vert_cross_plot)