Beispiel #1
0
		def __init__(self,data_q,num):
			super(PlotterWindow,self).__init__()

			self.data_q = data_q

			self.x = ArrayDataSource(zeros(num))
			self.y = ArrayDataSource(zeros(num))
			self.v = MultiArrayDataSource(zeros((num,2)))

			xrange = DataRange1D()
			xrange.add(self.x)
			yrange = DataRange1D()
			yrange.add(self.y)

			quiverplot = QuiverPlot(index=self.x,value=self.y,vectors=self.v,
				index_mapper=LinearMapper(range=xrange),
				value_mapper=LinearMapper(range=yrange),
				bgcolor='white')
			add_default_axes(quiverplot)
			add_default_grids(quiverplot)

			quiverplot.tools.append(PanTool(quiverplot,constrain_key='shift'))
			quiverplot.overlays.append(ZoomTool(quiverplot))

			self.plot = OverlayPlotContainer(quiverplot, padding=50)
			self.timer = Timer(50.0, self.onTimer)

			self.configure_traits()
Beispiel #2
0
def _create_plot_component():
    # Create some data
    numpts = 400
    x = sort(random(numpts))
    y = random(numpts)
    xs = ArrayDataSource(x, sort_order='ascending')
    ys = ArrayDataSource(y)
    vectorlen = 15
    vectors = array((random(numpts) * vectorlen, random(numpts) * vectorlen)).T
    vector_ds = MultiArrayDataSource(vectors)
    xrange = DataRange1D()
    xrange.add(xs)
    yrange = DataRange1D()
    yrange.add(ys)
    quiverplot = QuiverPlot(index=xs,
                            value=ys,
                            vectors=vector_ds,
                            index_mapper=LinearMapper(range=xrange),
                            value_mapper=LinearMapper(range=yrange),
                            bgcolor="white")
    add_default_axes(quiverplot)
    add_default_grids(quiverplot)
    # Attach some tools to the plot
    quiverplot.tools.append(PanTool(quiverplot, constrain_key="shift"))
    zoom = ZoomTool(quiverplot)
    quiverplot.overlays.append(zoom)
    container = OverlayPlotContainer(quiverplot, padding=50)

    return container
def _create_plot_component():
    # Create some data
    numpts = 400
    x = sort(random(numpts))
    y = random(numpts)
    xs = ArrayDataSource(x, sort_order='ascending')
    ys = ArrayDataSource(y)
    vectorlen = 15
    vectors = array((random(numpts)*vectorlen,random(numpts)*vectorlen)).T
    vector_ds = MultiArrayDataSource(vectors)
    xrange = DataRange1D()
    xrange.add(xs)
    yrange = DataRange1D()
    yrange.add(ys)
    quiverplot = QuiverPlot(index = xs, value = ys,
                    vectors = vector_ds,
                    index_mapper = LinearMapper(range=xrange),
                    value_mapper = LinearMapper(range=yrange),
                    bgcolor = "white")
    add_default_axes(quiverplot)
    add_default_grids(quiverplot)
    # Attach some tools to the plot
    quiverplot.tools.append(PanTool(quiverplot, constrain_key="shift"))
    zoom = ZoomTool(quiverplot)
    quiverplot.overlays.append(zoom)
    container = OverlayPlotContainer(quiverplot, padding=50)
   
    return container
Beispiel #4
0
def _create_plot_component():

    container = OverlayPlotContainer(padding = 50, fill_padding = True,
                                     bgcolor = "lightgray", use_backbuffer=True)

    # Create the initial X-series of data
    numpoints = 100
    low = -5
    high = 15.0
    x = arange(low, high+0.001, (high-low)/numpoints)

    # Plot some bessel functions
    plots = {}
    broadcaster = BroadcasterTool()
    for i in range(4):
        y = jn(i, x)
        plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[i]), width=2.0)
        plot.index.sort_order = "ascending"
        plot.bgcolor = "white"
        plot.border_visible = True
        if i == 0:
            add_default_grids(plot)
            add_default_axes(plot)

        # Create a pan tool and give it a reference to the plot it should
        # manipulate, but don't attach it to the plot.  Instead, attach it to
        # the broadcaster.
        pan = PanTool(plot)
        broadcaster.tools.append(pan)

        container.add(plot)
        plots["Bessel j_%d"%i] = plot

    # Add an axis on the right-hand side that corresponds to the second plot.
    # Note that it uses plot.value_mapper instead of plot0.value_mapper.
    plot1 = plots["Bessel j_1"]
    axis = PlotAxis(plot1, orientation="right")
    plot1.underlays.append(axis)

    # Add the broadcast tool to the container, instead of to an
    # individual plot
    container.tools.append(broadcaster)

    legend = Legend(component=container, padding=10, align="ur")
    legend.tools.append(LegendTool(legend, drag_button="right"))
    container.overlays.append(legend)

    # Set the list of plots on the legend
    legend.plots = plots

    # Add the title at the top
    container.overlays.append(PlotLabel("Bessel functions",
                              component=container,
                              font = "swiss 16",
                              overlay_position="top"))

    # Add the traits inspector tool to the container
    container.tools.append(TraitsTool(container))

    return container
Beispiel #5
0
    def _setup_plot_tools(self, plot):
        """Sets up the background, and several tools on a plot"""
        # Make a white background with grids and axes
        plot.bgcolor = "white"
        add_default_grids(plot)
        add_default_axes(plot)

        # Allow white space around plot
        plot.index_range.tight_bounds = False
        plot.index_range.refresh()
        plot.value_range.tight_bounds = False
        plot.value_range.refresh()

        # The PanTool allows panning around the plot
        plot.tools.append(PanTool(plot))

        # The ZoomTool tool is stateful and allows drawing a zoom
        # box to select a zoom region.
        zoom = ZoomTool(plot, tool_mode="box", always_on=False)
        plot.overlays.append(zoom)

        # The DragZoom tool just zooms in and out as the user drags
        # the mouse vertically.
        dragzoom = DragZoom(plot, drag_button="right")
        plot.tools.append(dragzoom)

        # Add a legend in the upper right corner, and make it relocatable
        legend = Legend(component=plot, padding=10, align="ur")
        legend.tools.append(LegendTool(legend, drag_button="right"))
        plot.overlays.append(legend)

        return plot.value_mapper, plot.index_mapper, legend
Beispiel #6
0
    def _setup_plot_tools(self, plot):
        """Sets up the background, and several tools on a plot"""
        # Make a white background with grids and axes
        plot.bgcolor = "white"
        add_default_grids(plot)
        add_default_axes(plot)

        # Allow white space around plot
        plot.index_range.tight_bounds = False
        plot.index_range.refresh()
        plot.value_range.tight_bounds = False
        plot.value_range.refresh()

        # The PanTool allows panning around the plot
        plot.tools.append(PanTool(plot))

        # The ZoomTool tool is stateful and allows drawing a zoom
        # box to select a zoom region.
        zoom = ZoomTool(plot, tool_mode="box", always_on=False)
        plot.overlays.append(zoom)

        # The DragZoom tool just zooms in and out as the user drags
        # the mouse vertically.
        dragzoom = DragZoom(plot, drag_button="right")
        plot.tools.append(dragzoom)

        # Add a legend in the upper right corner, and make it relocatable
        legend = Legend(component=plot, padding=10, align="ur")
        legend.tools.append(LegendTool(legend, drag_button="right"))
        plot.overlays.append(legend)

        return plot.value_mapper, plot.index_mapper, legend
Beispiel #7
0
def _create_plot_component(title, initial_values=None, on_change_functor=None):

    #return OverlayPlotContainer()


    container = OverlayPlotContainer(padding = 25, fill_padding = True,
                                     bgcolor = "lightgray", use_backbuffer=True)

    if initial_values:
        x = initial_values[0]
        y = initial_values[1]
    else:
        # Create the initial X-series of data
        numpoints = 30
        low = -5
        high = 15.0
        x = linspace(low, high, numpoints)
        y = jn(0, x)

    lineplot = create_line_plot((x, y), color=tuple(COLOR_PALETTE[0]), width=2.0)
    lineplot.selected_color = "none"

    scatter = ScatterPlot(index = lineplot.index,
                       value = lineplot.value,
                       index_mapper = lineplot.index_mapper,
                       value_mapper = lineplot.value_mapper,
                       color = tuple(COLOR_PALETTE[0]),
                       marker_size = 2)
    scatter.index.sort_order = "ascending"
    scatter.bgcolor = "white"
    scatter.border_visible = True

    add_default_grids(scatter)
    add_default_axes(scatter)
    scatter.tools.append(PanTool(scatter, drag_button="right"))

    # The ZoomTool tool is stateful and allows drawing a zoom
    # box to select a zoom region.
    zoom = ZoomTool(scatter, tool_mode="box", always_on=False, drag_button=None)
    scatter.overlays.append(zoom)

    point_dragging_tool = PointDraggingTool(scatter)
    point_dragging_tool.on_change_functor = on_change_functor
    scatter.tools.append(point_dragging_tool)


    container.add(lineplot)
    container.add(scatter)
    # Add the title at the top
    container.overlays.append(PlotLabel(title,
                              component=container,
                              font = "swiss 16",
                              overlay_position="top"))

    #container.mx = lineplot.index.get_data()
    #container.my = lineplot.value.get_data()
    container.lineplot = lineplot
    return container
