Example #1
0
    def _container_default(self):
        x = arange(-5.0, 15.0, 20.0/100)

        y = jn(0, x)
        left_plot = create_line_plot((x, y), bgcolor="white",
                                     add_grid=True, add_axis=True)
        left_plot.tools.append(PanTool(left_plot))
        self.left_plot = left_plot

        y = jn(1, x)
        right_plot = create_line_plot((x, y), bgcolor="white",
                                      add_grid=True, add_axis=True)
        right_plot.tools.append(PanTool(right_plot))
        right_plot.y_axis.orientation = "right"
        self.right_plot = right_plot

        # Tone down the colors on the grids
        right_plot.hgrid.line_color = (0.3, 0.3, 0.3, 0.5)
        right_plot.vgrid.line_color = (0.3, 0.3, 0.3, 0.5)
        left_plot.hgrid.line_color = (0.3, 0.3, 0.3, 0.5)
        left_plot.vgrid.line_color = (0.3, 0.3, 0.3, 0.5)

        container = HPlotContainer(spacing=20, padding=50, bgcolor="lightgray")
        container.add(left_plot)
        container.add(right_plot)
        return container
Example #2
0
def _create_plot_component():

    # Create some x-y data series to plot
    x = linspace(-2.0, 10.0, 40)
    pd = ArrayPlotData(index = x, y0=jn(0,x))

    # Create some line plots of some of the data
    plot1 = Plot(pd, title="render_style = hold", padding=50, border_visible=True,
                 overlay_border = True)
    plot1.legend.visible = True
    lineplot = plot1.plot(("index", "y0"), name="j_0", color="red", render_style="hold")

    # Attach some tools to the plot
    attach_tools(plot1)

    # Create a second scatter plot of one of the datasets, linking its
    # range to the first plot
    plot2 = Plot(pd, range2d=plot1.range2d, title="render_style = connectedhold",
                 padding=50, border_visible=True, overlay_border=True)
    plot2.plot(('index', 'y0'), color="blue", render_style="connectedhold")
    attach_tools(plot2)

    # Create a container and add our plots
    container = HPlotContainer()
    container.add(plot1)
    container.add(plot2)
    return container
Example #3
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
def _create_plot_component():

    # Create some x-y data series to plot
    x = linspace(-2.0, 10.0, 100)
    pd = ArrayPlotData(index=x)
    for i in range(5):
        pd.set_data("y" + str(i), jn(i, x))

    # Create some line plots of some of the data
    plot1 = Plot(pd, title="Line Plot", padding=50, border_visible=True)
    plot1.legend.visible = True
    plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")
    plot1.plot(("index", "y3"), name="j_3", color="blue")

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

    # Create a second scatter plot of one of the datasets, linking its
    # range to the first plot
    plot2 = Plot(pd,
                 range2d=plot1.range2d,
                 title="Scatter plot",
                 padding=50,
                 border_visible=True)
    plot2.plot(('index', 'y3'), type="scatter", color="blue", marker="circle")

    # Create a container and add our plots
    container = HPlotContainer()
    container.add(plot1)
    container.add(plot2)

    return container
Example #5
0
    def __init__(self):
        # The delegates views don't work unless we caller the superclass __init__
        super(CursorTest, self).__init__()

        container = HPlotContainer(padding=0, spacing=20)
        self.plot = container
        # a subcontainer for the first plot.
        # I'm not sure why this is required. Without it, the layout doesn't work right.
        subcontainer = OverlayPlotContainer(padding=40)
        container.add(subcontainer)

        # make some data
        index = numpy.linspace(-10, 10, 512)
        value = numpy.sin(index)

        # create a LinePlot instance and add it to the subcontainer
        line = create_line_plot([index, value], add_grid=True, add_axis=True, index_sort="ascending", orientation="h")
        subcontainer.add(line)

        # here's our first cursor.
        csr = CursorTool(line, drag_button="left", color="blue")
        self.cursor1 = csr
        # and set it's initial position (in data-space units)
        csr.current_position = 0.0, 0.0

        # this is a rendered component so it goes in the overlays list
        line.overlays.append(csr)

        # some other standard tools
        line.tools.append(PanTool(line, drag_button="right"))
        line.overlays.append(ZoomTool(line))

        # make some 2D data for a colourmap plot
        xy_range = (-5, 5)
        x = numpy.linspace(xy_range[0], xy_range[1], 100)
        y = numpy.linspace(xy_range[0], xy_range[1], 100)
        X, Y = numpy.meshgrid(x, y)
        Z = numpy.sin(X) * numpy.arctan2(Y, X)

        # easiest way to get a CMapImagePlot is to use the Plot class
        ds = ArrayPlotData()
        ds.set_data("img", Z)

        img = Plot(ds, padding=40)
        cmapImgPlot = img.img_plot("img", xbounds=xy_range, ybounds=xy_range, colormap=jet)[0]

        container.add(img)

        # now make another cursor
        csr2 = CursorTool(cmapImgPlot, drag_button="left", color="white", line_width=2.0)
        self.cursor2 = csr2

        csr2.current_position = 1.0, 1.5

        cmapImgPlot.overlays.append(csr2)

        # add some standard tools. Note, I'm assigning the PanTool to the
        # right mouse-button to avoid conflicting with the cursors
        cmapImgPlot.tools.append(PanTool(cmapImgPlot, drag_button="right"))
        cmapImgPlot.overlays.append(ZoomTool(cmapImgPlot))
Example #6
0
def _create_plot_component():

    # Create some x-y data series to plot
    x = linspace(-2.0, 10.0, 100)
    pd = ArrayPlotData(index = x)
    for i in range(5):
        pd.set_data("y" + str(i), jn(i,x))

    # Create some line plots of some of the data
    plot1 = Plot(pd, title="Line Plot", padding=50, border_visible=True)
    plot1.legend.visible = True
    plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")
    plot1.plot(("index", "y3"), name="j_3", color="blue")

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

    # Create a second scatter plot of one of the datasets, linking its
    # range to the first plot
    plot2 = Plot(pd, range2d=plot1.range2d, title="Scatter plot", padding=50,
                 border_visible=True)
    plot2.plot(('index', 'y3'), type="scatter", color="blue", marker="circle")

    # Create a container and add our plots
    container = HPlotContainer()
    container.add(plot1)
    container.add(plot2)

    return container
