示例#1
0
    def draw( self ):
        """Draw data."""
        if len(self.fitResults) == 0:
            return

        #if not hasattr( self, 'subplot1' ):
        #    self.subplot1 = self.figure.add_subplot( 211 )
        #    self.subplot2 = self.figure.add_subplot( 212 )

        a, ed = numpy.histogram(self.fitResults['tIndex'], self.Size[0]/2)

        #self.subplot1.cla()
        #self.subplot1.plot(ed[:-1], a, color='b' )
        #self.subplot1.set_xticks([0, ed.max()])
        #self.subplot1.set_yticks([0, a.max()])
        #self.subplot2.cla()
        #self.subplot2.plot(ed[:-1], numpy.cumsum(a), color='g' )
        #self.subplot2.set_xticks([0, ed.max()])
        #self.subplot2.set_yticks([0, a.sum()])

        plot1 = create_line_plot(ed[:,-1], a, color = 'blue', bgcolor="white",
                                add_grid=True, add_axis=True)

        plot2 = create_line_plot(ed[:,-1], numpy.cumsum(a), color = 'green', bgcolor="white",
                                add_grid=True, add_axis=True)
        container = HPlotContainer(spacing=20, padding=50, bgcolor="lightgray")
        container.add(plot1)
        container.add(plot2)
        return container
示例#2
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
示例#3
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
示例#4
0
    def init(self, parent):
        factory = self.factory
        container = OverlayPlotContainer(bgcolor='transparent',
                                         padding=0, spacing=0)

        window = Window(parent, component=container)

        interval = self.high - self.low
        data = ([self.low, self.high], [0.5]*2)
        plot = create_line_plot(data, color='black', bgcolor="sys_window")
        plot.x_mapper.range.low = self.low - interval*0.1
        plot.x_mapper.range.high = self.high + interval*0.1
        plot.y_mapper.range.high = 1.0
        plot.y_mapper.range.low = 0.0

        range_selection = RangeSelection(plot, left_button_selects=True)
        # Do not allow the user to reset the range
        range_selection.event_state = "selected"
        range_selection.deselect = lambda x: None
        range_selection.on_trait_change(self.update_interval, 'selection')

        plot.tools.append(range_selection)
        plot.overlays.append(RangeKnobsOverlay(plot))
        self.plot = plot
        container.add(self.plot)

        # To set the low and high, we're actually going to set the
        # 'selection' metadata on the line plot to the tuple (low,high).
        plot.index.metadata["selections"] = (0, 1.0)

        # Tell the editor what to display
        self.control = window.control
        self.control.SetSize((factory.width, factory.height))
示例#5
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)
示例#6
0
def _create_draggable_plot_component(title, initial_values=None,  on_change_functor=None):

    container = OverlayPlotContainer(padding = 30, 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
示例#7
0
    def _plot_targets_fired(self):
        print 'bla'
        numpoints = 100
        low = -5
        high = 15.0
        x = np.arange(low, high+0.001, (high-low)/numpoints)
        # Plot some bessel functions
        value_mapper = None
        index_mapper = None
        plots = {}
        for i in range(10):
            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:
                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"))
                plot.overlays.append(legend)
            self.LinePlotContainer.add(plot)
            plots["Bessel j_%d"%i] = plot
        # Set the list of plots on the legend
        legend.plots = plots
        # Add the title at the top
        self.LinePlotContainer.overlays.append(PlotLabel("Bessel functions",
                                  component=self.LinePlotContainer,
                                  font = "swiss 16",
                                  overlay_position="top"))
        # Add the traits inspector tool to the container
        self.LinePlotContainer.tools.append(TraitsTool(self.LinePlotContainer))
        self.show_lines=True
        print 'hallo'
示例#8
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)
    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