Beispiel #8
0
    def _plot_default(self):

        container = OverlayPlotContainer(padding = 50, fill_padding = True,
                                         bgcolor = "lightgray", use_backbuffer=True)

        # Create the initial X-series of data
        numpoints = self.numpoints
        low = self.low
        high = self.high
        x = arange(low, high+0.001, (high-low)/numpoints)
        y = jn(0, x)
        plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[0]), width=2.0)
        plot.index.sort_order = "ascending"
        plot.bgcolor = "white"
        plot.border_visible = True
        add_default_grids(plot)
        add_default_axes(plot)

        # Add some tools
        plot.tools.append(PanTool(plot))
        zoom = ZoomTool(plot, tool_mode="box", always_on=False)
        plot.overlays.append(zoom)

        # Add a dynamic label.  This can be dragged and moved around using the
        # right mouse button.  Note the use of padding to offset the label
        # from its data point.
        label = DataLabel(component=plot, data_point=(x[40], y[40]),
                          label_position="top left", padding=40,
                          bgcolor = "lightgray",
                          border_visible=False)
        plot.overlays.append(label)
        tool = DataLabelTool(label, drag_button="right", auto_arrow_root=True)
        label.tools.append(tool)

        # Add some static labels.
        label2 = DataLabel(component=plot, data_point=(x[20], y[20]),
                           label_position="bottom right",
                           border_visible=False,
                           bgcolor="transparent",
                           marker_color="blue",
                           marker_line_color="transparent",
                           marker = "diamond",
                           arrow_visible=False)
        plot.overlays.append(label2)

        label3 = DataLabel(component=plot, data_point=(x[80], y[80]),
                           label_position="top", padding_bottom=20,
                           marker_color="transparent",
                           marker_size=8,
                           marker="circle",
                           arrow_visible=False)
        plot.overlays.append(label3)
        container.add(plot)

        return container
Beispiel #9
0
def _create_plot_component():

    container = OverlayPlotContainer(padding=50,
                                     fill_padding=True,
                                     bgcolor="lightgray",
                                     use_backbuffer=True)

    # Create the initial X-series of data
    numpoints = 30
    low = -5
    high = 15.0
    x = linspace(low, high, numpoints)
    y = jn(0, x)

    lineplot = create_line_plot((x, y),
                                color=tuple(COLOR_PALETTE[0]),
                                width=2.0)
    lineplot.selected_color = "none"
    scatter = ScatterPlot(index=lineplot.index,
                          value=lineplot.value,
                          index_mapper=lineplot.index_mapper,
                          value_mapper=lineplot.value_mapper,
                          color=tuple(COLOR_PALETTE[0]),
                          marker_size=5)
    scatter.index.sort_order = "ascending"

    scatter.bgcolor = "white"
    scatter.border_visible = True

    add_default_grids(scatter)
    add_default_axes(scatter)

    scatter.tools.append(PanTool(scatter, drag_button="right"))

    # The ZoomTool tool is stateful and allows drawing a zoom
    # box to select a zoom region.
    zoom = ZoomTool(scatter,
                    tool_mode="box",
                    always_on=False,
                    drag_button=None)
    scatter.overlays.append(zoom)

    scatter.tools.append(PointDraggingTool(scatter))

    container.add(lineplot)
    container.add(scatter)

    # Add the title at the top
    container.overlays.append(
        PlotLabel("Line Editor",
                  component=container,
                  font="swiss 16",
                  overlay_position="top"))

    return container
def build_new_plot_context(container_properties):
    """ Build an empty chaco Plot to display data, using provided props.

    Note that this builds an empty Plot or Container. See
    add_chrome_log and remove_chrome_log for adding/removing line plots in it.

    Parameters
    ----------
    container_properties : dict
        Properties to display the
    """
    # create a new empty Plot object and initialize defaults.
    context_props = container_properties['plot_context']
    plot_context = Plot(ArrayPlotData(), **context_props)

    # adding zoom and pan tools to the plot
    zoom = BetterSelectingZoom(component=plot_context, tool_mode="box",
                               always_on=False)
    plot_context.overlays.append(zoom)
    plot_context.tools.append(PanTool(component=plot_context))

    # configure axes
    axes_factory_props = container_properties['axes_factory']
    add_default_axes(plot_context, **axes_factory_props)

    # If necessary, add a secondary axis:
    context_props2 = container_properties.get('plot_context2', None)
    if context_props2:
        plot_context2 = Plot(ArrayPlotData(), **context_props2)

    second_axes_factory_props = container_properties.get('second_axes_factory',
                                                         None)
    if second_axes_factory_props:
        add_sharedx_axes(plot_context2, **second_axes_factory_props)

    # Add a tool to track mouse location
    short_x_axis_title = axes_factory_props['htitle'].split()[0]
    short_y_axis_title = axes_factory_props['vtitle'].split()[0]

    def message_for_data(coords):
        """ Convert a data coordinate into a message for the text overlay
        of the inspector tool.
        """
        msg = "{}: {:.3f}, {}: {:.3f}"
        msg = msg.format(short_x_axis_title, coords[0],
                         short_y_axis_title, coords[1])
        return msg

    add_mouse_position_tool(plot_context, message_for_data=message_for_data,
                            include_overlay=True)
    return plot_context
Beispiel #11
0
    def _refresh_container(self):
        ''' rebuild the container for the current data
        '''
        broadcaster = BroadcasterTool()

        mfn_line = self.value
        #   print self.panel.GetSize()
        adapter = self.adapter
        if adapter.var_x != '':
            # Get the x-label text from the object's trait var_x
            label_x = getattr(self.object, adapter.var_x)
        else:
            # Get the x-label from the adapter
            label_x = adapter.label_x

        if adapter.var_y != '':
            label_y = getattr(self.object, adapter.var_y)
        else:
            label_y = adapter.label_y

        index = ArrayDataSource(mfn_line.xdata)
        y = ArrayDataSource(mfn_line.ydata, sort_order="none")

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

        value_range = DataRange1D(low_setting=0.0)
        value_range.add(y)
        value_mapper = LinearMapper(range=value_range)

        styles_m = list(adapter.line_style.values())
        line_style = styles_m[0]
        line_color = adapter.line_color[0]

        line_plot = self.lplot = LinePlot(index=index,
                                          value=y,
                                          index_mapper=index_mapper,
                                          value_mapper=value_mapper,
                                          color=line_color,
                                          width=25,
                                          edge_color='blue',
                                          linestyle=line_style,
                                          border_visible=False)

        add_default_grids(line_plot)
        add_default_axes(line_plot, vtitle="Y", htitle="X")

        self.plot_container.add(line_plot)
        line_plot.tools.append(PanTool(line_plot))
        line_plot.overlays.append(ZoomTool(line_plot))
Beispiel #12
0
def _create_plot_component_overlay(signals, use_downsampling=False):

    container = OverlayPlotContainer(padding=40,
                                     bgcolor="lightgray",
                                     use_backbuffer=True,
                                     border_visible=True,
                                     fill_padding=True)

    nSignal, nSample = np.shape(signals)
    time = arange(nSample)

    value_mapper = None
    index_mapper = None
    plots = {}
    for i in range(nSignal):

        plot = create_line_plot(
            (time, signals[i]),
            color=tuple(COLOR_PALETTE[i % len(COLOR_PALETTE)]),
            width=2.0)
        plot.use_downsampling = use_downsampling

        if value_mapper is None:
            index_mapper = plot.index_mapper
            value_mapper = plot.value_mapper
            add_default_grids(plot)
            add_default_axes(plot)
        else:
            plot.value_mapper = value_mapper
            value_mapper.range.add(plot.value)
            plot.index_mapper = index_mapper
            index_mapper.range.add(plot.index)
        if i % 2 == 1:
            plot.line_style = "dash"
        plot.bgcolor = "white"
        plots["Corr fun %d" % i] = plot
        container.add(plot)

    # Add a legend in the upper right corner, and make it relocatable
    #    legend = Legend(component=plot, padding=10, align="ur")
    #    legend.tools.append(LegendTool(legend, drag_button="right"))
    #    plot.overlays.append(legend)
    #    legend.plots = plots
    #    selection_overlay = RangeSelectionOverlay(component=plot)
    #    plot.tools.append(RangeSelection(plot))
    zoom = ZoomTool(plot, tool_mode="box", always_on=False)
    # plot.overlays.append(selection_overlay)
    plot.overlays.append(zoom)

    return container
Beispiel #13
0
    def _refresh_container(self):
        ''' rebuild the container for the current data
        '''
        broadcaster = BroadcasterTool()

        mfn_line = self.value
     #   print self.panel.GetSize()
        adapter = self.adapter
        if adapter.var_x != '':
            # Get the x-label text from the object's trait var_x
            label_x = getattr(self.object, adapter.var_x)
        else:
            # Get the x-label from the adapter
            label_x = adapter.label_x

        if adapter.var_y != '':
            label_y = getattr(self.object, adapter.var_y)
        else:
            label_y = adapter.label_y

        index = ArrayDataSource(mfn_line.xdata)
        y = ArrayDataSource(mfn_line.ydata, sort_order="none")

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

        value_range = DataRange1D(low_setting=0.0)
        value_range.add(y)
        value_mapper = LinearMapper(range=value_range)

        styles_m = adapter.line_style.values()
        line_style = styles_m[0]
        line_color = adapter.line_color[0]

        line_plot = self.lplot = LinePlot(index=index, value=y,
                                          index_mapper=index_mapper,
                                          value_mapper=value_mapper,
                                          color=line_color,
                                          width=25,
                                          edge_color='blue',
                                          linestyle=line_style,
                                          border_visible=False)

        add_default_grids(line_plot)
        add_default_axes(line_plot, vtitle="Y", htitle="X")

        self.plot_container.add(line_plot)
        line_plot.tools.append(PanTool(line_plot))
        line_plot.overlays.append(ZoomTool(line_plot))