Example #7
0
    def _create_plot_component(self):
        
        selected = Event()
    
        # Create some x-y data series to plot
        x = linspace(-2.0, 10.0, 100)
        pd = ArrayPlotData(index = x)
        for i in range(5):
            pd.set_data("y" + str(i), jn(i,x))
    
        # Create some line plots of some of the data
        plot1 = Plot(pd, title="Line Plot", padding=50, border_visible=True)
        plot1.legend.visible = True
        plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")
    
        # Attach some tools to the plot
        plot1.tools.append(PanTool(plot1))
        
        self.zoom = BetterSelectingZoom(component=plot1, tool_mode="box", always_on=False, selection_completed = selected)
        plot1.overlays.append(self.zoom)

        container = HPlotContainer()
        container.add(plot1)
        
        self.zoom.on_trait_change(self.selection_changed, 'ratio')
    
        return container
Example #8
0
def _create_plot_component(obj):
    # Setup the spectrum plot
    frequencies = linspace(0.0, float(SAMPLING_RATE)/2, num=NUM_SAMPLES/2)
    obj.spectrum_data = ArrayPlotData(frequency=frequencies)
    empty_amplitude = zeros(NUM_SAMPLES/2)
    obj.spectrum_data.set_data('amplitude', empty_amplitude)

    obj.spectrum_plot = Plot(obj.spectrum_data)
    spec_renderer = obj.spectrum_plot.plot(("frequency", "amplitude"), name="Spectrum",
                           color="red")[0]
    obj.spectrum_plot.padding = 50
    obj.spectrum_plot.title = "Spectrum"
    spec_range = list(obj.spectrum_plot.plots.values())[0][0].value_mapper.range
    spec_range.low = 0.0
    spec_range.high = 5.0
    obj.spectrum_plot.index_axis.title = 'Frequency (hz)'
    obj.spectrum_plot.value_axis.title = 'Amplitude'

    # Time Series plot
    times = linspace(0.0, float(NUM_SAMPLES)/SAMPLING_RATE, num=NUM_SAMPLES)
    obj.time_data = ArrayPlotData(time=times)
    empty_amplitude = zeros(NUM_SAMPLES)
    obj.time_data.set_data('amplitude', empty_amplitude)

    obj.time_plot = Plot(obj.time_data)
    obj.time_plot.plot(("time", "amplitude"), name="Time", color="blue")
    obj.time_plot.padding = 50
    obj.time_plot.title = "Time"
    obj.time_plot.index_axis.title = 'Time (seconds)'
    obj.time_plot.value_axis.title = 'Amplitude'
    time_range = list(obj.time_plot.plots.values())[0][0].value_mapper.range
    time_range.low = -0.2
    time_range.high = 0.2

    # Spectrogram plot
    values = [zeros(NUM_SAMPLES/2) for i in range(SPECTROGRAM_LENGTH)]
    p = WaterfallRenderer(index = spec_renderer.index, values = values,
            index_mapper = LinearMapper(range = obj.spectrum_plot.index_mapper.range),
            value_mapper = LinearMapper(range = DataRange1D(low=0, high=SPECTROGRAM_LENGTH)),
            y2_mapper = LinearMapper(low_pos=0, high_pos=8,
                            range=DataRange1D(low=0, high=15)),
            )
    spectrogram_plot = p
    obj.spectrogram_plot = p
    dummy = Plot()
    dummy.padding = 50
    dummy.index_axis.mapper.range = p.index_mapper.range
    dummy.index_axis.title = "Frequency (hz)"
    dummy.add(p)

    container = HPlotContainer()
    container.add(obj.spectrum_plot)
    container.add(obj.time_plot)

    c2 = VPlotContainer()
    c2.add(dummy)
    c2.add(container)

    return c2
Example #9
0
    def create_plot(self):

        # Create the mapper, etc
        self._image_index = GridDataSource(array([]),
                                           array([]),
                                           sort_order=("ascending",
                                                       "ascending"))
        image_index_range = DataRange2D(self._image_index)
        # self._image_index.on_trait_change(self._metadata_changed,
        #                                   "metadata_changed")

        self._image_value = ImageData(data=array([]), value_depth=1)
        image_value_range = DataRange1D(self._image_value)

        # Create the colormapped scalar plot
        self.plot = CMapImagePlot(
            index=self._image_index,
            index_mapper=GridMapper(range=image_index_range),
            value=self._image_value,
            value_mapper=self._cmap(image_value_range))

        # Add a left axis to the plot
        left = PlotAxis(orientation='left',
                        title="y",
                        mapper=self.plot.index_mapper._ymapper,
                        component=self.plot)
        self.plot.overlays.append(left)

        # Add a bottom axis to the plot
        bottom = PlotAxis(orientation='bottom',
                          title="x",
                          mapper=self.plot.index_mapper._xmapper,
                          component=self.plot)
        self.plot.overlays.append(bottom)

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

        # Create a colorbar
        cbar_index_mapper = LinearMapper(range=image_value_range)
        self.colorbar = ColorBar(index_mapper=cbar_index_mapper,
                                 plot=self.plot,
                                 padding_top=self.plot.padding_top,
                                 padding_bottom=self.plot.padding_bottom,
                                 padding_right=40,
                                 resizable='v',
                                 width=10)

        # Create a container and add components
        self.container = HPlotContainer(padding=40,
                                        fill_padding=True,
                                        bgcolor="white",
                                        use_backbuffer=False)
        self.container.add(self.colorbar)
        self.container.add(self.plot)
Example #10
0
    def create_plot(self):

        self.pd = ArrayPlotData(line_index=array([]), line_value=array([]))

        # Create the colormapped scalar plot
        self.line_plot = Plot(self.pd)
        self.line_plot.plot(("line_index", "line_value"), type="line")

        # Create a container and add components
        self.container = HPlotContainer()
        self.container.add(self.line_plot)