示例#9
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
示例#10
0
    def _create_complexspectrumplot(self, x, y1, y2):
        amplitudeplot = create_line_plot((x, y1), index_bounds=None, value_bounds=None,
                                         orientation='h', color='green', width=1.0, dash='solid',
                                         value_mapper_class=LinearMapper,
                                         bgcolor='white', border_visible=True,
                                         add_grid=False, add_axis=False, index_sort='ascending')
        add_default_axes(amplitudeplot, orientation='normal', htitle='Frequency [MHz]', vtitle='Amplitude')

        amplitudeplot.tools.append(PanTool(amplitudeplot, drag_button="right"))
        zoom = SimpleZoom(component=amplitudeplot, tool_mode="box", drag_button="left", always_on=True)
        amplitudeplot.overlays.append(zoom)

        phaseplot = create_line_plot((x, y2), index_bounds=None,
                                     value_bounds=None,
                                     orientation='h', color='red',
                                     width=1.0, dash='solid',
                                     value_mapper_class=LinearMapper,
                                     bgcolor='white', border_visible=True,
                                     add_grid=False, add_axis=False,
                                     index_sort='ascending')
        add_default_axes(phaseplot, orientation='normal',
                         htitle='Frequency [MHz]', vtitle='Unwrapped phase')

        #        phaseplot.tools.append(PanTool(phaseplot, drag_button="right"))
        zoom = SimpleZoom(component=phaseplot, tool_mode="box",
                          drag_button="left", always_on=True,
                          #                          enter_zoom_key=KeySpec('z')
        )
        phaseplot.overlays.append(zoom)
        self.rangeselect = RangeSelection(phaseplot, left_button_selects=False)
        self.rangeselect.on_trait_change(self.phase_center, "selection_completed")
        phaseplot.active_tool = self.rangeselect
        phaseplot.overlays.append(RangeSelectionOverlay(component=phaseplot))

        container = VPlotContainer(padding=40, padding_left=60, spacing=40)
        container.add(phaseplot)
        container.add(amplitudeplot)
        self.container = container
示例#11
0
    def _create_spectrumplot(self, x, y):
        spectrumplot = create_line_plot((x, y), index_bounds=None, value_bounds=None,
                                        orientation='v', color='green', width=1.0, dash='solid',
                                        value_mapper_class=LinearMapper,
                                        bgcolor='transparent', border_visible=True,
                                        add_grid=False, add_axis=False, index_sort='ascending')
        add_default_axes(spectrumplot, orientation='flipped', vtitle='Frequency [MHz]', htitle='Amplitude')
        spectrumplot.origin = "top left"
        spectrumplot.tools.append(PanTool(spectrumplot, drag_button="right"))
        zoom = SimpleZoom(component=spectrumplot, tool_mode="box", drag_button="left", always_on=True)
        spectrumplot.overlays.append(zoom)

        container = OverlayPlotContainer(padding=40, padding_left=60)
        container.add(spectrumplot)
        self.container = container
示例#12
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
示例#13
0
    def _create_traceplot(self, y=None):
        x = self.x
        if y == None:
            y = self.y
        traceplot = create_line_plot((x, y), index_bounds=None, value_bounds=None,
                                     orientation='v', color='blue', width=1.0, dash='solid',
                                     value_mapper_class=LinearMapper,
                                     bgcolor='transparent', border_visible=True,
                                     add_grid=False, add_axis=False, index_sort='ascending')
        add_default_axes(traceplot, orientation='flipped', vtitle='Time [ns]', htitle='Signal')
        traceplot.origin = "top left"
        traceplot.tools.append(PanTool(traceplot, drag_button="right"))
        zoom = SimpleZoom(component=traceplot, tool_mode="box", drag_button="left", always_on=True)
        traceplot.overlays.append(zoom)

        container = OverlayPlotContainer(padding=40, padding_left=60)
        container.add(traceplot)
        self.container = container