Beispiel #14
0
def _create_plot_component_overlay(signals, use_downsampling=False):

    container = OverlayPlotContainer(padding=40, bgcolor="lightgray",
                                     use_backbuffer=True,
                                     border_visible=True,
                                     fill_padding=True)

    nSignal, nSample = np.shape(signals)
    time = arange(nSample)

    value_mapper = None
    index_mapper = None
    plots = {}
    for i in range(nSignal):

        plot = create_line_plot((time, signals[i]),
                        color=tuple(COLOR_PALETTE[i % len(COLOR_PALETTE)]),
                        width=2.0)
        plot.use_downsampling = use_downsampling

        if value_mapper is None:
            index_mapper = plot.index_mapper
            value_mapper = plot.value_mapper
            add_default_grids(plot)
            add_default_axes(plot)
        else:
            plot.value_mapper = value_mapper
            value_mapper.range.add(plot.value)
            plot.index_mapper = index_mapper
            index_mapper.range.add(plot.index)
        if i % 2 == 1:
            plot.line_style = "dash"
        plot.bgcolor = "white"
        plots["Corr fun %d" % i] = plot
        container.add(plot)

    # Add a legend in the upper right corner, and make it relocatable
    #    legend = Legend(component=plot, padding=10, align="ur")
    #    legend.tools.append(LegendTool(legend, drag_button="right"))
    #    plot.overlays.append(legend)
    #    legend.plots = plots
    #    selection_overlay = RangeSelectionOverlay(component=plot)
    #    plot.tools.append(RangeSelection(plot))
    zoom = ZoomTool(plot, tool_mode="box", always_on=False)
    # plot.overlays.append(selection_overlay)
    plot.overlays.append(zoom)

    return container
Beispiel #15
0
    def _create_window(self):
        self._create_data()
        x = self.x_values[:self.current_index]
        y = self.y_values[:self.current_index]

        value_range = None
        index_range = None
        plot = create_line_plot((x, y), color="red", width=2.0)
        value_range = plot.value_mapper.range
        index_range = plot.index_mapper.range
        index_range.low = -5
        index_range.high = 15
        plot.padding = 50
        plot.fill_padding = True
        plot.bgcolor = "white"
        left, bottom = add_default_axes(plot)
        hgrid, vgrid = add_default_grids(plot)
        bottom.tick_interval = 2.0
        vgrid.grid_interval = 2.0

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

        # Set the timer to generate events to us
        timerId = wx.NewId()
        self.timer = wx.Timer(self, timerId)
        self.Bind(wx.EVT_TIMER, self.onTimer, id=timerId)
        self.timer.Start(50.0, wx.TIMER_CONTINUOUS)
        return Window(self, -1, component=plot)
Beispiel #16
0
    def _create_window(self):
        self._create_data()
        x = self.x_values[:]
        y = self.y_values[:]

        plots = []


        plot = create_line_plot((x,y), color="red", width=2.0)
        plot.padding = 50
        plot.fill_padding = True
        plot.bgcolor = "white"
        left, bottom = add_default_axes(plot)
        hgrid, vgrid = add_default_grids(plot)
        bottom.tick_interval = 2.0
        vgrid.grid_interval = 2.0


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

        self.timer = Timer(50.0, self.onTimer)
        return Window(self, -1, component=plot)
Beispiel #17
0
    def _create_window(self):
        self._create_data()
        x = self.x_values[:self.current_index]
        y = self.y_values[:self.current_index]

        value_range = None
        index_range = None
        plot = create_line_plot((x,y), color="red", width=2.0)
        value_range = plot.value_mapper.range
        index_range = plot.index_mapper.range
        index_range.low = -5
        index_range.high = 15
        plot.padding = 50
        plot.fill_padding = True
        plot.bgcolor = "white"
        left, bottom = add_default_axes(plot)
        hgrid, vgrid = add_default_grids(plot)
        bottom.tick_interval = 2.0
        vgrid.grid_interval = 2.0


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

        # Set the timer to generate events to us
        timerId = wx.NewId()
        self.timer = wx.Timer(self, timerId)
        self.Bind(wx.EVT_TIMER, self.onTimer, id=timerId)
        self.timer.Start(50.0, wx.TIMER_CONTINUOUS)
        return Window(self, -1, component=plot)
Beispiel #18
0
def _create_plot_component():

    container = OverlayPlotContainer(padding = 50, fill_padding = True,
                                     bgcolor = "lightgray", use_backbuffer=True)

    # Create the initial X-series of data
    numpoints = 30
    low = -5
    high = 15.0
    x = linspace(low, high, numpoints)
    y = jn(0, x)

    lineplot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[0]), width=2.0)
    lineplot.selected_color = "none"
    scatter = ScatterPlot(index = lineplot.index,
                       value = lineplot.value,
                       index_mapper = lineplot.index_mapper,
                       value_mapper = lineplot.value_mapper,
                       color = tuple(COLOR_PALETTE[0]),
                       marker_size = 5)
    scatter.index.sort_order = "ascending"

    scatter.bgcolor = "white"
    scatter.border_visible = True

    add_default_grids(scatter)
    add_default_axes(scatter)

    scatter.tools.append(PanTool(scatter, drag_button="right"))

    # The ZoomTool tool is stateful and allows drawing a zoom
    # box to select a zoom region.
    zoom = ZoomTool(scatter, tool_mode="box", always_on=False)
    scatter.overlays.append(zoom)

    scatter.tools.append(PointDraggingTool(scatter))

    container.add(lineplot)
    container.add(scatter)

    # Add the title at the top
    container.overlays.append(PlotLabel("Line Editor",
                              component=container,
                              font = "swiss 16",
                              overlay_position="top"))

    return container
Beispiel #19
0
def _create_plot_component(use_downsampling=True):

    container = OverlayPlotContainer(padding=40,
                                     bgcolor="lightgray",
                                     use_backbuffer=True,
                                     border_visible=True,
                                     fill_padding=True)

    numpoints = 100000
    low = -5
    high = 15.0
    x = arange(low, high + 0.001, (high - low) / numpoints)

    # Plot some bessel functionsless ../en
    value_mapper = None
    index_mapper = None
    for i in range(10):
        y = jn(i, x)
        plot = create_line_plot((x, y),
                                color=tuple(COLOR_PALETTE[i]),
                                width=2.0)
        plot.use_downsampling = use_downsampling

        if value_mapper is None:
            index_mapper = plot.index_mapper
            value_mapper = plot.value_mapper
            add_default_grids(plot)
            add_default_axes(plot)
        else:
            plot.value_mapper = value_mapper
            value_mapper.range.add(plot.value)
            plot.index_mapper = index_mapper
            index_mapper.range.add(plot.index)
        if i % 2 == 1:
            plot.line_style = "dash"
        plot.bgcolor = "white"
        container.add(plot)

    selection_overlay = RangeSelectionOverlay(component=plot)
    plot.tools.append(RangeSelection(plot))
    zoom = ZoomTool(plot, tool_mode="box", always_on=False)
    plot.overlays.append(selection_overlay)
    plot.overlays.append(zoom)

    return container
        def __init__(self):
            super(ScatterPlotTraits, self).__init__()

            x = linspace(-14, 14, 100)
            y = sin(x) * x**3
            y2 = 2*y
            plotdata = ArrayPlotData(x = x)
            plotdata.set_data('y',y)
            plotdata.set_data('y2', y2)

            self.plot = Plot1D(plotdata)
            self.plot.x_grid.line_color = 'yellow'
            self.plot.y_grid.line_color = 'yellow'
            # Can be used for
            line = self.plot.plot(("x", "y"), name = 'line', type="line",
                                  color="white")[0]
            self.cursor_bar = CursorBar1D(self.plot)
            add_default_axes(line,vtitle = 'toto', htitle = 'hh')
def _create_plot_component():

    numpoints = 100
    low = -5
    high = 15.001
    x = arange(low, high, (high-low)/numpoints)

    # Plot a bessel function
    y = jn(0, x)
    plot = create_line_plot((x,y), color=(0,0,1,1), width=2.0, index_sort="ascending")
    value_range = plot.value_mapper.range
    plot.active_tool = RangeSelection(plot, left_button_selects = True)
    plot.overlays.append(RangeSelectionOverlay(component=plot))
    plot.bgcolor = "white"
    plot.padding = 50
    add_default_grids(plot)
    add_default_axes(plot)

    return plot
Beispiel #22
0
def _create_plot_component(use_downsampling=False):

    container = OverlayPlotContainer(padding=40, bgcolor="lightgray",
                                     use_backbuffer = True,
                                     border_visible = True,
                                     fill_padding = True)

    numpoints = 100000
    low = -5
    high = 15.0
    x = arange(low, high+0.001, (high-low)/numpoints)

    # Plot some bessel functionsless ../en
    value_mapper = None
    index_mapper = None
    for i in range(1):
        y = jn(i, x)
        plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[i]), width=2.0)
        plot.use_downsampling = use_downsampling

        if value_mapper is None:
            index_mapper = plot.index_mapper
            value_mapper = plot.value_mapper
            add_default_grids(plot)
            add_default_axes(plot)
        else:
            plot.value_mapper = value_mapper
            value_mapper.range.add(plot.value)
            plot.index_mapper = index_mapper
            index_mapper.range.add(plot.index)
        if i%2 == 1:
            plot.line_style = "dash"
        plot.bgcolor = "white"
        container.add(plot)

    selection_overlay = RangeSelectionOverlay(component = plot)
    plot.tools.append(RangeSelection(plot))
    zoom = ZoomTool(plot, tool_mode="box", always_on=False)
    plot.overlays.append(selection_overlay)
    plot.overlays.append(zoom)

    return container