Example #11
0
def _create_plot_component():

    # Create some x-y data series to plot
    plot_area = OverlayPlotContainer(border_visible=True)
    container = HPlotContainer(padding=50, bgcolor="transparent")
    #container.spacing = 15

    x = linspace(-2.0, 10.0, 100)
    for i in range(5):
        color = tuple(COLOR_PALETTE[i])
        y = jn(i, x)
        renderer = create_line_plot((x, y), color=color)
        plot_area.add(renderer)
        #plot_area.padding_left = 20

        axis = PlotAxis(orientation="left", resizable="v",
                    mapper = renderer.y_mapper,
                    axis_line_color=color,
                    tick_color=color,
                    tick_label_color=color,
                    title_color=color,
                    bgcolor="transparent",
                    title = "jn_%d" % i,
                    border_visible = True,)
        axis.bounds = [60,0]
        axis.padding_left = 10
        axis.padding_right = 10

        container.add(axis)

        if i == 4:
            # Use the last plot's X mapper to create an X axis and a
            # vertical grid
            x_axis = PlotAxis(orientation="bottom", component=renderer,
                        mapper=renderer.x_mapper)
            renderer.overlays.append(x_axis)
            grid = PlotGrid(mapper=renderer.x_mapper, orientation="vertical",
                    line_color="lightgray", line_style="dot")
            renderer.underlays.append(grid)

    # Add the plot_area to the horizontal container
    container.add(plot_area)

    # Attach some tools to the plot
    broadcaster = BroadcasterTool()
    for plot in plot_area.components:
        broadcaster.tools.append(PanTool(plot))

    # Attach the broadcaster to one of the plots.  The choice of which
    # plot doesn't really matter, as long as one of them has a reference
    # to the tool and will hand events to it.
    plot.tools.append(broadcaster)

    return container
Example #12
0
File: graph.py Project: mtim/BacLog
class Graph(HasTraits):
    plot=None
    traits_view=View(Item('plot',editor=ComponentEditor(bgcolor="white"), show_label=False),
                     width=1200, height=1024, resizable=True, title="BacLog")
    
    def __init__(self):
        super(Graph,self).__init__()
        self.container = HPlotContainer(padding=20, bgcolor="transparent")
        self.plot_area = OverlayPlotContainer(border_visible=True)

    def add(self,series,limit=None):
        
        broadcaster = BroadcasterTool()
        
        for name,line in series._plot.line.items():
            if limit is not None and name not in limit:
                continue
            if line.time==[]:
                print "Graph.add> empty:", name
                continue
            plot=create_line_plot((seconds(line.time),line.data),color=line.color)
            self.plot_area.add(plot)

            axis = PlotAxis(orientation="left", resizable="v",
                            mapper = plot.y_mapper,
                            bgcolor="white",
                            title = name,
                            title_color = line.color,
                            title_spacing = -4.0,
                            border_visible = True,)
            ## Visual style
            axis.bounds = [60,0]
            axis.padding_left = 1
            axis.padding_right = 1
            self.container.add(axis)

            ## Tools (attach to all for now)
            plot.tools.append(broadcaster)
            broadcaster.tools.append(PanTool(plot))
            broadcaster.tools.append(DragZoom(plot,maintain_aspect_ratio=False,drag_button='right',restrict_domain=True))

        
    def run(self):

        ## Time axis (first one)
        plot=self.plot_area.components[0]
        time = PlotAxis(orientation="bottom", component=plot, mapper=plot.x_mapper)
        plot.overlays.append(time)

        ## Plot
        self.container.add(self.plot_area)
        self.plot=self.container

        self.configure_traits()
    def _plot1_2d_container_default(self):
        if self.cost_data is None or len(self.cost_data) == 0:
            return

        plot = Plot(self.cost_plot_data)
        plot.title = "Cost function"
        plot.padding_left = 80
        container = HPlotContainer()
        container.add(plot)
        self.rebuild_renderer(container)
        return container
Example #14
0
 def _plot_default(self):
     data = self.data < self.limit
     pd = self.pd = ArrayPlotData(imagedata=data,orig=self.data)
     plot1 = Plot(pd, default_origin='top left')
     plot2 = Plot(pd, default_origin='top left')
     img_plot1 = plot1.img_plot("imagedata",colormap=gray,padding=0)[0]
     img_plot2 = plot2.img_plot("orig",colormap=gray,padding=0)[0]
     container = HPlotContainer(plot1,plot2)
     container.spacing=0
     plot1.padding_right=0
     plot2.padding_left=0
     plot2.y_axis.orientation= 'right'
     return container
Example #15
0
 def test_valign(self):
     container = HPlotContainer(bounds=[300, 200], valign="center")
     comp1 = StaticPlotComponent([200, 100])
     container.add(comp1)
     container.do_layout()
     self.assertEqual(comp1.position, [0, 50])
     container.valign = "top"
     container.do_layout(force=True)
     self.assertEqual(comp1.position, [0, 100])
     return
Example #16
0
    def _figure_image_default(self):
        plot = Plot(self.plot_data_image, width=180, height=180, padding=3, padding_left=48, padding_bottom=32)
        plot.img_plot('image', colormap=jet, name='image')
        plot.aspect_ratio=1
        #plot.value_mapper.domain_limits = (scanner.getYRange()[0],scanner.getYRange()[1])
        #plot.index_mapper.domain_limits = (scanner.getXRange()[0],scanner.getXRange()[1])
        plot.value_mapper.domain_limits = (0,self.size_xy)
        plot.index_mapper.domain_limits = (0,self.size_xy)

        container = HPlotContainer()
        image = plot.plots['image'][0]
        colormap = image.color_mapper
        colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                            color_mapper=colormap,
                            plot=plot,
                            orientation='v',
                            resizable='v',
                            width=20,
                            height=200,
                            padding=8,
                            padding_left=20)
        container = HPlotContainer()
        container.add(plot)
        container.add(colorbar)
        return container