示例#14
0
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
示例#15
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(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
示例#16
0
def do_plotv(session, *args, **kw):
    """ Creates a list of plots from the data in ``*args`` and options in
    ``**kw``, according to the docstring on commands.plot().
    """

    sort = kw.get("sort", "none")
    sources_list = make_data_sources(session, index_sort=sort, *args)

    plot_type = kw.get("type", "line")
    if plot_type == "scatter":
        plots = [create_scatter_plot(sources) for sources in sources_list]
    elif plot_type == "line":
        plots = [create_line_plot(sources) for sources in sources_list]
    else:
        raise ChacoShellError, "Unknown plot type '%s'." % plot_type

    for plot in plots:
        plot.orientation = kw.get("orientation", "h")


    return plots
def create_plot():

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

    low = -5

    high = 15.0

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

    # Plot some bessel functions

    value_mapper = None

    index_mapper = None

    for i in range(10):

        y = jn(i, x)

        plot = create_line_plot((x, y),
                                color=(1.0 - i / 10.0, i / 10.0, 0, 1),
                                width=2.0,
                                index_sort="ascending")
        if i == 0:
            value_mapper = plot.value_mapper
            index_mapper = plot.index_mapper
            add_default_axes(plot)
            add_default_grids(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"
        container.add(plot)
    return container
示例#18
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
    def _refresh_container(self,container):
        """ Plot some distribution functions """
        plots = {}
        broadcaster = BroadcasterTool()
    
        index = ArrayDataSource(self.x_array)
        value = ArrayDataSource(self.pdf_array, 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(value)
        value_mapper = LinearMapper(range=value_range)

        """Plot probability distribution function(pdf) with marking the area under the function  """ 
        plot_pdf = FilledLinePlot(index = index, value = value,
                                    index_mapper = index_mapper,
                                    value_mapper = value_mapper,
                                    edge_color = tuple(COLOR_PALETTE[0]),
                                    face_color = "paleturquoise",
                                    border_visible = True)
        
        """define the grid, axes and title of the vertical grid """
        add_default_grids(plot_pdf)
        add_default_axes(plot_pdf, vtitle="PDF") 

        """create a label for the pdf and append it to the plot_pdf """
        label_pdf = DataLabel(component=plot_pdf, data_point=(2.4,0.13), 
                          label_position=(15,15), padding=5,
                          label_format = 'PDF',
                          bgcolor = "transparent",
                          marker_color = "transparent",
                          marker_line_color = "transparent",
                          arrow_color = tuple(COLOR_PALETTE[0]),
                          border_visible=False)
        plot_pdf.overlays.append(label_pdf)
        container.add(plot_pdf)
        
        """create a label for the x coordinate """
        container.overlays.append(PlotLabel("X",
                                  component=container,
                                  font = "swiss 16",
                                  overlay_position="bottom"))

        pan = PanTool(plot_pdf)
#        zoom = SimpleZoom(plot_pdf, tool_mode="box", always_on=False)

        broadcaster.tools.append(pan)
 #       broadcaster.tools.append(zoom)
        #"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
        #""" Mean Plot
        x = ArrayDataSource( array( [ self.mean, self.mean ], dtype = float ) ) 
        y = ArrayDataSource( array( [ 0.0, max( self.pdf_array ) ], dtype = float ) )

        """ Plot the mean value"""
        plot_mean = LinePlot(index = x, value = y,
                        color = "pink",
                        index_mapper = index_mapper,
                        value_mapper = value_mapper )
        container.add(plot_mean)
        
        # 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.
        mean_pan = PanTool(plot_mean)
#        mean_zoom = SimpleZoom(plot_mean, tool_mode="box", always_on=False)
        broadcaster.tools.append(mean_pan)
 #       broadcaster.tools.append(mean_zoom)
        #"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
        # 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.
        """ Plot cdf and its label """
        plot_cdf = create_line_plot((self.x_array,self.cdf_array), 
                                color=tuple(COLOR_PALETTE[1]), width=2.0)
        plot_cdf.bgcolor = "white"
        plot_cdf.border_visible = True

        label_cdf = DataLabel(component=plot_cdf, data_point=(2.4,0.9), 
                          label_position=(-35,20), padding=5,
                          label_format = 'CDF',
                          bgcolor = "transparent",
                          marker_color = "transparent",
                          marker_line_color = "transparent",
                          arrow_color = tuple(COLOR_PALETTE[1]),
                          border_visible=False)
        plot_cdf.overlays.append(label_cdf)

        container.add(plot_cdf)

        pan1 = PanTool(plot_cdf)
#        zoom1 = SimpleZoom(plot_cdf, tool_mode="box", always_on=False)
        broadcaster.tools.append(pan1)
#        broadcaster.tools.append(zoom1)

        axis = PlotAxis(plot_cdf, title="CDF", orientation="right")
        plot_cdf.underlays.append(axis)
        #"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
        # Add the broadcast tool to the container, instead of to an
        # individual plot
        container.tools.append(broadcaster)
        ##**************************************************************************
        """Plot standard deviation """
        stdev_low   = self.mean - self.standard_deviation
        stdev_high  = self.mean + self.standard_deviation
        stdev_low_height = self.distr.pdf( stdev_low )
        stdev_high_height = self.distr.pdf( stdev_high )
        
        x = ArrayDataSource( array( [ stdev_low, stdev_low, stdev_high, stdev_high ], dtype = float ) ) 
        y = ArrayDataSource( array( [ 0, stdev_low_height, stdev_high_height, 0. ], dtype = float ) )
              
        plot_st = PolygonPlot(index = x, value = y,
                        edge_color = "purple",
                        index_mapper = index_mapper,
                        value_mapper = value_mapper )
        container.add(plot_st)
        ##*****************************************************************************
        """create the legend for the mean """
        legend = Legend(component=container, padding=10, align="ul")
        legend.tools.append(LegendTool(legend, drag_button="right"))
        container.overlays.append(legend)

        # Set the list of plots on the legend
        plots["Mean"] = plot_mean
        legend.plots = plots

        # Add the title at the top
        container.overlays.append(PlotLabel("probability distribution plots",
                                  component=container,
                                  font = "swiss 16",
                                  overlay_position="top"))
        # Add the traits inspector tool to the container
        container.tools.append(TraitsTool(container))
示例#20
0
    def make_plots(self):
        main_plot = chaco.Plot(self.plotdata, padding=0)

        colors = {
            'pos': 'black',
            'vel': 'blue',
            'accel': 'red',
            'jerk': 'green',
            'power': 'purple'
        }
        left_y_axis_title_list = []
        legend_dict = {}
        if self.plot_vel:
            vel_plot = main_plot.plot(("sample_times", "velocities"),
                                      type="line",
                                      color=colors['vel'],
                                      line_width=2)
            max_vel_plot = main_plot.plot(("endpoint_times", "max_vel"),
                                          color=colors['vel'],
                                          line_style='dash',
                                          line_width=0.60)
            min_vel_plot = main_plot.plot(("endpoint_times", "min_vel"),
                                          color=colors['vel'],
                                          line_style='dash',
                                          line_width=0.60)
            left_y_axis_title_list.append("Velocity (m/s)")
            legend_dict['vel'] = vel_plot

        if self.plot_accel:
            accel_plot = main_plot.plot(("knot_times", "accelerations"),
                                        type="line",
                                        color=colors['accel'],
                                        line_width=2)
            max_accel_plot = main_plot.plot(("endpoint_times", "max_accel"),
                                            color=colors['accel'],
                                            line_style='dash',
                                            line_width=0.55)
            min_accel_plot = main_plot.plot(("endpoint_times", "min_accel"),
                                            color=colors['accel'],
                                            line_style='dash',
                                            line_width=0.55)
            left_y_axis_title_list.append("Accel (m/s2)")
            legend_dict['accel'] = accel_plot

        if self.plot_jerk:
            jerk_plot = main_plot.plot(("knot_times", "jerks"),
                                       type="line",
                                       color=colors['jerk'],
                                       line_width=2,
                                       render_style="connectedhold")
            max_jerk_plot = main_plot.plot(("endpoint_times", "max_jerk"),
                                           color=colors['jerk'],
                                           line_style='dash',
                                           line_width=0.45)
            min_jerk_plot = main_plot.plot(("endpoint_times", "min_jerk"),
                                           color=colors['jerk'],
                                           line_style='dash',
                                           line_width=0.45)
            left_y_axis_title_list.append("Jerk (m/s3)")
            legend_dict['jerk'] = jerk_plot

        if self.plot_power:
            power_plot = main_plot.plot(("sample_times", "powers"),
                                        type="line",
                                        color=colors['power'],
                                        line_width=2)
            left_y_axis_title_list.append("Power (KW)")
            legend_dict['power'] = power_plot

        main_plot.y_axis.title = ", ".join(left_y_axis_title_list)
        self.container.add(main_plot)

        # plot positions (on a separate scale from the others)
        if self.plot_pos:
            pos_plot = chaco.create_line_plot([
                self.plotdata.arrays["sample_times"],
                self.plotdata.arrays["positions"]
            ],
                                              color=colors['pos'],
                                              width=2)
            legend_dict['pos'] = pos_plot
            self.container.add(pos_plot)

            # add a second y-axis for the positions
            pos_y_axis = chaco.PlotAxis(pos_plot,
                                        orientation="right",
                                        title="Position (meters)")
            self.container.overlays.append(pos_y_axis)

        # make Legend
        legend = chaco.Legend(component=self.container, padding=20, align="ul")
        legend.plots = legend_dict
        legend.tools.append(tools.LegendTool(legend, drag_button="left"))
        self.container.overlays.append(legend)

        # Add title, if any
        if self.title:
            main_plot.title = self.title
            main_plot.title_position = "inside top"
示例#21
0
# First, we create two arrays of data, x and y.  'x' will be a sequence of
# 100 points spanning the range -2pi to 2pi, and 'y' will be sin(x).
from scipy import arange, pi, sin
numpoints = 100
step = 4*pi / numpoints
x = arange(-2*pi, 2*pi+step/2, step)
y = sin(x)


# Now that we have our data, we can use a factory function to create the
# line plot for us.  Chaco provides a few factories to simplify creating common
# plot types (line, scatter, etc.).  In later tutorials we'll see what the
# factories are actually doing, and how to manually assemble plotting
# primitives in more powerful ways.  For now, factories suit our needs.
from enthought.chaco import api as chaco
myplot = chaco.create_line_plot((x,y), bgcolor="white", add_grid=True, add_axis=True)

# We now need to set the plot's size, and add a little padding for the axes.
# (Normally, when Chaco plots are placed inside WX windows, the bounds are
# set automatically by the window.)
myplot.padding = 50
myplot.bounds = [400,400]

def main():
    # Now we create a canvas of the appropriate size and ask it to render
    # our component.  (If we wanted to display this plot in a window, we
    # would not need to create the graphics context ourselves; it would be
    # created for us by the window.)
    plot_gc = chaco.PlotGraphicsContext(myplot.outer_bounds)
    plot_gc.render_component(myplot)
示例#22
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))
    def _plot_container_default(self):
        container = OverlayPlotContainer( padding = 60, fill_padding = False,
                                  bgcolor = "white", use_backbuffer=True)
        # Plot some distribution functions
        plots = {}
        broadcaster = BroadcasterTool()
    
    #""" Plot 
        
#        view = DataView(border_visible = True)
#
        index = ArrayDataSource(self.x_array)
        value = ArrayDataSource(self.pdf_array, sort_order="none")

        index_range = DataRange1D()
        index_range.add(index)
        index_mapper = LinearMapper(range=index_range)
    
        value_range = DataRange1D()
        value_range.add(value)
        value_mapper = LinearMapper(range=value_range)

        pdf_plot = FilledLinePlot(index = index, value = value,
                                    index_mapper = index_mapper,
                                    value_mapper = value_mapper,
                                    edge_color = tuple(COLOR_PALETTE[0]),
                                    face_color = "paleturquoise",
                                    bgcolor = "white",
                                    border_visible = True)

        add_default_grids(pdf_plot)
        add_default_axes(pdf_plot)

        #***************************Label*************************************
        pdf_label = DataLabel(component=pdf_plot, data_point=(2.4,0.15), 
                          label_position=(15,15), padding=5,
                          label_format = 'PDF',
                          bgcolor = "transparent",
                          marker_color = "transparent",
                          marker_line_color = "transparent",
                          border_visible=False)
        pdf_plot.overlays.append(pdf_label)
        
        
#        tool = DataLabelTool(pdf_label, drag_button="right", auto_arrow_root=True)
#        pdf_label.tools.append(tool)


        container.add(pdf_plot)
        pan = PanTool(pdf_plot)
        zoom = SimpleZoom(pdf_plot, tool_mode="box", always_on=False)
        broadcaster.tools.append(pan)
        broadcaster.tools.append(zoom)
        
        
#*********************************CDF****************************

        plot = create_line_plot((self.x_array,self.pdf_array), 
                                color=tuple(COLOR_PALETTE[0]), width=2.0)
        
        plot.bgcolor = "white"
        plot.border_visible = True                

        add_default_grids(plot)
        add_default_axes(plot)


        container.add(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)
        zoom = SimpleZoom(plot, tool_mode="box", always_on=False)
        broadcaster.tools.append(pan)
        broadcaster.tools.append(zoom)
        

    #""" PDF 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.
        pdf_plot = create_line_plot((self.x_array,self.cdf_array), 
                                color=tuple(COLOR_PALETTE[1]), width=2.0)
        pdf_plot.bgcolor = "white"
        pdf_plot.border_visible = True
     

        # Label
        cdf_text = TextBoxOverlay(text = 'CDF', alternate_position = (200,390) )
        pdf_plot.overlays.append(cdf_text)

        tool = DataLabelTool(cdf_text, drag_button="right", auto_arrow_root=True)
        cdf_text.tools.append(tool)
        
        container.add(pdf_plot)

#        vertical_axis = LabelAxis(pdf_plot, orientation='top',
#                                  title='Categories')
#        pdf_plot.underlays.append(vertical_axis)

        pdf_pan = PanTool(pdf_plot)
        pdf_zoom = SimpleZoom(pdf_plot, tool_mode="box", always_on=False)
        broadcaster.tools.append(pdf_pan)
        broadcaster.tools.append(pdf_zoom)


        axis = PlotAxis(pdf_plot, orientation="right")
        pdf_plot.underlays.append(axis)



#"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

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


        container.underlays.append(PlotLabel("CDF",
                                  component=container,
                                  font = "swiss 16",
                                  overlay_position="right"))


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

        # Set the list of plots on the legend
        plots["pdf"] = plot
        plots["cdf"] = pdf_plot
        legend.plots = plots


#*******************************************************************************


        x = ArrayDataSource( array( [ 0.0, 0.0 ], dtype = float ) ) 
        y = ArrayDataSource( array( [ 0.0, self.mean ], dtype = float ) )
        
        
        mean_plot = create_line_plot((x,y),
                                  color=tuple(COLOR_PALETTE[2]), width=2.0)


#        vertical_plot = LinePlot(index = ArrayDataSource( array( [ 0.0, 1.0 ], dtype = float ) ),
#                        value = ArrayDataSource( array( [ 0.0, 1.0 ], dtype = float ) ),
#                        color = "green"),
#                        index_mapper = LinearMapper(range=index_mapper),
#                        value_mapper = LinearMapper(range=value_mapper))
 


        container.add(mean_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.
        mean_pan = PanTool(mean_plot)
        mean_zoom = SimpleZoom(mean_plot, tool_mode="box", always_on=False)
        broadcaster.tools.append(mean_pan)
        broadcaster.tools.append(mean_zoom)



#**************************************************************************

        x = ArrayDataSource( array( [ 0.0, 0.0 ], dtype = float ) ) 
        y = ArrayDataSource( array( [ 0.0, 2.0 ], dtype = float ) )
        
        print "self.standard_deviation", self.standard_deviation
        
        st_plot = create_line_plot((x,y),
                                  color=tuple(COLOR_PALETTE[4]), width=2.0)

        container.add(st_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.
        st_pan = PanTool(st_plot)
        st_zoom = SimpleZoom(st_plot, tool_mode="box", always_on=False)
        broadcaster.tools.append(st_pan)
        broadcaster.tools.append(st_zoom)



#*****************************************************************************

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

        # Add the traits inspector tool to the container
        container.tools.append(TraitsTool(container))
        return container
示例#24
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 = linspace(low, high, numpoints)

    now = time()
    timex = linspace(now, now+7*24*3600, numpoints)

    # Plot some bessel functions
    value_mapper = None
    index_mapper = None
    plots = {}
    for i in range(10):
        y = jn(i, x)
        if i%2 == 1:
            plot = create_line_plot((timex,y), color=tuple(COLOR_PALETTE[i]), width=2.0)
            plot.index.sort_order = "ascending"
        else:
            plot = create_scatter_plot((timex,y), color=tuple(COLOR_PALETTE[i]))
        plot.bgcolor = "white"
        plot.border_visible = True
        if i == 0:
            value_mapper = plot.value_mapper
            index_mapper = plot.index_mapper
            left, bottom = add_default_axes(plot)
            left.tick_generator = ScalesTickGenerator()
            bottom.tick_generator = ScalesTickGenerator(scale=CalendarScaleSystem())
            add_default_grids(plot, tick_gen=bottom.tick_generator)
        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==0:
            plot.tools.append(PanTool(plot))
            zoom = ZoomTool(plot, tool_mode="box", always_on=False)
            plot.overlays.append(zoom)
            # 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)

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

    # 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
示例#25
0
    def _create_plot_component(self):
        container = OverlayPlotContainer(padding = 50, fill_padding = True,
                                         bgcolor = 0xc9e1eb,
                                         use_backbuffer=True)
        self.container = container

        self.value_mapper = None
        self.index_mapper = None
        self.plots = {}
        
        if sys.platform == 'linux2':
            plot_font = 'sans-serif'
        elif sys.platform == 'darwin':
            plot_font = 'Helvetica'
        else:
            plot_font = 'Verdana'
        
        # Store Python object ids to distinguish between different plots
        # with the same label
        self.plot_ids = []
        
        self.beams = {}
        x = numpy.arange(0)
        y = numpy.arange(0)
        plot = create_line_plot((x,y), color=tuple(self.get_plot_color()), width=2.0)
        plot.index.sort_order = "ascending"
       

        plot.bgcolor = "white"
        plot.border_visible = True
            
        self.value_mapper = plot.value_mapper
        self.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, drag_button="middle"))
        
                
        # 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, 
                        drag_button="right", always_on_modifier='control')#,