Beispiel #23
0
    def _create_plot_component(self):

        container = OverlayPlotContainer(padding=50,
                                         fill_padding=True,
                                         bgcolor="white",
                                         use_backbuffer=True)
        types = {"line": LinePlot, "scatter": ScatterPlot}

        # Create the initial X-series of data
        if len(self) > 0:  # Only create a plot if we ahve datat
            if self.p_type == "scatter and line":
                lineplot = self._create_plot(p_type=LinePlot)
                #lineplot.selected_color = "none"
                scatter = self._create_plot(p_type=ScatterPlot)
                scatter.bgcolor = "white"
                scatter.index_mapper = lineplot.index_mapper
                scatter.value_mapper = lineplot.value_mapper
                add_default_grids(scatter)
                add_default_axes(scatter)
                container.add(lineplot)
                container.add(scatter)
            else:
                plot = self._create_plot(p_type=types[self.p_type])
                add_default_grids(plot)
                add_default_axes(plot)
                container.add(plot)
                scatter = plot
            scatter.tools.append(PanTool(scatter, drag_button="left"))

            # The ZoomTool tool is stateful and allows drawing a zoom
            # box to select a zoom region.
            zoom = ZoomTool(scatter,
                            tool_mode="box",
                            always_on=True,
                            drag_button="right")
            scatter.overlays.append(zoom)
            csr = CursorTool(scatter, color="black", drag_button="left")
            scatter.overlays.append(csr)

        self.plot = container
        return container
def _create_plot_component():

    numpoints = 100
    low = -5
    high = 15.001
    x = arange(low, high, (high - low) / numpoints)

    # Plot a bessel function
    y = jn(0, x)
    plot = create_line_plot((x, y),
                            color=(0, 0, 1, 1),
                            width=2.0,
                            index_sort="ascending")
    value_range = plot.value_mapper.range
    plot.active_tool = RangeSelection(plot, left_button_selects=True)
    plot.overlays.append(RangeSelectionOverlay(component=plot))
    plot.bgcolor = "white"
    plot.padding = 50
    add_default_grids(plot)
    add_default_axes(plot)

    return plot
Beispiel #25
0
    def _plot_default(self):
        # Create starting points for the vectors.
        numpts = self.numpts
        x = sort(random(numpts))
        y = random(numpts)

        # Create vectors.
        vectorlen = self.vectorlen
        vectors = array((random(numpts)*vectorlen, random(numpts)*vectorlen)).T

        # Create an array data sources to plot all vectors at once
        xs = ArrayDataSource(x, sort_order='ascending')
        ys = ArrayDataSource(y)
        vector_ds = MultiArrayDataSource(vectors)

        # Set up the Plot
        xrange = DataRange1D()
        xrange.add(xs)
        yrange = DataRange1D()
        yrange.add(ys)

        quiverplot = QuiverPlot(index = xs, value = ys,
                        vectors = vector_ds,
                        index_mapper = LinearMapper(range=xrange),
                        value_mapper = LinearMapper(range=yrange),
                        bgcolor = "white")

        add_default_axes(quiverplot)
        add_default_grids(quiverplot)

        # Attach some tools to the plot
        quiverplot.tools.append(PanTool(quiverplot, constrain_key="shift"))
        zoom = ZoomTool(quiverplot)
        quiverplot.overlays.append(zoom)

        container = OverlayPlotContainer(quiverplot, padding=50)

        return container
Beispiel #26
0
  def _plot_default(self):

    data_xy = self.map.xy()

    x_ds = ArrayDataSource(data_xy[:,0] * self.map.scale)
    y_ds = ArrayDataSource(data_xy[:,1] * self.map.scale)
    self.x_ds = x_ds
    self.y_ds = y_ds

    x_dr = DataRange1D(x_ds)
    y_dr = DataRange1D(y_ds)
    x_dr.set_bounds(0, self.map.x_inches)  # auto ranging won't work if a side has no walls
    y_dr.set_bounds(0, self.map.y_inches)

    markersize = max( min(475/self.map.ydim, 500/self.map.xdim), 1 )

    # marker_size needs to be roughly plot.bounds[0] / (xdim*2)
    plot = ScatterPlot(index = x_ds, value = y_ds,
                       index_mapper = LinearMapper(range = x_dr),
                       value_mapper = LinearMapper(range = y_dr),
                       color = "black", bgcolor = "white", 
                       marker = "square", marker_size = markersize)

    plot.aspect_ratio = float(self.xdim) / float(self.ydim)

    pgx = PlotGrid(component = plot, mapper = plot.index_mapper, orientation = 'vertical',
                   grid_interval = 1, line_width = 1.0, line_style = "dot", line_color = "lightgray")
    pgy = PlotGrid(component = plot, mapper = plot.value_mapper, orientation = 'horizontal',
                   grid_interval = 1, line_width = 1.0, line_style = "dot", line_color = "lightgray")
    plot.underlays.append(pgx)
    plot.underlays.append(pgy)
    add_default_axes(plot)

    # this is meaningless until we're actually rendered
    #print plot.bounds

    return plot    
    def _create_plot_component(self):

        container = OverlayPlotContainer(padding = 50, fill_padding = True,
                                         bgcolor = "white", use_backbuffer=True)
        types={"line":LinePlot, "scatter":ScatterPlot}

        # Create the initial X-series of data
        if len(self)>0: # Only create a plot if we ahve datat
            if self.p_type=="scatter and line":
                lineplot = self._create_plot(p_type=LinePlot)
                #lineplot.selected_color = "none"
                scatter=self._create_plot(p_type=ScatterPlot)
                scatter.bgcolor = "white"
                scatter.index_mapper=lineplot.index_mapper
                scatter.value_mapper=lineplot.value_mapper
                add_default_grids(scatter)
                add_default_axes(scatter)
                container.add(lineplot)
                container.add(scatter)
            else:
                plot= self._create_plot(p_type=types[self.p_type])
                add_default_grids(plot)
                add_default_axes(plot)
                container.add(plot)
                scatter=plot
            scatter.tools.append(PanTool(scatter, drag_button="left"))

            # The ZoomTool tool is stateful and allows drawing a zoom
            # box to select a zoom region.
            zoom = ZoomTool(scatter, tool_mode="box", always_on=True, drag_button="right")
            scatter.overlays.append(zoom)
            csr=CursorTool(scatter, color="black", drag_button="left")
            scatter.overlays.append(csr)

        self.plot=container
        return container
	def init_plot(self):
		x = arange(100)
		y = arange(100)
		self.plothandle = create_line_plot((x,y), color="red", width=2.0, 
						index_bounds=(-5,100), value_bounds=(-100,100))
		self.plothandle.padding = 50
		self.plothandle.fill_padding = True
		self.plothandle.bgcolor = "white"
		left, bottom = add_default_axes(self.plothandle, 
							vtitle=self.ytitle, htitle="Time (s)")
		hgrid, vgrid = add_default_grids(self.plothandle)
		bottom.tick_interval = 20.0
		vgrid.grid_interval = 10.0

		return self.plothandle
Beispiel #29
0
    def _create_window(self):
        self._create_data()
        x = self.x_values[:self.current_index]
        y = self.y_values[:self.current_index]

        plot = create_line_plot((x, y), color="red", width=2.0)
        plot.padding = 50
        plot.fill_padding = True
        plot.bgcolor = "white"
        left, bottom = add_default_axes(plot)
        hgrid, vgrid = add_default_grids(plot)
        bottom.tick_interval = 2.0
        vgrid.grid_interval = 2.0

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

        self.timer = Timer(50.0, self.onTimer)
        return Window(self, -1, component=plot)
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)
    plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")

    # Tweak some of the plot properties
    plot1.title = "My First Line Plot"
    plot1.padding = 50
    plot1.padding_top = 75
    plot1.legend.visible = True

    x = linspace(-5, 15.0, 100)
    y = jn(5, x)
    foreign_plot = create_line_plot((x, y),
                                    color=tuple(COLOR_PALETTE[0]),
                                    width=2.0)
    left, bottom = add_default_axes(foreign_plot)
    left.orientation = "right"
    bottom.orientation = "top"
    plot1.add(foreign_plot)

    # Attach some tools to the plot
    broadcaster = BroadcasterTool()
    broadcaster.tools.append(PanTool(plot1))
    broadcaster.tools.append(PanTool(foreign_plot))

    for c in (plot1, foreign_plot):
        zoom = ZoomTool(component=c, tool_mode="box", always_on=False)
        broadcaster.tools.append(zoom)

    plot1.tools.append(broadcaster)

    return plot1
Beispiel #31
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)
    plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")

    # Tweak some of the plot properties
    plot1.title = "My First Line Plot"
    plot1.padding = 50
    plot1.padding_top = 75
    plot1.legend.visible = True

    x = linspace(-5, 15.0, 100)
    y = jn(5, x)
    foreign_plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[0]), width=2.0)
    left, bottom = add_default_axes(foreign_plot)
    left.orientation = "right"
    bottom.orientation = "top"
    plot1.add(foreign_plot)

    # Attach some tools to the plot
    broadcaster = BroadcasterTool()
    broadcaster.tools.append(PanTool(plot1))
    broadcaster.tools.append(PanTool(foreign_plot))

    for c in (plot1, foreign_plot):
        zoom = ZoomTool(component=c, tool_mode="box", always_on=False)
        broadcaster.tools.append(zoom)

    plot1.tools.append(broadcaster)

    return plot1