Example #17
0
    def _load_image_data(self, data):
        cont = HPlotContainer()
        pd = ArrayPlotData()
        plot = Plot(data=pd, padding=[30, 5, 5, 30], default_origin="top left")

        pd.set_data("img", data)
        img_plot = plot.img_plot("img")[0]

        self._add_inspector(img_plot)
        self._add_tools(img_plot)

        cont.add(plot)
        cont.request_redraw()
        self.image_container.container = cont
Example #18
0
    def __init__(self):
        # Create the data and the PlotData object
        x = linspace(-14, 14, 100)
        y = sin(x) * x**3
        plotdata = ArrayPlotData(x = x, y = y)

        # Create a scatter plot
        scatter_plot = Plot(plotdata)
        scatter_plot.plot(("x", "y"), type="scatter", color="blue")

        # Create a line plot
        line_plot1 = Plot(plotdata)
        line_plot1.plot(("x", "y"), type="line", color="blue")
        line_plot2 = Plot(plotdata)
        line_plot2.plot(("x", "y"), type="line", color="red")

        # Create a vertical container containing two horizontal containers
        h_container1 = HPlotContainer()
        h_container2 = HPlotContainer()
        outer_container = VPlotContainer(h_container1, h_container2,
                                         stack_order="top_to_bottom")

        # Add the two plots to the first container
        h_container1.add(scatter_plot, line_plot1, line_plot2)

        # Now add the first line plot to the second container => it is removed
        # from the first, as each plot can only have one container
        h_container2.add(line_plot1)

        self.plot = outer_container
Example #19
0
def _create_plot_component():

    # Create some x-y data series to plot
    x = linspace(-2.0, 10.0, 100)
    pd = ArrayPlotData(index = x)
    for i in range(5):
        pd.set_data("y" + str(i), jn(i,x))

    # Create some line plots of some of the data
    plot = Plot(pd, title="Line Plot", padding=50, border_visible=True)
    plot.legend.visible = True
    plot.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="auto")
    plot.plot(("index", "y3"), name="j_3", color="auto")

    plot.x_grid.line_color = "black"
    plot.y_grid.line_color = "black"
    xmin, xmax = 1.0, 6.0
    ymin, ymax = 0.2, 0.80001
    plot.x_grid.set(data_min = xmin, data_max = xmax,
            transverse_bounds = (ymin, ymax),
            transverse_mapper = plot.y_mapper)

    plot.y_grid.set(data_min = ymin, data_max = ymax,
            transverse_bounds = (xmin, xmax),
            transverse_mapper = plot.x_mapper)

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

    # A second plot whose vertical grid lines are clipped to the jn(3) function
    def my_bounds_func(ticks):
        """ Returns y_low and y_high for each grid tick in the array **ticks** """
        tmp = array([zeros(len(ticks)),jn(3, ticks)]).T
        return tmp

    func_plot = Plot(pd, padding=50, border_visible=True)
    func_plot.plot(("index", "y3"), color="red")
    func_plot.x_grid.set(transverse_bounds = my_bounds_func,
                    transverse_mapper = func_plot.y_mapper,
                    line_color="black")
    func_plot.tools.append(PanTool(func_plot))

    container = HPlotContainer()
    container.add(plot)
    container.add(func_plot)

    return container
Example #20
0
def _create_plot_component(obj):
    # Setup the spectrum plot
    frequencies = linspace(0.0, float(SAMPLING_RATE)/2, num=NUM_SAMPLES/2)
    obj.spectrum_data = ArrayPlotData(frequency=frequencies)
    empty_amplitude = zeros(NUM_SAMPLES/2)
    obj.spectrum_data.set_data('amplitude', empty_amplitude)

    obj.spectrum_plot = Plot(obj.spectrum_data)
    obj.spectrum_plot.plot(("frequency", "amplitude"), name="Spectrum",
                           color="red")
    obj.spectrum_plot.padding = 50
    obj.spectrum_plot.title = "Spectrum"
    spec_range = obj.spectrum_plot.plots.values()[0][0].value_mapper.range
    spec_range.low = 0.0
    spec_range.high = 5.0
    obj.spectrum_plot.index_axis.title = 'Frequency (hz)'
    obj.spectrum_plot.value_axis.title = 'Amplitude'

    # Time Series plot
    times = linspace(0.0, float(NUM_SAMPLES)/SAMPLING_RATE, num=NUM_SAMPLES)
    obj.time_data = ArrayPlotData(time=times)
    empty_amplitude = zeros(NUM_SAMPLES)
    obj.time_data.set_data('amplitude', empty_amplitude)

    obj.time_plot = Plot(obj.time_data)
    obj.time_plot.plot(("time", "amplitude"), name="Time", color="blue")
    obj.time_plot.padding = 50
    obj.time_plot.title = "Time"
    obj.time_plot.index_axis.title = 'Time (seconds)'
    obj.time_plot.value_axis.title = 'Amplitude'
    time_range = obj.time_plot.plots.values()[0][0].value_mapper.range
    time_range.low = -0.2
    time_range.high = 0.2

    # Spectrogram plot
    spectrogram_data = zeros(( NUM_SAMPLES/2, SPECTROGRAM_LENGTH))
    obj.spectrogram_plotdata = ArrayPlotData()
    obj.spectrogram_plotdata.set_data('imagedata', spectrogram_data)
    spectrogram_plot = Plot(obj.spectrogram_plotdata)
    max_time = float(SPECTROGRAM_LENGTH * NUM_SAMPLES) / SAMPLING_RATE
    max_freq = float(SAMPLING_RATE / 2)
    spectrogram_plot.img_plot('imagedata',
                              name='Spectrogram',
                              xbounds=(0, max_time),
                              ybounds=(0, max_freq),
                              colormap=jet,
                              )
    range_obj = spectrogram_plot.plots['Spectrogram'][0].value_mapper.range
    range_obj.high = 5
    range_obj.low = 0.0
    spectrogram_plot.title = 'Spectrogram'
    obj.spectrogram_plot = spectrogram_plot

    container = HPlotContainer()
    container.add(obj.spectrum_plot)
    container.add(obj.time_plot)
    container.add(spectrogram_plot)

    return container