#                        x_min_zoom_factor=0.5,
#                        y_min_zoom_factor=0.5,
#                        x_max_zoom_factor=40.,
#                        y_max_zoom_factor=40.)
        
        zoom.zoom_factor = 1.2
        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")
#        dragzoom.speed = 0.2
#        plot.tools.append(dragzoom)

        # Add a legend in the upper right corner, and make it relocatable
        self.legend = Legend(component=plot, padding=10, align="ur")
        self.legend.tools.append(LegendTool(self.legend, drag_button="right"))
        self.legend.font = plot_font+' 12'
        plot.overlays.append(self.legend)
        self.legend.visible = False
        
        # The  Legend tool allows plots to be selected by left clicking
        # on the label in the plot legend.  This tool sets the ChacoPlot 
        # selected plot trait.
        highlight_legend = HighlightLegend(self.legend)
        highlight_legend.parent = self
        self.legend.tools.append(highlight_legend)
        
        # The PlotSelectTool allows plots to be selected by left clicking
        # on the actual plot trace.  This tools sets the ChacoPlot selected
        # plot trait.
        plot_select_tool = PlotSelectTool(self.container)
        plot_select_tool.parent = self
        plot.tools.append(plot_select_tool)
        
        plot.x_axis.title = "Distance (cm)"
        plot.x_axis.title_font = plot_font+" 12"
        plot.x_axis.tick_label_font = plot_font+" 10"
        plot.y_axis.title = "% Dose"
        plot.y_axis.title_font = plot_font+" 12"
        plot.y_axis.tick_label_font = plot_font+" 10"

        container.add(plot)
        
        # Set the list of plots on the legend
        self.legend.plots = self.plots
        
        # Add the title at the top
        self.title = PlotLabel("Scans",
                                  component=container,
                                  font = plot_font+' 16',
                                  overlay_position="top")
        container.overlays.append(self.title)

        return container