Beispiel #32
0
    def change_plot(self, indices, x_scale=None, y_scale=None):
        global XY_DATA
        self.plot_indices = indices
        self.container = self.create_container()
        self.high_step = 1  #float(max(self.plot_data[0][:, 0]))
        self.low_step = 0
        self.container.data = capi.ArrayPlotData()
        self.time_data_labels = {}
        if len(indices) == 0:
            return
        self._refresh = 1
        XY_DATA = []
        x_scale, y_scale = self.get_axis_scales(x_scale, y_scale)

        # loop through plot data and plot it
        overlays_plotted = False
        fnams = []
        for d in range(len(self.plot_data)):

            if not self.runs_shown[d]:
                continue

            # The legend entry for each file is one of the following forms:
            #   1) [file basename] VAR
            #   2) [file basename:] VAR variables
            # depending on if variabes were perturbed for this run.
            variables = self.variables[d]
            if len(variables) > 30:
                variables = ", ".join(variables.split(",")[:-1])
            if variables:
                variables = ": {0}".format(variables)

            self.time_data_labels[d] = []
            ti = self.find_time_index()
            mheader = self._mheader()
            xname = mheader[self.x_idx]
            self.y_idx = getidx(mheader, mheader[indices[0]])

            # indices is an integer list containing the columns of the data to
            # be plotted. The indices are wrt to the FIRST file in parsed, not
            # necessarily the same for every file. Here, we loop through the
            # indices, determine the name from the first file's header and
            # find the x and y index in the file of interest
            fnam, header = self.get_info(d)
            if fnam in fnams:
                fnam += "-{0}".format(len(fnams))
            fnams.append(fnam)
            for i, idx in enumerate(indices):
                yname = mheader[idx]

                # get the indices for this file
                xp_idx = getidx(header, xname)
                yp_idx = getidx(header, yname)
                if xp_idx is None or yp_idx is None:
                    continue

                # tjfulle: x and y should always be x and disp, z is the color
                x = self.plot_data[d][:, xp_idx] * x_scale
                y = self.plot_data[d][:, yp_idx] * y_scale
                z = self.plot_data[d][:, yp_idx]
                if self.nfiles() - 1 or self.overlay_plot_data:
                    entry = "({0}) {1}{2}".format(fnam, yname, variables)
                else:
                    entry = "{0} {1}".format(yname, variables)
                self.create_plot(x, y, z, entry)
                XY_DATA.append(
                    Namespace(key=fnam,
                              xname=xname,
                              x=x,
                              yname=yname,
                              y=y,
                              lw=1))

                # create point marker
                xp = self.plot_data[d][ti, xp_idx] * x_scale
                yp = self.plot_data[d][ti, yp_idx] * y_scale
                #self.create_data_label(xp, yp, d, yp_idx)

                if not overlays_plotted:
                    # plot the overlay data
                    overlays_plotted = True
                    ii = i + 1
                    for fnam, head in self.overlay_headers.items():
                        # get the x and y indeces corresponding to what is
                        # being plotted
                        xo_idx = getidx(head, xname)
                        yo_idx = getidx(head, yname)
                        if xo_idx is None or yo_idx is None:
                            continue
                        xo = self.overlay_plot_data[fnam][:, xo_idx] * x_scale
                        zo = self.overlay_plot_data[fnam][:, yo_idx] * y_scale
                        # legend entry
                        entry = "({0}) {1}".format(fnam, head[yo_idx])
                        _i = d + len(self.plot_data) + 3
                        self.create_plot(xo, y, zo, entry)
                        XY_DATA.append(
                            Namespace(key=fnam,
                                      xname=xname,
                                      x=xo,
                                      yname=yname,
                                      y=yo,
                                      lw=3))
                        ii += 1
                        continue

        capi.add_default_grids(self.container)
        capi.add_default_axes(self.container, htitle=mheader[self.x_idx])

        self.container.index_range.tight_bounds = False
        self.container.index_range.refresh()
        self.container.value_range.tight_bounds = False
        self.container.value_range.refresh()

        self.container.tools.append(ctapi.PanTool(self.container))

        zoom = ctapi.ZoomTool(self.container, tool_mode="box", always_on=False)
        self.container.overlays.append(zoom)

        dragzoom = ctapi.DragZoom(self.container, drag_button="right")
        self.container.tools.append(dragzoom)

        self.container.legend.visible = True

        self.container.invalidate_and_redraw()
        return
Beispiel #33
0
    def new_series(self, x=None, y=None, plotid=0, **kw):
        '''
        '''

        plot, scatter, _line = super(ResidualsGraph,
                                     self).new_series(x=x,
                                                      y=y,
                                                      plotid=plotid,
                                                      **kw)
        for underlay in plot.underlays:
            if underlay.orientation == 'bottom':
                underlay.visible = False
                underlay.padding_bottom = 0
        plot.padding_bottom = 0

        x, y, res = self.calc_residuals(plotid=plotid)

        ressplit = self._split_residual(x, res)
        resneg = ArrayDataSource(ressplit[1])
        xneg = ArrayDataSource(ressplit[0])
        respos = ArrayDataSource(ressplit[3])
        xpos = ArrayDataSource(ressplit[2])

        yrange = DataRange1D(ArrayDataSource(res))

        ymapper = LinearMapper(range=yrange)

        container = self._container_factory(type='o',
                                            padding=[50, 15, 0, 30],
                                            height=75,
                                            resizable='h')
        bar = BarPlot(
            index=xneg,
            value=resneg,
            index_mapper=scatter.index_mapper,
            value_mapper=ymapper,
            bar_width=0.2,
            line_color='blue',
            fill_color='blue',
            border_visible=True,
        )

        #        left_axis = PlotAxis(bar, orientation = 'left')
        # bottom_axis=PlotAxis(bar,orientaiton='bottom')

        kw = dict(vtitle='residuals')
        if self.xtitle:
            kw['htitle'] = self.xtitle
        add_default_axes(bar, **kw)
        hgrid = PlotGrid(mapper=ymapper,
                         component=bar,
                         orientation='horizontal',
                         line_color='lightgray',
                         line_style='dot')

        bar.underlays.append(hgrid)
        #        bar.underlays.append(left_axis)
        #        bar.underlays.append(bottom_axis)

        bar2 = BarPlot(
            index=xpos,
            value=respos,
            index_mapper=scatter.index_mapper,
            value_mapper=ymapper,
            bar_width=0.2,
            line_color='green',
            fill_color='green',
            # bgcolor = 'green',
            resizable='hv',
            border_visible=True,
            # padding = [30, 5, 0, 30]
        )
        bar2.overlays.append(GuideOverlay(bar2, value=0, color=(0, 0, 0)))
        bar2.underlays.append(hgrid)
        container.add(bar)
        container.add(bar2)

        # container.add(PlotLabel('foo'))

        self.residual_plots = [bar, bar2]
        self.plotcontainer.add(container)
Beispiel #34
0
    def _create_Container(self):

        #creating dict of plots and the broadcaster
        plots = {}
        broadcaster = BroadcasterTool()

        #=====================first container===========================

        #first plot
        #index = linspace(-2*pi,2*pi,1000)
        plot = create_line_plot((self.timestamp, self.e), color = "black", index_bounds=(self.xmin, self.xmax), value_bounds = (self.ymin, self.ymax))
        plot.bgcolor = "white"
        plot.border_visible = True
        value_mapper = plot.value_mapper
        index_mapper = plot.index_mapper
        add_default_grids(plot)
        add_default_axes(plot)

        self.sync_trait("xmin", index_mapper.range, "_low_value")
        self.sync_trait("xmax", index_mapper.range, "_high_value")
        self.sync_trait("ymin", value_mapper.range, "_low_value")
        self.sync_trait("ymax", value_mapper.range, "_high_value")
        
       
        # range selection
        self.rangeselect = RangeSelection(plot, left_button_selects = False, auto_handle_event = False)
        plot.active_tool = self.rangeselect
        plot.overlays.append(RangeSelectionOverlay(component=plot))
        self.rangeselect.on_trait_change(self.on_selection_changed, "selection")

        #adds plot to the container
        self.container.add(plot)

        # second plot
        index2 = linspace(-5*pi,4*pi,1000)
        plot = create_line_plot((self.timestamp, self.a2), color = "red", index_bounds=(self.xmin, self.xmax), value_bounds = (self.ymin, self.ymax))
        print plot
        plot.value_mapper = value_mapper
        value_mapper.range.add(plot.value)
        plot.index_mapper = index_mapper
        index_mapper.range.add(plot.index)

        # Create a pan tool and give it a reference to the plot
        pan = PanTool(plot, drag_button="left")
        broadcaster.tools.append(pan)

        # allows to zoom
        zoom = ZoomTool(plot, tool_mode="box", always_on = False, visible = True)
        plot.overlays.append(zoom)


        #adds plot to the container
        self.container.add(plot)

        # appends broadcaster to the container
        self.container.tools.append(broadcaster)

        # title of the container
        self.container.overlays.append(PlotLabel("Plotting of the Normalized SkinTemp and CGM Timeseries ", component=self.container, overlay_position = "top"))

        #==============end of first container===========================

        #====================second container===========================

        #first plot2
        
        plot2 = create_line_plot((self.c, self.d), color = "blue", index_bounds=(self.rangeXMin, self.rangeXMax), value_bounds = (self.y3, self.y4))
        plot2.bgcolor = "white"
        plot2.border_visible = True
        #plot2.value_mapper = value_mapper # the plot uses the same index and
        #plot2.index_mapper = index_mapper # value like the plots of container1
        self.sync_trait("rangeXMin", plot2.index_mapper.range, "low", False)
        self.sync_trait("rangeXMax", plot2.index_mapper.range, "high", False)


        plot2.index_mapper.range.low = 0
        plot2.index_mapper.range.high = 10000

        plot2.value_mapper.range.low = 0
        plot2.value_mapper.range.high = 1
    
        value_mapper.range.add(plot2.value)
        index_mapper.range.add(plot2.index)
        add_default_grids(plot2)
        add_default_axes(plot2)

        #adds plot to the container
        self.container2.add(plot2)

        # title of the container
        self.container2.overlays.append(PlotLabel("R-Squared Correlation", component=self.container, overlay_position = "top"))

        index_mapper.on_trait_change(self.on_mapper_updated, "updated")