Example #21
0
    def __init__(self, *args, **kwargs):
        """Instantiates the mandelbrot model and necessary objects for the view/controller."""
        super().__init__(*args, **kwargs)
        self.mandelbrot_model = MandelbrotModel()
        self._update_with_initial_plot_data()

        self.image_plot = self._create_image_plot()
        self.container = HPlotContainer(padding=10,
                                        fill_padding=True,
                                        bgcolor="white",
                                        use_backbuffer=True)
        self.container.add(self._plot_object)
        self._fix_aspect_ratio()
        self._colormap_changed()
        self._append_tools()
Example #22
0
    def activate_template ( self ):
        """ Converts all contained 'TDerived' objects to real objects using the
            template traits of the object. This method must be overridden in
            subclasses.

            Returns
            -------
            None
        """
        plots = [ p for p in [ self.scatter_plot_1.plot,
                               self.scatter_plot_2.plot ] if p is not None ]
        if len( plots ) == 2:
            self.plot = HPlotContainer( spacing = self.spacing )
            self.plot.add( *plots )
        elif len( plots ) == 1:
            self.plot = plots[0]
    def _container_default(self):
        x = linspace(-10, 10, 100)
        y = sin(x) * x
        plotdata = ArrayPlotData(x=x, y=y)

        scatter = Plot(plotdata)
        scatter.plot(('x', 'y'), type='scatter', color='blue')

        line = Plot(plotdata)
        line.plot(('x', 'y'), type='line', color='green')

        container = HPlotContainer(scatter, line)

        scatter.tools.append(PanTool(scatter))
        scatter.tools.append(ZoomTool(scatter))

        line.tools.append(PanTool(line))
        line.tools.append(ZoomTool(line))

        # Chaco has the concept of data range to express bounds in data space
        # Standard 2D plots all have 2D ranges on them
        # Here two plots now share same range object, and will change together
        # In response to changes to the data space bounds.
        scatter.range2d = line.range2d
        return container
Example #24
0
    def __init__(self):
        # Create the data and the PlotData object
        x = linspace(-14, 14, 100)
        y = sin(x) * x**3
        plotdata = ArrayPlotData(x=x, y=y)

        # Create the scatter plot
        scatter = Plot(plotdata)
        scatter.plot(("x", "y"), type="scatter", color="blue")

        # Create the line plot
        line = Plot(plotdata)
        line.plot(("x", "y"), type="line", color="blue")

        # Create a horizontal container and put the two plots inside it
        self.container = HPlotContainer(scatter, line)

        # Add pan/zoom so we can see they are connected
        scatter.tools.append(PanTool(scatter))
        scatter.tools.append(ZoomTool(scatter))
        line.tools.append(PanTool(line))
        line.tools.append(ZoomTool(line))

        # Set the two plots' ranges to be the same
        scatter.range2d = line.range2d
Example #25
0
    def _interp_data_button_fired(self):
        x = [row.x for row in self.rows]
        y = [row.y for row in self.rows]

        f = interp1d(asarray(x), asarray(y))
        y2 = Array
        print x, sorted(x)
        y2 = [f(i) for i in sorted(x)]

        print y2

        plotdata = ArrayPlotData(x=x, y=y)
        plotdata2 = ArrayPlotData(y=y2)

        test_plot = Plot(plotdata)
        test_plot.plot(("x", "y"), type="scatter")
        test_plot.plot(("x", "y"), type="line")
        test_plot_2 = Plot(plotdata2)
        #test_plot_2.plot("y2", type="line")
        # changing type to line w)ill make the
        # plot a line plot! not recommended!
        """
        test_plot = plot(x,y,"b-", bgcolor="white")
        test_plot.hold()
        test_plot = plot(x,y2,"g-")
        """
        container = HPlotContainer(test_plot)  #,test_plot_2)
        self.aplot = container
Example #26
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
Example #27
0
    def _container_default(self):
        # Create the data and the PlotData object
        x = linspace(-14, 14, 100)
        y = sin(x) * x**3
        plotdata = ArrayPlotData(x=x, y=y)

        # Create the scatter plot
        scatter = Plot(plotdata)
        scatter.plot(("x", "y"), type="scatter", color="blue")

        # Create the line plot, rotated and vertically oriented
        line = Plot(plotdata, orientation="v", default_origin="top left")
        line.plot(("x", "y"), type="line", color="blue")

        # Add pan/zoom so we can see they are connected
        scatter.tools.append(PanTool(scatter))
        scatter.tools.append(ZoomTool(scatter))
        line.tools.append(PanTool(line))
        line.tools.append(ZoomTool(line))

        # Set the two plots' ranges to be the same
        scatter.range2d = line.range2d

        # Create a horizontal container and put the two plots inside it
        return HPlotContainer(scatter, line)
Example #28
0
    def __init__(self):
        super(ConnectedRange, self).__init__()
        x = linspace(-14, 14, 100)
        y = sin(x) * x ** 3
        plotdata = ArrayPlotData(x=x, y=y)

        scatter = Plot(plotdata)
        scatter.plot(("x", "y"), type="scatter", color="blue")

        line = Plot(plotdata)
        #line = Plot(plotdata, orientation="v", default_origin="top left")
        line.plot(("x", "y"), type="line", color="red")

        self.container = HPlotContainer(scatter, line)

        scatter.tools.append(PanTool(scatter))
        scatter.tools.append(ZoomTool(scatter))

        line.tools.append(PanTool(line))
        line.tools.append(ZoomTool(line))

        #Axis link options, try them out
        #scatter.value_range = line.value_range  # Link y-axis only
        #scatter.index_range = line.index_range  # Link x-axis only
        scatter.range2d = line.range2d  # Link both axes