示例#26
0
    def add_plot(self, label, beam):
        
        # Check to see if beam has already been plotted.
        if id(beam) in self.plot_ids:
            return          
        
        # Remove extraneous whitespace
        label = '|'.join([i.strip() for i in label.split('|')])
        # Remove spaces in fields within the label so that when the '|' are
        # replaced with spaces, the label will be able to be split on spaces.
        label = label.replace(' ','_')
        # The plot_type trait is defined by the geometry of the scanned plot 
        # (inline, crossline, depth dose, etc.).  
        if self.plot_type is not None:
            self.plot_type = beam.get_scan_type()
            
#        # Reformat labels
#        fields = [i.strip() for i in label.split('|')]
#        if self.plot_type == 'Depth Dose':
#            label = ' '.join(fields[:-1])
        if self.plot_type in ['Inplane Profile','Crossplane Profile']:
            label = label+'_cm_depth'
            
        x, y = (beam.Data_Abscissa, beam.Data_Ordinate)
        if label in self.plots.keys():
            #label = increment(label)
            label = label + '_' + str(len(self.plots))
        plot = create_line_plot((x,y), color=tuple(
                                    self.get_plot_color()), width=2.0)
        plot.index.sort_order = "ascending"
            
        plot.bgcolor = "white"
        plot.border_visible = True
                
        plot.value_mapper = self.value_mapper
        self.value_mapper.range.add(plot.value)
        plot.index_mapper = self.index_mapper
        self.index_mapper.range.add(plot.index)
            
        self.container.add(plot)
        
        # beams and plots are dictionaries that map plot objects to beam
        # objects and plot labels to plot objects.  They are used to
        # determine plot titles and legend labels as well as mapping 
        # the selected_plot trait to the selected_beam trait.
        self.beams[plot] = beam
        self.plots[label] = plot
        self.plot_ids.append(id(beam))
        
        self.legend.visible = True
        self.legend.plots = self.plots
        self.legend.labels = self.get_legend_labels()
        
        # legend.plots dictionary must have keys that match the labels in 
        # legend.labels in order for the labels to be visible.
        legend_plot_dict = {}
        for i in self.legend.plots.keys():
            for j in self.legend.labels:
                label_set = set(j.split(' '))
                plot_set = set(i.split('|'))
                if label_set.issubset(plot_set):
                    legend_plot_dict[j] = self.legend.plots[i]
        self.legend.plots = legend_plot_dict
        
        
                    
        self.title.text = self.get_title()
        self.container.request_redraw()
        
        return self.title.text
示例#27
0
    def _create_window(self):
        container = OverlayPlotContainer(padding = 50, fill_padding = True,
                                         bgcolor = "lightgray", use_backbuffer=True)
        self.container = container

        # 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
        value_mapper = None
        index_mapper = None
        plots = {}
        for i in range(10):
            y = jn(i, x)
            if i%2 == 1:
                plot = create_line_plot((x,y), color=tuple(COLOR_PALETTE[i]), width=2.0)
                plot.index.sort_order = "ascending"
            else:
                plot = create_scatter_plot((x,y), color=tuple(COLOR_PALETTE[i]))

            plot.bgcolor = "white"
            plot.border_visible = True
            if i == 0:
                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()
            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==0:
                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)

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

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

        
        container.overlays.append(PlotLabel("height",component=container,overlay_position="bottom"))


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

        return Window(self, -1, component=container)