Beispiel #35
0
    def _plot_default(self):

        container = OverlayPlotContainer(padding=50, fill_padding=True,
                                         bgcolor="lightgray",
                                         use_backbuffer=True)

        # Create the initial X-series of data
        numpoints = self.numpoints
        low = self.low
        high = self.high
        x = linspace(low, high, numpoints + 1)
        y = jn(0, x)
        plot = create_line_plot((x, y), color=tuple(COLOR_PALETTE[0]),
                                width=2.0)
        plot.index.sort_order = "ascending"
        plot.bgcolor = "white"
        plot.border_visible = True
        add_default_grids(plot)
        add_default_axes(plot)

        # Add some tools
        plot.tools.append(PanTool(plot))
        zoom = ZoomTool(plot, tool_mode="box", always_on=False)
        plot.overlays.append(zoom)

        # Add a dynamic label.  This can be dragged and moved around using the
        # right mouse button.  Note the use of padding to offset the label
        # from its data point.
        label = DataLabel(component=plot, data_point=(x[40], y[40]),
                          label_position="top left", padding=40,
                          bgcolor="lightgray",
                          border_visible=False)
        plot.overlays.append(label)
        tool = DataLabelTool(label, drag_button="right", auto_arrow_root=True)
        label.tools.append(tool)

        # Add some static labels.
        label2 = DataLabel(component=plot, data_point=(x[20], y[20]),
                           label_position="bottom right",
                           border_visible=False,
                           bgcolor="transparent",
                           marker_color="blue",
                           marker_line_color="transparent",
                           marker="diamond",
                           font='modern 14',
                           arrow_visible=False)
        plot.overlays.append(label2)

        label3 = DataLabel(component=plot, data_point=(x[80], y[80]),
                           label_position="top", padding_bottom=20,
                           marker_color="transparent",
                           marker_size=8,
                           marker="circle",
                           arrow_visible=False)
        plot.overlays.append(label3)

        # This label uses label_style='bubble'.
        label4 = DataLabel(component=plot, data_point=(x[60], y[60]),
                           border_padding=10,
                           marker_color="red",
                           marker_size=3,
                           label_position=(20, 50),
                           label_style='bubble',
                           label_text="Something interesting",
                           label_format="at x=%(x).2f, y=%(y).2f",
                           font='modern 18',
                           bgcolor=(1, 1, 0.75, 1),
                          )
        plot.overlays.append(label4)
        tool4 = DataLabelTool(label4, drag_button="right",
                              auto_arrow_root=True)
        label4.tools.append(tool4)

        # Another 'bubble' label.  This one sets arrow_min_length=20, so
        # the arrow is not drawn when the label is close to the data point.
        label5 = DataLabel(component=plot, data_point=(x[65], y[65]),
                           border_padding=10,
                           marker_color="green",
                           marker_size=4,
                           show_label_coords=False,
                           label_style='bubble',
                           label_position=(25, 5),
                           label_text="Label with\narrow_min_length=20",
                           border_visible=False,
                           arrow_min_length=20,
                           font='modern 14',
                           bgcolor=(0.75, 0.75, 0.75, 1),
                          )
        plot.overlays.append(label5)
        tool5 = DataLabelTool(label5, drag_button="right",
                              auto_arrow_root=True)
        label5.tools.append(tool5)

        container.add(plot)

        return container
Beispiel #36
0
    def new_series(self, x=None, y=None, plotid=0, **kw):
        '''
        '''

        plot, scatter, _line = super(ResidualsGraph, self).new_series(x=x, y=y, plotid=plotid, **kw)
        for underlay in plot.underlays:
            if underlay.orientation == 'bottom':
                underlay.visible = False
                underlay.padding_bottom = 0
        plot.padding_bottom = 0

        x, y, res = self.calc_residuals(plotid=plotid)

        ressplit = self._split_residual(x, res)
        resneg = ArrayDataSource(ressplit[1])
        xneg = ArrayDataSource(ressplit[0])
        respos = ArrayDataSource(ressplit[3])
        xpos = ArrayDataSource(ressplit[2])

        yrange = DataRange1D(ArrayDataSource(res))

        ymapper = LinearMapper(range=yrange)

        container = self._container_factory(type='o',
                                            padding=[50, 15, 0, 30],
                                            height=75,
                                            resizable='h'
                                            )
        bar = BarPlot(index=xneg,
                    value=resneg,
                    index_mapper=scatter.index_mapper,
                    value_mapper=ymapper,
                    bar_width=0.2,
                    line_color='blue',
                    fill_color='blue',

                    border_visible=True,
                    )

#        left_axis = PlotAxis(bar, orientation = 'left')
        # bottom_axis=PlotAxis(bar,orientaiton='bottom')

        kw = dict(vtitle='residuals')
        if self.xtitle:
            kw['htitle'] = self.xtitle
        add_default_axes(bar, **kw)
        hgrid = PlotGrid(mapper=ymapper,
                       component=bar,
                       orientation='horizontal',
                       line_color='lightgray',
                       line_style='dot')

        bar.underlays.append(hgrid)
#        bar.underlays.append(left_axis)
#        bar.underlays.append(bottom_axis)

        bar2 = BarPlot(index=xpos,
                    value=respos,
                    index_mapper=scatter.index_mapper,
                    value_mapper=ymapper,
                    bar_width=0.2,
                    line_color='green',
                    fill_color='green',
                    # bgcolor = 'green',

                    resizable='hv',
                    border_visible=True,
                    # padding = [30, 5, 0, 30]
                    )
        bar2.overlays.append(GuideOverlay(bar2, value=0, color=(0, 0, 0)))
        bar2.underlays.append(hgrid)
        container.add(bar)
        container.add(bar2)

        # container.add(PlotLabel('foo'))

        self.residual_plots = [bar, bar2]
        self.plotcontainer.add(container)
Beispiel #37
0
    def _plot_default(self):

        container = OverlayPlotContainer(padding=50,
                                         fill_padding=True,
                                         bgcolor="lightgray",
                                         use_backbuffer=True)

        # Create the initial X-series of data
        numpoints = self.numpoints
        low = self.low
        high = self.high
        x = linspace(low, high, numpoints + 1)
        y = jn(0, x)
        plot = create_line_plot((x, y),
                                color=tuple(COLOR_PALETTE[0]),
                                width=2.0)
        plot.index.sort_order = "ascending"
        plot.bgcolor = "white"
        plot.border_visible = True
        add_default_grids(plot)
        add_default_axes(plot)

        # Add some tools
        plot.tools.append(PanTool(plot))
        zoom = ZoomTool(plot, tool_mode="box", always_on=False)
        plot.overlays.append(zoom)

        # Add a dynamic label.  This can be dragged and moved around using the
        # right mouse button.  Note the use of padding to offset the label
        # from its data point.
        label = DataLabel(component=plot,
                          data_point=(x[40], y[40]),
                          label_position="top left",
                          padding=40,
                          bgcolor="lightgray",
                          border_visible=False)
        plot.overlays.append(label)
        tool = DataLabelTool(label, drag_button="right", auto_arrow_root=True)
        label.tools.append(tool)

        # Add some static labels.
        label2 = DataLabel(component=plot,
                           data_point=(x[20], y[20]),
                           label_position="bottom right",
                           border_visible=False,
                           bgcolor="transparent",
                           marker_color="blue",
                           marker_line_color="transparent",
                           marker="diamond",
                           font='modern 14',
                           arrow_visible=False)
        plot.overlays.append(label2)

        label3 = DataLabel(component=plot,
                           data_point=(x[80], y[80]),
                           label_position="top",
                           padding_bottom=20,
                           marker_color="transparent",
                           marker_size=8,
                           marker="circle",
                           arrow_visible=False)
        plot.overlays.append(label3)

        # This label uses label_style='bubble'.
        label4 = DataLabel(
            component=plot,
            data_point=(x[60], y[60]),
            border_padding=10,
            marker_color="red",
            marker_size=3,
            label_position=(20, 50),
            label_style='bubble',
            label_text="Something interesting",
            label_format="at x=%(x).2f, y=%(y).2f",
            font='modern 18',
            bgcolor=(1, 1, 0.75, 1),
        )
        plot.overlays.append(label4)
        tool4 = DataLabelTool(label4,
                              drag_button="right",
                              auto_arrow_root=True)
        label4.tools.append(tool4)

        # Another 'bubble' label.  This one sets arrow_min_length=20, so
        # the arrow is not drawn when the label is close to the data point.
        label5 = DataLabel(
            component=plot,
            data_point=(x[65], y[65]),
            border_padding=10,
            marker_color="green",
            marker_size=4,
            show_label_coords=False,
            label_style='bubble',
            label_position=(25, 5),
            label_text="Label with\narrow_min_length=20",
            border_visible=False,
            arrow_min_length=20,
            font='modern 14',
            bgcolor=(0.75, 0.75, 0.75, 1),
        )
        plot.overlays.append(label5)
        tool5 = DataLabelTool(label5,
                              drag_button="right",
                              auto_arrow_root=True)
        label5.tools.append(tool5)

        container.add(plot)

        return container