Example #29
0
    def _add_line_plots(self, plot):
        """Adds curve line plots to the ChacoPlot"""

        line_plots = []
        for plot_config in self.line_plot_configs:
            line_plot = ChacoPlot(self._plot_data)

            # Customize text
            line_plot.trait_set(title=plot_config.title,
                                padding=75,
                                line_width=1)
            line_plot.x_axis.title = plot_config.x_label
            line_plot.y_axis.title = plot_config.y_label

            # Add pan and zoom tools
            line_plot.tools.append(PanTool(line_plot))
            line_plot.overlays.append(ZoomTool(line_plot))

            for name, kwargs in plot_config.line_config.items():
                line = line_plot.plot((f"x_line_{name}", f"y_line_{name}"),
                                      type="line",
                                      **kwargs)[0]
                self._sub_axes[f'{name}_line_plot'] = line

            line_plots.append(line_plot)

        container = GridPlotContainer(*line_plots,
                                      shape=self._grid_shape,
                                      spacing=(0, 0),
                                      valign='top',
                                      bgcolor="none")
        self._component = HPlotContainer(plot, container, bgcolor="none")
        self._line_plots = line_plots
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 test_valign(self):
     container = HPlotContainer(bounds=[300,200], valign="center")
     comp1 = StaticPlotComponent([200,100])
     container.add(comp1)
     container.do_layout()
     self.assertEqual(comp1.position, [0,50])
     container.valign="top"
     container.do_layout(force=True)
     self.assertEqual(comp1.position, [0,100])
     return
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
Example #33
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
Example #34
0
def _create_plot_component():

    # Create the index
    numpoints = 100
    low = -5
    high = 15.0
    x = arange(low, high, (high - low) / numpoints)
    plotdata = ArrayPlotData(x=x, y1=jn(0, x), y2=jn(1, x))

    # Create the left plot
    left_plot = Plot(plotdata)
    left_plot.x_axis.title = "X"
    left_plot.y_axis.title = "j0(x)"
    renderer = left_plot.plot(("x", "y1"), type="line", color="blue",
                              width=2.0)[0]
    renderer.overlays.append(LineInspector(renderer, axis='value',
                                            write_metadata=True,
                                            is_listener=True))
    renderer.overlays.append(LineInspector(renderer, axis="index",
                                            write_metadata=True,
                                            is_listener=True))
    left_plot.overlays.append(ZoomTool(left_plot, tool_mode="range"))
    left_plot.tools.append(PanTool(left_plot))

    # Create the right plot
    right_plot = Plot(plotdata)
    right_plot.index_range = left_plot.index_range
    right_plot.orientation = "v"
    right_plot.x_axis.title = "j1(x)"
    right_plot.y_axis.title = "X"
    renderer2 = right_plot.plot(("x", "y2"), type="line", color="red",
                                width=2.0)[0]
    renderer2.index = renderer.index
    renderer2.overlays.append(LineInspector(renderer2, write_metadata=True,
                              is_listener=True))
    renderer2.overlays.append(LineInspector(renderer2, axis="value",
                              is_listener=True))
    right_plot.overlays.append(ZoomTool(right_plot, tool_mode="range"))
    right_plot.tools.append(PanTool(right_plot))

    container = HPlotContainer(background="lightgray")
    container.add(left_plot)
    container.add(right_plot)

    return container
Example #35
0
    def __init__(self, **kwargs):

        super(Plot2D, self).__init__(**kwargs)

        self.renderer = ChacoPlot2D(self.data)
        self.renderer.padding = (80, 50, 10, 40)

        # Dummy plot so that the color bar can be correctly initialized
        xs = linspace(-2, 2, 600)
        ys = linspace(-1.2, 1.2, 300)
        x, y = meshgrid(xs, ys)
        z = tanh(x*y/6)*cosh(exp(-y**2)*x/3)
        z = x*y
        self.data.set_data('c', z)
        self.renderer.img_plot(('c'), name='c',
                               colormap=self._cmap,
                               xbounds=(self.x_min, self.x_max),
                               ybounds=(self.y_min, self.y_max))

        # Add basic tools and ways to activate them in public API
        zoom = BetterSelectingZoom(self.renderer, tool_mode="box",
                                   always_on=False)
        self.renderer.overlays.append(zoom)
        self.renderer.tools.append(PanTool(self.renderer,
                                           restrict_to_data=True))

        # Create the colorbar, the appropriate range and colormap are handled
        # at the plot creation
        mapper = LinearMapper(range=self.renderer.color_mapper.range)
        self.colorbar = ColorBar(index_mapper=mapper,
                                 color_mapper=self.renderer.color_mapper,
                                 plot=self.renderer,
                                 orientation='v',
                                 resizable='v',
                                 width=20,
                                 padding=10)

        self.colorbar.padding_top = self.renderer.padding_top
        self.colorbar.padding_bottom = self.renderer.padding_bottom

        self.container = HPlotContainer(self.renderer,
                                        self.colorbar,
                                        use_backbuffer=True,
                                        bgcolor="lightgray")

        # Add pan and zoom tools to the colorbar
        self.colorbar.tools.append(PanTool(self.colorbar,
                                           constrain_direction="y",
                                           constrain=True)
                                   )
        self.zoom_colorbar = zoom_bar(self.colorbar,
                                      box=False,
                                      reset=True,
                                      orientation='vertical'
                                      )
        self.colormap = 'Blues'
    def _plot_default(self):
        # Create the data and the PlotData object
        x = linspace(-14, 14, 100)
        y = sin(x) * x**3
        plotdata = ArrayPlotData(x = x, y = y)
        # Create the scatter plot
        scatter = Plot(plotdata)
        scatter.plot(("x", "y"), type="scatter", color="blue")
        # Create the line plot
        line = Plot(plotdata)
        line.plot(("x", "y"), type="line", color="blue")
        # Create a horizontal container and put the two plots inside it
        container = HPlotContainer(scatter, line)
        container.spacing = 0
        scatter.padding_right = 0
        line.padding_left = 0
        line.y_axis.orientation = "right"

        return container
Example #37
0
    def __init__(self):
        # Create the data and the PlotData object
        x = linspace(-14, 14, 100)
        y = sin(x) * x**3
        plotdata = ArrayPlotData(x=x, y=y)
        # Create the scatter plot
        scatter = Plot(plotdata)
        scatter.plot(("x", "y"), type="scatter", color="blue")
        # Create the line plot
        line = Plot(plotdata)
        line.plot(("x", "y"), type="line", color="blue")
        # Create a horizontal container and put the two plots inside it
        container = HPlotContainer(scatter, line)
        container.spacing = 0
        scatter.padding_right = 0
        line.padding_left = 0
        line.y_axis.orientation = "right"

        self.plot = container
Example #38
0
    def __init__(self, **traits):
        Ice.Application.__init__(self)
        HasTraits.__init__(self,**traits)

        plots = {}
        self.container = OverlayPlotContainer(padding = 50, fill_padding = True,
                                         bgcolor = "lightgray", use_backbuffer=True)
        self.jtrig = 0
        self.trigTelType = 0
        self.CAMERAlayout = ArrayPlotData()
Example #39
0
   def createPlot( self, showDataTag ):
      
      # picks the desired channel out of the interleaved data
      stride = self.header.getChannels()

      # the first sample contains the data tag - the user has the 
      # option to not display with the offset enabled
      offset = 0 if showDataTag else stride

      # we first grab the entire table and then select ALL ipps
      # along with the associated channel we're interested in. 
      # I'm assuming this slice is a reference of the original.
      self.dataView = self.header.getBuffer()[ :, offset::stride ]

      i = self.dataView['real']
      q = self.dataView['imag']
      xAxis = range( offset, i.size )

      # compute magnitude
      pwr = ( i**2.00 + q**2.00 )

      # compute power in dB
      pwr = 10*log10(pwr)

      # limit lower data value to -40dB to prevent -inf problems
      pwr = clip(pwr, -40, pwr.max() )

      plotData = ArrayPlotData( pwr=pwr ) 
      plot = Plot( plotData )
      plot.img_plot( 
            'pwr', 
            xbounds=(0,self.header.getSamples()-offset),
            ybounds=(0,self.header.getIpps())
            )
      plot.title = 'RTI Plot'

      colorbar = self.createColorbar( plot.color_mapper )
      container = HPlotContainer( use_backbuffer = True )
      container.add( plot )
      container.add( colorbar )
      
      return container
Example #40
0
    def _reconstruction_default(self):
        rows, cols = self.image.shape[:2]
        self.plot_data = ArrayPlotData(original=self.image[0],
                                       reconstruction=self.result[0])

        aspect = cols/float(rows)

        old = Plot(self.plot_data)
        old.plot('original', )
        old.title = 'Old'

        self.new = Plot(self.plot_data)
        self.new.plot('reconstruction')
        self.new.title = 'New'

        container = HPlotContainer(bgcolor='none')
        container.add(old)
        container.add(self.new)

        return container
Example #41
0
    def _plot_default(self):
        x = linspace(-14, 14, 100)
        y = sin(x) * x**3
        plotdata = ArrayPlotData(x=x, y=y)

        scatter = Plot(plotdata)
        scatter.plot(("x", "y"), type="scatter", color="blue")

        line = Plot(plotdata)
        line.plot(("x", "y"), type="line", color="blue")

        container = HPlotContainer(scatter, line)
        container.spacing = 0

        scatter.padding_right = 0

        line.padding_left = 0
        line.y_axis_orientation = "right"

        return container
Example #42
0
def _create_plot_component():
    numpoints = 100
    low = -5
    high = 15.0
    x = arange(low, high, (high-low)/numpoints)

    container = HPlotContainer(resizable = "hv", bgcolor="lightgray",
                               fill_padding=True, padding = 10)
    # container = VPlotContainer(resizable = "hv", bgcolor="lightgray",
    #                            fill_padding=True, padding = 10)


    # Plot some bessel functions
    value_range = None
    for i in range(10):
        y = jn(i, x)
        plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[i]), width=2.0,
                                orientation="v")
                               # orientation="h")
        plot.origin_axis_visible = True
        plot.origin = "top left"
        plot.padding_left = 10
        plot.padding_right = 10
        plot.border_visible = True
        plot.bgcolor = "white"
        if value_range is None:
            value_range = plot.value_mapper.range
        else:
            plot.value_range = value_range
            value_range.add(plot.value)
        if i%2 == 1:
            plot.line_style = "dash"
        container.add(plot)

    container.padding_top = 50
    container.overlays.append(PlotLabel("More Bessels",
                                        component=container,
                                        font = "swiss 16",
                                        overlay_position = "top"))

    return container
Example #43
0
    def set_image(self, buf):
        '''
            buf is a file-like object
        '''
        self.container = HPlotContainer()
        pd = ArrayPlotData(x=[0, 640], y=[0, 480])
        padding = [30, 5, 5, 30]
        plot = Plot(
            data=pd,
            padding=padding,
            #                    default_origin=''
        )
        self.plot = plot.plot(('x', 'y'), )[0]
        self.plot.index.sort_order = 'ascending'
        imo = ImageUnderlay(self.plot, padding=padding, path=buf)
        self.plot.overlays.append(imo)

        self._add_tools(self.plot)

        self.container.add(plot)
        self.container.request_redraw()
Example #44
0
    def _resplotter_default(self):
        res = np.zeros((400, 400))
        self.pd = ArrayPlotData(res=res)
        p = Plot(self.pd)
        img = p.img_plot('res', name="my_plot")
        my_plot = p.plots["my_plot"][0]
        colormap = my_plot.color_mapper
        colorbar = ColorBar(
            index_mapper=dc.LinearMapper(range=colormap.range),
            color_mapper=colormap,
            orientation='v',
            plot=my_plot,
            resizable='v',
            width=30,
            padding=20)

        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"))
        range_selection.listeners.append(my_plot)
        con = HPlotContainer()
        con.add(p)
        con.add(colorbar)
        return con
    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
Example #46
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
Example #47
0
    def _container_default(self):
        x = arange(-5.0, 15.0, 20.0 / 100)

        y = jn(0, x)
        left_plot = create_line_plot((x, y),
                                     bgcolor="white",
                                     add_grid=True,
                                     add_axis=True)
        left_plot.tools.append(PanTool(left_plot))
        self.left_plot = left_plot

        y = jn(1, x)
        right_plot = create_line_plot((x, y),
                                      bgcolor="white",
                                      add_grid=True,
                                      add_axis=True)
        right_plot.tools.append(PanTool(right_plot))
        right_plot.y_axis.orientation = "right"
        self.right_plot = right_plot

        # Tone down the colors on the grids
        right_plot.hgrid.line_color = (0.3, 0.3, 0.3, 0.5)
        right_plot.vgrid.line_color = (0.3, 0.3, 0.3, 0.5)
        left_plot.hgrid.line_color = (0.3, 0.3, 0.3, 0.5)
        left_plot.vgrid.line_color = (0.3, 0.3, 0.3, 0.5)

        container = HPlotContainer(spacing=20, padding=50, bgcolor="lightgray")
        container.add(left_plot)
        container.add(right_plot)
        return container