Beispiel #38
0
def _create_plot_component():
    container = OverlayPlotContainer(padding = 50, fill_padding = True,
        bgcolor = "lightgray", use_backbuffer=True)

    fprefix = './test_data/CEN184/'

    filename1 = fprefix + 'THL_2012-03-21_18-40-42_000.dat'
    filename2  = fprefix + 'THL_2012-03-21_18-44-42_000.dat'
    fprefix = './test_data/CEN111/'
    filename3 = fprefix + 'THL_2011-07-09_15-02-54_000.dat'
    ioreader = HekaIO(filename3)

    #read a block
    blo = ioreader.read_block(group = 2)

    #protocol stuff
    f = open(filename1)
    head = BundleHeader(f)
    head.load(f)
    bi = head.oBundleItems[2]
    pgf = PGFFile(f,bi)

    value_mapper = None
    index_mapper = None
    plots = {}

    firstplot = True
    for seg in blo.segments:
        #prococol building
        for a_sig in seg.analogsignals:
            x = array(a_sig.times)
            y = array(a_sig)
            ch = int(a_sig.annotations['trSourceChannel'])
            plot = create_line_plot((x,y), width=0.5,color=tuple(COLOR_PALETTE[ch]))
            plot.index.sort_order = "ascending"
            plot.bgcolor = "white"
            plot.border_visible = True

            #code for protocols

            print "###########################"
            st_rec = pgf.tree['children'][a_sig.annotations['pgf_index']]['contents']
            se_rec = pgf.tree['children'][a_sig.annotations['pgf_index']]['children'][0]['children'][1]['contents']
            for key in ['stMark','stDataStartSegment','stDataStartTime']:
                print key+ ' ' +str(st_rec.__dict__[key])
            for key in ['seVoltageIncMode','seDuration','seDurationIncMode','seVoltage',]:
                print key+' '+str(se_rec.__dict__[key])
            for key in ['pgf_index','trTraceCount','trAdcChannel','trSourceChannel','swStimCount']:

                print "%s:%s"%(key,a_sig.annotations[key])
                #se_index = int(seg.annotations['seSeriesCount']) -1
                #sw_index = int(a_sig.annotations['swSweepCount']) -1
                #st_index = int(a_sig.annotations['swStimCount']) -1
            #print pgf.tree['children'][se_index]['children'][st_index]['children'][1]['contents'].seVoltage
            if not firstplot:
                plot.value_mapper = value_mapper
                value_mapper.range.add(plot.value)
                plot.index_mapper = index_mapper
                index_mapper.range.add(plot.index)
            else:
                value_mapper = plot.value_mapper
                index_mapper = plot.index_mapper
                add_default_grids(plot)
                add_default_axes(plot)
                plot.index_range.tight_bounds = False
                plot.index_range.refresh()
                plot.value_range.tight_bounds = False
                plot.value_range.refresh()
                plot.tools.append(PanTool(plot))
                # The ZoomTool tool is stateful and allows drawing a zoom
                # box to select a zoom region.
                zoom = ZoomTool(plot, tool_mode="box", always_on=False)
                plot.overlays.append(zoom)
                # The DragZoom tool just zooms in and out as the user drags
                # the mouse vertically.
                dragzoom = DragZoom(plot, drag_button="right")
                plot.tools.append(dragzoom)
                # Add a legend in the upper right corner, and make it relocatable
                legend = Legend(component=plot, padding=10, align="ur")
                legend.tools.append(LegendTool(legend, drag_button="right"))
                #print a_sig.annotations
                plot.overlays.append(legend)
                firstplot = False
            container.add(plot)
            plots["sweep %s"%a_sig.annotations['trLabel'][:4]] = plot
            # Set the list of plots on the legend
    legend.plots = plots
    # Add the title at the top
    container.overlays.append(PlotLabel(blo.annotations['grLabel'],
        component=container,
        font = "swiss 16",
        overlay_position="top"))
    # Add the traits inspector tool to the container
    container.tools.append(TraitsTool(container))

    return container
Beispiel #39
0
def _create_plot_component():

    container = OverlayPlotContainer(padding=60,
                                     fill_padding=True,
                                     use_backbuffer=True,
                                     border_visible=True)

    # Create the initial X-series of data
    numpoints = 100
    low = -5
    high = 15.0
    x = arange(low, high + 0.001, (high - low) / numpoints)

    # Plot some bessel functions
    plots = {}
    broadcaster = BroadcasterTool()
    for i in range(4):
        y = jn(i, x)
        plot = create_line_plot((x, y),
                                color=tuple(COLOR_PALETTE[i]),
                                width=2.0)
        if i == 0:
            add_default_grids(plot)
            left_axis, _ = add_default_axes(plot)
            left_axis.title = "Bessel j0, j2, j3"
        elif i != 1:
            # Map correctly j2 and j3 on the first plot's axis:
            plot0 = plots["Bessel j_0"]
            plot.index_mapper = plot0.index_mapper
            plot.value_mapper = plot0.value_mapper
            plot0.value_mapper.range.add(plot.value)

        # Create a pan/zoom tool and give it a reference to the plot it should
        # manipulate, but don't attach it to the plot. Instead, attach it to
        # the broadcaster. Do it only for each independent set of axis_mappers:
        if i in [0, 1]:
            pan = PanTool(component=plot)
            broadcaster.tools.append(pan)

            zoom = ZoomTool(component=plot)
            broadcaster.tools.append(zoom)

        container.add(plot)
        plots["Bessel j_%d" % i] = plot

    # Add an axis on the right-hand side that corresponds to the second plot.
    # Note that it uses plot.value_mapper instead of plot0.value_mapper.
    plot1 = plots["Bessel j_1"]
    axis = PlotAxis(plot1, orientation="right")
    plot1.underlays.append(axis)
    axis.title = "Bessel j1"

    # Add the broadcast tool to one of the renderers: adding it to the
    # container instead breaks the box mode of the ZoomTool:
    plot0 = plots["Bessel j_0"]
    plot0.tools.append(broadcaster)

    # Create a legend, with tools to move it around and highlight renderers:
    legend = Legend(component=container, padding=10, align="ur")
    legend.tools.append(LegendTool(legend, drag_button="right"))
    legend.tools.append(LegendHighlighter(legend))
    container.overlays.append(legend)
    # Set the list of plots on the legend
    legend.plots = plots

    # Add the title at the top
    container.overlays.append(
        PlotLabel("Bessel functions",
                  component=container,
                  font="swiss 16",
                  overlay_position="top"))

    # Add the traits inspector tool to the container
    container.tools.append(TraitsTool(container))

    return container
Beispiel #40
0
    def _create_plot(self):

        # count data
        if len(self.df) > 0:
            self.indexes = np.arange(len(self.df.date_time))
            time_ds = ArrayDataSource(self.indexes)
            vol_ds = ArrayDataSource(self.df.volumn.values, sort_order="none")
            xmapper = LinearMapper(range=DataRange1D(time_ds))
            vol_mapper = LinearMapper(range=DataRange1D(vol_ds))

            ####################################################################
            # create volumn plot
            vol_plot = BarPlot(
                index=time_ds,
                value=vol_ds,
                index_mapper=xmapper,
                value_mapper=vol_mapper,
                line_color="transparent",
                fill_color="blue",
                bar_width=0.6,
                antialias=False,
                height=100,
                resizable="h",
                origin="bottom left",
                bgcolor="white",
                border_visible=True,
            )

            vol_plot.padding = 30
            vol_plot.padding_left = 40
            vol_plot.tools.append(PanTool(vol_plot, constrain=True, constrain_direction="x"))
            add_default_grids(vol_plot)
            add_default_axes(vol_plot)

            # print vol_plot.index_mapper.range.high
            # print vol_plot.value_mapper.range.low, vol_plot.value_mapper.range.high
            self.vol_plot = vol_plot
            self.container.add(vol_plot)

            ####################################################################
            ## Create price plot

            sorted_vals = np.vstack((self.df.open, self.df.high, self.df.low, self.df.close))
            sorted_vals.sort(0)
            __bool = self.df.close.values - self.df.open.values
            self.up_boolean = __bool >= 0
            self.down_boolean = np.invert(self.up_boolean)

            pd = ArrayPlotData(
                up_index=self.indexes[self.up_boolean],
                up_min=sorted_vals[0][self.up_boolean],
                up_bar_min=sorted_vals[1][self.up_boolean],
                up_bar_max=sorted_vals[2][self.up_boolean],
                up_max=sorted_vals[3][self.up_boolean],
                down_index=self.indexes[self.down_boolean],
                down_min=sorted_vals[0][self.down_boolean],
                down_bar_min=sorted_vals[1][self.down_boolean],
                down_bar_max=sorted_vals[2][self.down_boolean],
                down_max=sorted_vals[3][self.down_boolean],
                volumn=self.df.volumn.values,
                index=self.indexes,
            )

            price_plot = Plot(pd)

            up_plot = price_plot.candle_plot(
                ("up_index", "up_min", "up_bar_min", "up_bar_max", "up_max"),
                color=color_red,
                bgcolor="azure",
                bar_line_color="black",
                stem_color="black",
                end_cap=False,
            )[0]

            down_plot = price_plot.candle_plot(
                ("down_index", "down_min", "down_bar_min", "down_bar_max", "down_max"),
                color=color_green,
                bar_line_color="black",
                stem_color="black",
                end_cap=False,
            )[0]

            price_plot.fill_padding = True
            price_plot.padding = 30
            price_plot.padding_left = 40

            price_plot.tools.append(ZoomTool(component=price_plot, tool_mode="box", zoom_factor=1.2, always_on=False))
            price_plot.tools.append(PanTool(price_plot, drag_button="left"))
            price_plot.tools.append(XYTool(price_plot, callback=self._update_ohlc))  # get data
            self._add_line_tool(up_plot)
            self._add_line_tool(down_plot)
            price_plot.range2d = self._compute_range2d()

            price_plot.index_mapper = vol_plot.index_mapper  # maper vol_plot and price_plot
            self.price_plot = price_plot

            self.container.add(price_plot)