Example #48
0
class ImageViewer(HasTraits):
    container = Instance(HPlotContainer, ())
    plot = Any

    def load_image(self, path):
        if os.path.isfile(path):
            with open(path, 'r') as rfile:
                self.set_image(rfile)

    def set_image(self, buf):
        '''
            buf is a file-like object
        '''
        self.container = HPlotContainer()
        pd = ArrayPlotData(x=[0, 640],
                           y=[0, 480])
        padding = [30, 5, 5, 30]
        plot = Plot(data=pd, padding=padding,
#                    default_origin=''
                    )
        self.plot = plot.plot(('x', 'y'),)[0]
        self.plot.index.sort_order = 'ascending'
        imo = ImageUnderlay(self.plot,
                            padding=padding,
                            path=buf)
        self.plot.overlays.append(imo)

        self._add_tools(self.plot)

        self.container.add(plot)
        self.container.request_redraw()

    def _add_tools(self, plot):
        inspector = XYInspector(plot)
        plot.tools.append(inspector)
        plot.overlays.append(XYInspectorOverlay(inspector=inspector,
                                                component=plot,
                                                align='ul',
                                                bgcolor=0xFFFFD2
                                                ))
Example #49
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 _create_plot_component():

    # Create some x-y data series to plot
    plot_area = OverlayPlotContainer(border_visible=True)
    container = HPlotContainer(padding=50, bgcolor="transparent")
    #container.spacing = 15

    x = linspace(-2.0, 10.0, 100)
    for i in range(5):
        color = tuple(COLOR_PALETTE[i])
        y = jn(i, x)
        renderer = create_line_plot((x, y), color=color)
        plot_area.add(renderer)
        #plot_area.padding_left = 20

        axis = PlotAxis(
            orientation="left",
            resizable="v",
            mapper=renderer.y_mapper,
            axis_line_color=color,
            tick_color=color,
            tick_label_color=color,
            title_color=color,
            bgcolor="transparent",
            title="jn_%d" % i,
            border_visible=True,
        )
        axis.bounds = [60, 0]
        axis.padding_left = 10
        axis.padding_right = 10

        container.add(axis)

        if i == 4:
            # Use the last plot's X mapper to create an X axis and a
            # vertical grid
            x_axis = PlotAxis(orientation="bottom",
                              component=renderer,
                              mapper=renderer.x_mapper)
            renderer.overlays.append(x_axis)
            grid = PlotGrid(mapper=renderer.x_mapper,
                            orientation="vertical",
                            line_color="lightgray",
                            line_style="dot")
            renderer.underlays.append(grid)

    # Add the plot_area to the horizontal container
    container.add(plot_area)

    # Attach some tools to the plot
    broadcaster = BroadcasterTool()
    for plot in plot_area.components:
        broadcaster.tools.append(PanTool(plot))

    # Attach the broadcaster to one of the plots.  The choice of which
    # plot doesn't really matter, as long as one of them has a reference
    # to the tool and will hand events to it.
    plot.tools.append(broadcaster)

    return container
Example #51
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
Example #52
0
class ImageViewer(HasTraits):
    container = Instance(HPlotContainer, ())
    plot = Any

    def load_image(self, path):
        if os.path.isfile(path):
            with open(path, 'r') as fp:
                self.set_image(fp)

    def set_image(self, buf):
        '''
            buf is a file-like object
        '''
        self.container = HPlotContainer()
        pd = ArrayPlotData(x=[0, 640],
                           y=[0, 480])
        padding = [30, 5, 5, 30]
        plot = Plot(data=pd, padding=padding,
#                    default_origin=''
                    )
        self.plot = plot.plot(('x', 'y'),)[0]
        self.plot.index.sort_order = 'ascending'
        imo = ImageUnderlay(self.plot,
                            padding=padding,
                            path=buf)
        self.plot.overlays.append(imo)

        self._add_tools(self.plot)

        self.container.add(plot)
        self.container.request_redraw()

    def _add_tools(self, plot):
        inspector = XYInspector(plot)
        plot.tools.append(inspector)
        plot.overlays.append(XYInspectorOverlay(inspector=inspector,
                                                component=plot,
                                                align='ul',
                                                bgcolor=0xFFFFD2
                                                ))
  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 __init__(self):
        super(ContainerExample, self).__init__()

        x = linspace(-14, 14, 100)
        y = sin(x) * x ** 3
        plotdata = ArrayPlotData(x=x, y=y)

        scatter = Plot(plotdata)
        scatter.plot(("x", "y"), type="scatter", color="blue")

        line = Plot(plotdata)
        line.plot(("x", "y"), type="line", color="blue")

        container = HPlotContainer(scatter, line)

        #Making the plots touch in the middle
        container.spacing = 0
        scatter.padding_right = 0
        line.padding_left = 0
        line.y_axis.orientation = "right"

        self.plot = container
Example #55
0
    def _reconstruction_default(self):
        self.plot_data = ArrayPlotData(original=self.image,
                                       reconstruction=self.result)

        rows, cols = self.image.shape[:2]
        aspect = cols/float(rows)

        old = Plot(self.plot_data)
        old.img_plot('original', colormap=gray, origin='top left')
        old.title = 'Old'
        old.aspect_ratio = aspect

        self.new = Plot(self.plot_data)
        self.new.img_plot('reconstruction', colormap=gray, origin='top left')
        self.new.title = 'New'
        self.new.aspect_ratio = aspect

        container = HPlotContainer(bgcolor='none')
        container.add(old)
        container.add(self.new)

        return container
Example #56
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
Example #57
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