Beispiel #41
0
def _create_plot_component():
	container = GridContainer(padding=40, fill_padding=True,
		bgcolor="lightgray", use_backbuffer=True,
		shape=(3,3), spacing=(10,10))

	x = arange(100)
	y = arange(100)
	plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-5,90))
	plot.padding = 50
	plot.fill_padding = True
	plot.bgcolor = "white"
	left, bottom = add_default_axes(plot, vtitle="Roll (degrees)", htitle="Time (s)")
	hgrid, vgrid = add_default_grids(plot)
	bottom.tick_interval = 20.0
	vgrid.grid_interval = 10.0
	container.add(plot)
	
	x = arange(100)
	y = arange(100)
	plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-5,90))
	plot.padding = 50
	plot.fill_padding = True
	plot.bgcolor = "white"
	left, bottom = add_default_axes(plot, vtitle="Pitch (degrees)", htitle="Time (s)")
	hgrid, vgrid = add_default_grids(plot)
	bottom.tick_interval = 20.0
	vgrid.grid_interval = 10.0
	container.add(plot)
	
	x = arange(100)
	y = arange(100)
	plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-5,365))
	plot.padding = 50
	plot.fill_padding = True
	plot.bgcolor = "white"
	left, bottom = add_default_axes(plot, vtitle="Yaw (degrees)", htitle="Time (s)")
	hgrid, vgrid = add_default_grids(plot)
	bottom.tick_interval = 20.0
	vgrid.grid_interval = 10.0
	container.add(plot)
	
	x = arange(100)
	y = arange(100)
	plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-100,100))
	plot.padding = 50
	plot.fill_padding = True
	plot.bgcolor = "white"
	left, bottom = add_default_axes(plot, vtitle="Gyro X", htitle="Time (s)")
	hgrid, vgrid = add_default_grids(plot)
	bottom.tick_interval = 20.0
	vgrid.grid_interval = 10.0
	container.add(plot)
	
	x = arange(100)
	y = arange(100)
	plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-100,100))
	plot.padding = 50
	plot.fill_padding = True
	plot.bgcolor = "white"
	left, bottom = add_default_axes(plot, vtitle="Gyro Y", htitle="Time (s)")
	hgrid, vgrid = add_default_grids(plot)
	bottom.tick_interval = 20.0
	vgrid.grid_interval = 10.0
	container.add(plot)
	
	x = arange(100)
	y = arange(100)
	plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-100,100))
	plot.padding = 50
	plot.fill_padding = True
	plot.bgcolor = "white"
	left, bottom = add_default_axes(plot, vtitle="Gyro Z", htitle="Time (s)")
	hgrid, vgrid = add_default_grids(plot)
	bottom.tick_interval = 20.0
	vgrid.grid_interval = 10.0
	container.add(plot)
	
	x = arange(100)
	y = arange(100)
	plot = create_line_plot((x,y), color="red", width=2.0, index_bounds=(-5,100), value_bounds=(-1,35))
	plot.padding = 50
	plot.fill_padding = True
	plot.bgcolor = "white"
	left, bottom = add_default_axes(plot, vtitle="Battery Voltage (V)", htitle="Time (s)")
	hgrid, vgrid = add_default_grids(plot)
	bottom.tick_interval = 20.0
	vgrid.grid_interval = 10.0
	container.add(plot)

	return container
def _create_plot_component():

    container = OverlayPlotContainer(padding=50,
                                     fill_padding=True,
                                     bgcolor="lightgray",
                                     use_backbuffer=True)

    # Create the initial X-series of data
    numpoints = 100
    low = -5
    high = 15.0
    x = arange(low, high + 0.001, (high - low) / numpoints)

    # Plot some bessel functions
    plots = {}
    broadcaster = BroadcasterTool()
    for i in range(4):
        y = jn(i, x)
        plot = create_line_plot((x, y),
                                color=tuple(COLOR_PALETTE[i]),
                                width=2.0)
        plot.index.sort_order = "ascending"
        plot.bgcolor = "white"
        plot.border_visible = True
        if i == 0:
            add_default_grids(plot)
            add_default_axes(plot)

        # Create a pan tool and give it a reference to the plot it should
        # manipulate, but don't attach it to the plot.  Instead, attach it to
        # the broadcaster.
        pan = PanTool(plot)
        broadcaster.tools.append(pan)

        container.add(plot)
        plots["Bessel j_%d" % i] = plot

    # Add an axis on the right-hand side that corresponds to the second plot.
    # Note that it uses plot.value_mapper instead of plot0.value_mapper.
    plot1 = plots["Bessel j_1"]
    axis = PlotAxis(plot1, orientation="right")
    plot1.underlays.append(axis)

    # Add the broadcast tool to the container, instead of to an
    # individual plot
    container.tools.append(broadcaster)

    legend = Legend(component=container, padding=10, align="ur")
    legend.tools.append(LegendTool(legend, drag_button="right"))
    container.overlays.append(legend)

    # Set the list of plots on the legend
    legend.plots = plots

    # Add the title at the top
    container.overlays.append(
        PlotLabel("Bessel functions",
                  component=container,
                  font="swiss 16",
                  overlay_position="top"))

    # Add the traits inspector tool to the container
    container.tools.append(TraitsTool(container))

    return container
Beispiel #43
0
    def _create_plot(self):

        # count data
        if len(self.df) > 0:
            self.indexes = np.arange(len(self.df.date_time))
            time_ds = ArrayDataSource(self.indexes)
            vol_ds = ArrayDataSource(self.df.volumn.values, sort_order="none")
            xmapper = LinearMapper(range=DataRange1D(time_ds))
            vol_mapper = LinearMapper(range=DataRange1D(vol_ds))

            ####################################################################
            # create volumn plot
            vol_plot = BarPlot(index=time_ds, value=vol_ds,
                               index_mapper=xmapper,
                               value_mapper=vol_mapper,
                               line_color="transparent",
                               fill_color="blue",
                               bar_width=0.6,
                               antialias=False,
                               height=100,
                               resizable="h",
                               origin="bottom left",
                               bgcolor="white",
                               border_visible=True
                               )

            vol_plot.padding = 30
            vol_plot.padding_left = 40
            vol_plot.tools.append(
                PanTool(vol_plot, constrain=True, constrain_direction="x"))
            add_default_grids(vol_plot)
            add_default_axes(vol_plot)

            #print vol_plot.index_mapper.range.high
            #print vol_plot.value_mapper.range.low, vol_plot.value_mapper.range.high
            self.vol_plot = vol_plot
            self.container.add(vol_plot)

            ####################################################################
            ## Create price plot

            sorted_vals = np.vstack(
                (self.df.open, self.df.high, self.df.low, self.df.close))
            sorted_vals.sort(0)
            __bool = self.df.close.values - self.df.open.values
            self.up_boolean = __bool >= 0
            self.down_boolean = np.invert(self.up_boolean)

            pd = ArrayPlotData(
                up_index=self.indexes[self.up_boolean],
                up_min=sorted_vals[0][self.up_boolean],
                up_bar_min=sorted_vals[1][self.up_boolean],
                up_bar_max=sorted_vals[2][self.up_boolean],
                up_max=sorted_vals[3][self.up_boolean],
                down_index=self.indexes[self.down_boolean],
                down_min=sorted_vals[0][self.down_boolean],
                down_bar_min=sorted_vals[1][self.down_boolean],
                down_bar_max=sorted_vals[2][self.down_boolean],
                down_max=sorted_vals[3][self.down_boolean],
                volumn=self.df.volumn.values,
                index=self.indexes
            )

            price_plot = Plot(pd)

            up_plot = price_plot.candle_plot(
                ("up_index", "up_min", "up_bar_min", "up_bar_max", "up_max"),
                color=color_red,
                bgcolor="azure",
                bar_line_color="black",
                stem_color="black",
                end_cap=False)[0]

            down_plot = price_plot.candle_plot(
                ("down_index", "down_min", "down_bar_min",
                 "down_bar_max", "down_max"),
                color=color_green,
                bar_line_color="black",
                stem_color="black",
                end_cap=False)[0]

            price_plot.fill_padding = True
            price_plot.padding = 30
            price_plot.padding_left = 40

            price_plot.tools.append(ZoomTool(component=price_plot, tool_mode="box", zoom_factor=1.2, always_on=False))
            price_plot.tools.append(PanTool(price_plot, drag_button="left"))
            price_plot.tools.append(
                XYTool(price_plot, callback=self._update_ohlc))  # get data
            self._add_line_tool(up_plot)
            self._add_line_tool(down_plot)
            price_plot.range2d = self._compute_range2d()

            price_plot.index_mapper = vol_plot.index_mapper  # maper vol_plot and price_plot
            self.price_plot = price_plot

            self.container.add(price_plot)