def _create_plot_component():
    # Create a GridContainer to hold all of our plots: 2 rows, 3 columns:
    container = GridContainer(padding=40,
                              fill_padding=True,
                              bgcolor="lightgray",
                              use_backbuffer=True,
                              shape=(2, 3),
                              spacing=(20, 20))

    # Create the initial series of data
    x = linspace(-5, 15.0, 100)
    pd = ArrayPlotData(index=x)

    # Plot some bessel functions and add the plots to our container
    for i in range(6):
        pd.set_data("y" + str(i), jn(i, x))
        plot = Plot(pd)
        plot.plot(("index", "y" + str(i)),
                  color=tuple(COLOR_PALETTE[i]),
                  line_width=2.0,
                  bgcolor="white",
                  border_visible=True)

        # Tweak some of the plot properties
        plot.border_width = 1
        plot.padding = 0
        plot.padding_top = 30

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

        # Add to the grid container (
        container.add(plot)

    # Set the upper-left plot to only be resizable vertically, and to have a
    # fixed horizontal width. This also constrains the width of the first column.
    ul_plot = container.components[0]
    ul_plot.set(resizable="v", width=200)
    ul_plot.overlays.append(
        PlotLabel("Not horizontally resizable", component=ul_plot))

    # Set the bottom center plot to have a fixed width and height.
    # This also constrains the height of the bottom row and the width of
    # the middle column.
    cplot = container.components[4]
    cplot.set(resizable="", bounds=[400, 400])
    cplot.overlays.append(PlotLabel("Not resizable", component=cplot))

    container.padding_top = 50
    container.overlays.append(
        PlotLabel(
            'Resize the window - some plots resize, others cannot '
            '(see source code)',
            component=container,
            font="swiss 16",
            overlay_position="top"))

    return container
Beispiel #2
0
    def _create_spin_noise_plot(self):
        plot_data_spin_noise = ArrayPlotData(value=np.array((0., 1.)),
                                             time=np.array((0., 0.)),
                                             fit=np.array((0., 0.)),
                                             peak_free=np.array((0., 0.)),
                                             f=np.array((0., 0.)),
                                             fit_x=np.array((0., 0.)))
        plot = Plot(plot_data_spin_noise,
                    width=50,
                    height=40,
                    padding=8,
                    padding_left=64,
                    padding_bottom=32)
        plot.plot(('time', 'value'), color='red', line_width=2,
                  type='scatter')  #, index_scale = 'log', value_scale = 'log')
        plot.index_axis.title = 'frequency [MHz]'
        plot.value_axis.title = 'noise spectrum [nT^2/Hz]'
        #plot.title='noise spectrum'
        line_label = PlotLabel(text='',
                               hjustify='left',
                               vjustify='top',
                               position=[50, 100])
        plot.overlays.append(line_label)
        self.line_label = line_label

        self.plot_data_spin_noise = plot_data_spin_noise
        self.spin_noise_plot = plot
        return self.spin_noise_plot
Beispiel #3
0
    def _fit_changed(self, name, old, new):
        old.measurement = None
        new.measurement = self.measurement
        plot = self.line_plot
        plot2 = self.processed_plot
        # delete all old plots
        for key in plot.plots.keys()[0:1]:
            plot.delplot(key)
        for key in plot2.plots.keys()[1:]:
            plot2.delplot(key)

        # set new data source
        plot.data = self.fit.line_data
        plot2.data = self.fit.processed_plot_data

        # make new plots
        for item in self.fit.plots[0:1]:
            plot.plot(**item)

        for item in self.fit.plots[1:]:
            plot2.plot(**item)
        #if hasattr(self.fit,'legends'):
        #plot.legend(**self.fit.legends)
        # if the fit has an attr 'text' attached to it, print it in the lower left corner of the plot
        if hasattr(old, 'text'):
            label = plot.overlays[0]
            old.sync_trait('text', label, 'text', mutual=False, remove=True)
            plot.overlays = []
        if hasattr(new, 'text'):
            label = PlotLabel(text=self.fit.text,
                              hjustify='left',
                              vjustify='bottom',
                              position=[64, 32])
            new.sync_trait('text', label, 'text', mutual=False)
            plot.overlays = [label]
Beispiel #4
0
    def _create_plot(self):
        plot_data = ArrayPlotData(image=self.image)
        plot = Plot(plot_data, width=500, height=500, resizable='hv', aspect_ratio=1.0, padding=8, padding_left=32, padding_bottom=32)
        plot.img_plot('image',  colormap=RdBu_r, xbounds=(self.X[0],self.X[-1]), ybounds=(self.Y[0],self.Y[-1]), name='image')
        image = plot.plots['image'][0]
        image.x_mapper.domain_limits = (self.imager.get_x_range()[0],self.imager.get_x_range()[1])
        image.y_mapper.domain_limits = (self.imager.get_y_range()[0],self.imager.get_y_range()[1])
        zoom = AspectZoomTool(image, enable_wheel=False)
        cursor = CursorTool2D(image, drag_button='left', color='yellow', marker_size=1.0, line_width=1.0 )
        image.overlays.append(cursor)
        image.overlays.append(zoom)
        colormap = image.color_mapper
        colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                            color_mapper=colormap,
                            plot=plot,
                            orientation='v',
                            resizable='v',
                            width=16,
                            height=320,
                            padding=8,
                            padding_left=32)
        container = HPlotContainer()
        container.add(plot)
        container.add(colorbar)
        z_label = PlotLabel(text='z=0.0', color='red', hjustify='left', vjustify='bottom', position=[10,10])
        container.overlays.append(z_label)
        container.tools.append(SaveTool(container))

        self.plot_data = plot_data
        self.scan_plot = image
        self.cursor = cursor
        self.zoom = zoom
        self.figure = plot
        self.figure_container = container
        self.sync_trait('z_label_text', z_label, 'text')
Beispiel #5
0
 def _set_title_label(self, plot):
     font_size = self.plot_style.title_style.font_size
     font_name = self.plot_style.title_style.font_name
     font = '{} {}'.format(font_name, font_size)
     title_label = PlotLabel(self.plot_title,
                             component=plot,
                             font=font,
                             overlay_position="top")
     plot.overlays.append(title_label)
     plot.title = title_label
Beispiel #6
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
Beispiel #7
0
    def _create_plot_component_vertical(signals=Array, use_downsampling=False):

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

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

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

            plot = create_line_plot(
                (time, signals[i]),
                color=tuple(COLOR_PALETTE[i % len(COLOR_PALETTE)]),
                width=1.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 = False
            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)

            container.add(plot)
            plots["Corr fun %d" % i] = 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
        # container.padding_top = 50
        container.overlays.append(
            PlotLabel("Correlation function",
                      component=container,
                      font="swiss 16",
                      overlay_position="top"))
        # 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 #8
0
 def _create_line_plot(self):
     line_data = ArrayPlotData(frequency=np.array((0.,1.)), counts=np.array((0.,0.)), fit=np.array((0.,0.))) 
     line_plot = Plot(line_data, padding=8, padding_left=64, padding_bottom=32)
     line_plot.plot(('frequency','counts'), style='line', color='blue')
     line_plot.index_axis.title = 'Frequency [MHz]'
     line_plot.value_axis.title = 'Fluorescence counts'
     line_label = PlotLabel(text='', hjustify='left', vjustify='bottom', position=[64,128])
     line_plot.overlays.append(line_label)
     self.line_label = line_label
     self.line_data = line_data
     self.line_plot = line_plot
Beispiel #9
0
 def _add_avg_std_err(self, text):
     info_label = PlotLabel(
         text=text,
         component=self,
         overlay_position='outside bottom',
         border_visible=False,
         border_width=2,
         margin=6,
         fill_padding=False,
         hjustify='center',
     )
     self.overlays.append(info_label)
Beispiel #10
0
 def _create_second_method_plot(self):
     plot_data_second_method = ArrayPlotData(value=np.array((0., 1.)), time=np.array((0., 0.)), fit=np.array((0., 0.)) )
     plot = Plot(plot_data_second_method, width=50, height=40, padding=8, padding_left=64, padding_bottom=32)
     plot.plot(('time', 'value'), color='green', line_width = 2)
     plot.index_axis.title = 'time [ns]'
     plot.value_axis.title = 'Normalized Contrast'
     #plot.title='noise spectrum'
     line_label = PlotLabel(text='', hjustify='left', vjustify='top', position=[64, 280])
     plot.overlays.append(line_label)
     self.line_label = line_label
     
     self.plot_data_second_method= plot_data_second_method
     self.second_method_plot = plot
     return self.second_method_plot
Beispiel #11
0
    def add_plot_label(self, txt, x, y, plotid=0, **kw):
        '''
        '''

        #        print x, y
        # #        x, y = .map_screen([(x, y)])[0]
        #        x, y = self.plots[plotid].map_screen([(x, y)])[0]
        #        print x, y
        c = self.plots[plotid]

        pl = PlotLabel(txt,
                       overlay_position='inside top',
                       hjustify='left',
                       component=c,
                       **kw)
        c.overlays.append(pl)
        return pl
Beispiel #12
0
 def _create_line_plot(self):
     line_data = ArrayPlotData(index=np.array((0, 1)),
                               spin_state=np.array((0, 0)),
                               fit=np.array((0, 0)))
     plot = Plot(line_data, padding=8, padding_left=64, padding_bottom=36)
     plot.plot(('index', 'spin_state'), color='blue', name='spin_state')
     plot.plot(('index', 'fit'), color='red', name='fit')
     plot.index_axis.title = 'time [micro s]'
     plot.value_axis.title = 'spin state'
     plot.overlays.insert(
         0,
         PlotLabel(text=self.label_text,
                   hjustify='left',
                   vjustify='bottom',
                   position=[64, 32]))
     plot.tools.append(SaveTool(plot))
     self.line_data = line_data
     self.line_plot = plot
Beispiel #13
0
    def __init__(self, **traits):
        super(CameraImage, self).__init__(**traits)
        self._dims = (200, 320)
        self.data_store = ArrayPlotData(image=self.data)
        self._hud = dict()
        self.plot = Plot(self.data_store)
        # Draw the image
        renderers = self.plot.img_plot('image',
                                       name='camera_image',
                                       colormap=fix(gray, (0, 255)))
        self._image = renderers[0]
        self.plot.aspect_ratio = float(self._dims[1]) / self._dims[0]

        self.hud_overlay = PlotLabel(text='',
                                     component=self.plot,
                                     hjustify='left',
                                     overlay_position='inside bottom',
                                     color='white')
        self.plot.overlays.append(self.hud_overlay)
Beispiel #14
0
    def set_title(self, t, font='modern', size=None):
        '''
        '''
        self._title = t

        pc = self.plotcontainer

        if pc.overlays:
            pc.overlays.pop()

        if not font in VALID_FONTS:
            font = 'modern'

        if size is None:
            size = 12
        self._title_font = font
        self._title_size = size
        font = '{} {}'.format(font, size)
        #        import wx

        #        family = wx.FONTFAMILY_MODERN
        #        style = wx.FONTSTYLE_NORMAL
        #        weight = wx.FONTWEIGHT_NORMAL
        #        font = wx.Font(size, family, style, weight, False,
        #                       font)

        pl = PlotLabel(
            t,
            component=pc,
            #                       bgcolor='red',
            #                       draw_layer='overlay'
            font=font,
            #                                 vjustify='bottom',
            #                                 overlay_position='top'
        )
        #        print pl
        pc.overlays.append(pl)
        #        print pc.components
        #        pc.add(pl)
        #        pc._components.insert(0, pl)
        #        pc.invalidate_and_redraw()
        #        pc.request_redraw()
        self.redraw()
Beispiel #15
0
def _create_plot_component():
    numpoints = 100
    low = -5
    high = 15.0
    x = arange(low, high, (high - low) / numpoints)
    container = container_class(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=plot_orientation)
        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("Bessel Functions in a Strip Plot",
                  component=container,
                  font="swiss 16",
                  overlay_position="top"))

    return container
Beispiel #16
0
    def set_title(self, t, font='modern', size=None):
        """
        """
        self._title = t

        pc = self.plotcontainer

        if pc.overlays:
            pc.overlays.pop()

        if not font in VALID_FONTS:
            font = 'modern'

        if size is None:
            size = 12
        self._title_font = font
        self._title_size = size
        font = '{} {}'.format(font, size)

        pl = PlotLabel(t, component=pc, font=font)

        pc.overlays.append(pl)
        self.redraw()
Beispiel #17
0
    def _rebuild_plot(self):
        container = self.plot

        value_range = DataRange1D(low=-1, high=1.)
        index_range = DataRange1D(self.index_ds,
                                  high='track',
                                  tracking_amount=24 * 3600 * 365)

        color_mapper = cmap(range=value_range)

        # Remove old plots
        container.remove(*container.components)
        for val, row in zip(self.value_ds, self.rows):
            horizon = HorizonPlot(
                index=self.index_ds,
                value=val,
                index_mapper=LinearMapper(range=index_range,
                                          stretch_data=False),
                value_mapper=BandedMapper(range=DataRange1D(val)),
                color_mapper=cmap(range=DataRange1D(val)),  #color_mapper,
                negative_bands=False,
            )
            horizon.tools.append(
                PanTool(horizon, constrain=True, constrain_direction="x"))
            horizon.overlays.append(
                PlotLabel(component=horizon,
                          hjustify='right',
                          text=row,
                          overlay_position='outside left'))
            container.add(horizon)
        bottom_axis = PlotAxis(
            horizon,
            orientation="bottom",
            tick_generator=ScalesTickGenerator(scale=CalendarScaleSystem()))
        container.overlays = [bottom_axis]

        container.request_redraw()
Beispiel #18
0
    def _setup_plots(self):
        """Creates series of Bessel function plots"""
        plots = {}
        x = arange(self.low, self.high + 0.001,
                   (self.high - self.low) / self.numpoints)

        for i in range(self.num_funs):
            y = jn(i, x)
            if i % 2 == 1:
                plot = create_line_plot((x, y),
                                        color=tuple(COLOR_PALETTE[i]),
                                        width=2.0)
            else:
                plot = create_scatter_plot((x, y),
                                           color=tuple(COLOR_PALETTE[i]))

            if i == 0:
                value_mapper, index_mapper, legend = \
                    self._setup_plot_tools(plot)
            else:
                self._setup_mapper(plot, value_mapper, index_mapper)

            self.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.overlays.append(
            PlotLabel("Bessel functions",
                      component=self,
                      font="swiss 16",
                      overlay_position="top"))

        # Add the traits inspector tool to the container
        self.tools.append(TraitsTool(self))
Beispiel #19
0
    def _create_plot_component(self):
        from numpy import abs, cumprod, random


        # Chaco imports
        from chaco.api import ArrayDataSource, BarPlot, DataRange1D, \
            LinearMapper, VPlotContainer, PlotAxis, \
            FilledLinePlot, add_default_grids, PlotLabel
        from chaco.tools.api import PanTool, ZoomTool

        from chaco.scales.api import CalendarScaleSystem, ScaleSystem
        from chaco.scales_tick_generator import ScalesTickGenerator

        # Create the data and datasource objects
        # In order for the date axis to work, the index data points need to
        # be in units of seconds since the epoch.  This is because we are using
        # the CalendarScaleSystem, whose formatters interpret the numerical values
        # as seconds since the epoch.
        numpoints = self.data.size
        index = np.arange(self.data.size)

        self.xsource = ArrayDataSource(index)
        #vol_ds = ArrayDataSource(volume, sort_order="none")
        self.ysource = ArrayDataSource(self.data, sort_order="none")

        xmapper = LinearMapper(range=DataRange1D(self.xsource))
        #vol_mapper = LinearMapper(range=DataRange1D(vol_ds))
        meas_mapper = LinearMapper(range=DataRange1D(self.ysource))

        price_plot = FilledLinePlot(index=self.xsource, value=self.ysource,
                                    index_mapper=xmapper,
                                    value_mapper=meas_mapper,
                                    edge_color=tuple(cbrewer[0]),
                                    face_color="paleturquoise",
                                    bgcolor="gray",
                                    border_visible=True)
        price_plot.overlays.append(PlotAxis(price_plot, orientation='left')),

        # Set the plot's bottom axis to use the Scales ticking system
        # bottom_axis = PlotAxis(price_plot, orientation="bottom",  # mapper=xmapper,
        #                        tick_generator=ScalesTickGenerator(scale=ScaleSystem()))
        # price_plot.overlays.append(bottom_axis)
        # hgrid, vgrid = add_default_grids(price_plot)
        # vgrid.tick_generator = bottom_axis.tick_generator
        #
        # price_plot.tools.append(PanTool(price_plot, constrain=True,
        #                                 constrain_direction="x"))
        # price_plot.overlays.append(ZoomTool(price_plot, drag_button="right",
        #                                     always_on=True,
        #                                     tool_mode="range",
        #                                     axis="index",
        #                                     max_zoom_out_factor=10.0,
        #                                     ))




        container = VPlotContainer(bgcolor="lightblue",
                                   spacing=40,
                                   padding=50,
                                   fill_padding=False)

        container.add(price_plot)
        container.overlays.append(PlotLabel(self.title,
                                            component=container,
                                            # font="Times New Roman 24"))
                                            ))

        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 #21
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
Beispiel #22
0
    def _get_plot_overlay(self):

        if self.data is None or len(self.data.shape) == 1:
            return

        container = OverlayPlotContainer(resizable="v",
                                         fill_padding=True,
                                         padding=30,
                                         bgcolor="transparent",
                                         use_backbuffer=True)

        numpoints = self.data.shape[1]

        if self.scale_type == 'Time':
            index = self._create_dates(numpoints, start=self.first_day)
        else:
            index = range(numpoints)

        time_ds = ArrayDataSource(index)
        xmapper = LinearMapper(range=DataRange1D(time_ds))

        corr_mapper = None

        for (m, cDx) in enumerate(self.data):

            corr_ds = ArrayDataSource(cDx, sort_order="none")

            if corr_mapper is None:
                corr_mapper = LinearMapper(range=DataRange1D(corr_ds))

            corr_plot = LinePlot(
                index=time_ds,
                value=corr_ds,
                index_mapper=xmapper,
                value_mapper=corr_mapper,
                color=tuple(COLOR_PALETTE[m % len(COLOR_PALETTE)]),
                edge_color="blue",
                face_color="paleturquoise",
                #bgcolor="white",
                border_visible=True,
                padding_left=25)

            corr_mapper.range.add(corr_plot.value)

            if m == 0:
                ###### Y axis #####################################################

                left = PlotAxis(
                    orientation='left',
                    title=self.y_lbl,
                    title_font="modern 12",
                    #title_spacing=0,
                    tick_label_font="modern 8",
                    tick_visible=True,
                    small_axis_style=True,
                    axis_line_visible=False,
                    ensure_labels_bounded=True,
                    #tick_label_color="transparent",
                    mapper=corr_mapper,
                    component=corr_plot)

                corr_plot.overlays.append(left)

                ###### X axis #####################################################

                if self.scale_type == 'Time':
                    # Just the last axis shows tick_labels
                    bottom_axis = PlotAxis(corr_plot,
                                           orientation="bottom",
                                           title=self.x_lbl,
                                           tick_generator=ScalesTickGenerator(
                                               scale=CalendarScaleSystem()))
                else:
                    bottom_axis = PlotAxis(orientation='bottom',
                                           title=self.x_lbl,
                                           title_font="modern 12",
                                           tick_visible=True,
                                           small_axis_style=True,
                                           axis_line_visible=False,
                                           component=corr_plot)

                corr_plot.overlays.append(bottom_axis)

                ###### Grids #####################################################

                _, vgrid = add_default_grids(corr_plot)
                vgrid.tick_generator = bottom_axis.tick_generator

                ###### Tools #####################################################

                corr_plot.tools.append(
                    PanTool(corr_plot, constrain=True,
                            constrain_direction="x"))
                corr_plot.overlays.append(
                    ZoomTool(
                        corr_plot,
                        drag_button="right",
                        always_on=True,
                        tool_mode="box",
                        #axis="index",
                        max_zoom_out_factor=10.0,
                    ))
            container.add(corr_plot)

        ###### Title #####################################################
        container.overlays.append(
            PlotLabel(self.p_title,
                      component=container,
                      overlay_position="outside top",
                      font="modern 16"))

        container.padding_bottom = 50

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

        if self.data is None or len(self.data.shape) == 1:
            return

        numpoints = self.data.shape[1]

        if self.scale_type == 'Time':
            index_x = self._create_dates(numpoints, start=self.first_day)
        else:
            index_x = np.arange(numpoints)

        x_bounds = (index_x[0], index_x[-1], len(index_x))
        y_bounds = (1, self.data.shape[0], self.data.shape[0])
        # Create a plot data obect and give it this data
        pd = ArrayPlotData()
        pd.set_data("imagedata", self.data)

        plot = Plot(pd)

        plot.img_plot("imagedata",
                      name="corr_plot",
                      origin="top left",
                      xbounds=x_bounds[:2],
                      ybounds=y_bounds[:2],
                      colormap=jet,
                      padding_left=25)

        corr_plot = plot.plots['corr_plot'][0]

        if self.scale_type == 'Time':
            # Just the last axis shows tick_labels
            bottom_axis = PlotAxis(corr_plot,
                                   orientation="bottom",
                                   title=self.x_lbl,
                                   tick_generator=ScalesTickGenerator(
                                       scale=CalendarScaleSystem()))
        else:
            bottom_axis = PlotAxis(orientation='bottom',
                                   title=self.x_lbl,
                                   title_font="modern 12",
                                   tick_visible=True,
                                   small_axis_style=True,
                                   axis_line_visible=False,
                                   component=corr_plot)

        corr_plot.overlays.append(bottom_axis)

        corr_plot.tools.append(
            PanTool(corr_plot,
                    constrain=True,
                    constrain_direction="x",
                    constrain_key="shift"))
        corr_plot.overlays.append(
            ZoomTool(
                corr_plot,
                drag_button="right",
                always_on=True,
                tool_mode="range",
                axis="index",
                max_zoom_out_factor=10.0,
            ))

        # Create the colorbar, handing in the appropriate range and colormap
        colorbar = ColorBar(
            index_mapper=LinearMapper(range=corr_plot.color_mapper.range),
            color_mapper=corr_plot.color_mapper,
            plot=corr_plot,
            orientation='v',
            resizable='v',
            width=30,
            padding_top=corr_plot.padding_top,
            padding_bottom=corr_plot.padding_bottom,
            padding_left=50,
            padding_right=5)

        #colorbar.plot = corr_plot
        #colorbar.padding_top = corr_plot.padding_top
        #colorbar.padding_bottom = corr_plot.padding_bottom

        # Add pan and zoom tools to the colorbar
        pan_tool = PanTool(colorbar, constrain_direction="y", constrain=True)
        colorbar.tools.append(pan_tool)

        zoom_overlay = ZoomTool(colorbar,
                                axis="index",
                                tool_mode="range",
                                always_on=False,
                                drag_button=None)
        colorbar.overlays.append(zoom_overlay)

        # Create a container to position the plot and the colorbar side-by-side
        container = HPlotContainer(corr_plot,
                                   colorbar,
                                   use_backbuffer=True,
                                   bgcolor="transparent",
                                   spacing=9,
                                   padding=30)

        container.overlays.append(
            PlotLabel(self.p_title,
                      component=container,
                      overlay_position="outside top",
                      font="modern 16"))

        container.overlays.append(
            PlotLabel(self.y_lbl,
                      component=container,
                      angle=90.0,
                      overlay_position="outside left",
                      font="modern 12"))

        container.padding_bottom = 50

        return container
Beispiel #24
0
    def setup_plots(self):
        self.screen = Plot(self.data,
                resizable="hv", padding=0, bgcolor="lightgray",
                border_visible=False)
        self.screen.index_grid.visible = False
        self.screen.value_grid.visible = False
        px = self.process.capture.pixelsize
        w, h = self.process.capture.width, self.process.capture.height
        # value_range last, see set_range()
        self.screen.index_range.low_setting = -w/2*px
        self.screen.index_range.high_setting = w/2*px
        self.screen.value_range.low_setting = -h/2*px
        self.screen.value_range.high_setting = h/2*px

        self.horiz = Plot(self.data,
                resizable="h", padding=0, height=100,
                bgcolor="lightgray", border_visible=False)
        self.horiz.value_mapper.range.low_setting = \
                -.1*self.process.capture.maxval
        self.horiz.index_range = self.screen.index_range
        self.vert = Plot(self.data, orientation="v",
                resizable="v", padding=0, width=100,
                bgcolor="lightgray", border_visible=False)
        for p in self.horiz, self.vert:
            p.index_axis.visible = False
            p.value_axis.visible = False
            p.index_grid.visible = True
            p.value_grid.visible = False
        self.vert.value_mapper.range.low_setting = \
                -.1*self.process.capture.maxval
        self.vert.index_range = self.screen.value_range

        #self.vert.value_range = self.horiz.value_range

        self.mini = Plot(self.data,
                width=100, height=100, resizable="", padding=0,
                bgcolor="lightgray", border_visible=False)
        self.mini.index_axis.visible = False
        self.mini.value_axis.visible = False
        self.label = PlotLabel(component=self.mini,
                overlay_position="inside left", font="modern 10",
                text=self.process.text)
        self.mini.overlays.append(self.label)

        self.plots = GridPlotContainer(shape=(2, 2), padding=0,
                spacing=(5, 5), use_backbuffer=True,
                bgcolor="lightgray")
        self.plots.component_grid = [[self.vert, self.screen],
                                     [self.mini, self.horiz ]]

        self.screen.overlays.append(ZoomTool(self.screen,
            x_max_zoom_factor=1e2, y_max_zoom_factor=1e2,
            x_min_zoom_factor=0.5, y_min_zoom_factor=0.5,
            zoom_factor=1.2))
        self.screen.tools.append(PanTool(self.screen))
        self.plots.tools.append(SaveTool(self.plots,
            filename="bullseye.pdf"))

        self.asum = Plot(self.data,
                padding=0, height=100, bgcolor="lightgray",
                title="major axis", border_visible=False)
        self.bsum = Plot(self.data,
                padding=0, height=100, bgcolor="lightgray",
                title="minor axis", border_visible=False)
        for p in self.asum, self.bsum:
            p.value_axis.visible = False
            p.value_grid.visible = False
            p.title_font = "modern 10"
            p.title_position = "left"
            p.title_angle = 90
        # lock scales
        #self.bsum.value_range = self.asum.value_range
        #self.bsum.index_range = self.asum.index_range

        self.abplots = VPlotContainer(padding=20, spacing=20,
                use_backbuffer=True,bgcolor="lightgray",
                fill_padding=True)
        self.abplots.add(self.bsum, self.asum)
def _create_plot_component():

    # Create the data and datasource objects
    # In order for the date axis to work, the index data points need to
    # be in units of seconds since the epoch.  This is because we are using
    # the CalendarScaleSystem, whose formatters interpret the numerical values
    # as seconds since the epoch.
    numpoints = 500
    index = create_dates(numpoints)
    returns = random.lognormal(0.01, 0.1, size=numpoints)
    price = 100.0 * cumprod(returns)
    volume = abs(random.normal(1000.0, 1500.0, size=numpoints) + 2000.0)

    time_ds = ArrayDataSource(index)
    vol_ds = ArrayDataSource(volume, sort_order="none")
    price_ds = ArrayDataSource(price, sort_order="none")

    xmapper = LinearMapper(range=DataRange1D(time_ds))
    vol_mapper = LinearMapper(range=DataRange1D(vol_ds))
    price_mapper = LinearMapper(range=DataRange1D(price_ds))

    price_plot = FilledLinePlot(index=time_ds,
                                value=price_ds,
                                index_mapper=xmapper,
                                value_mapper=price_mapper,
                                edge_color="blue",
                                face_color="paleturquoise",
                                bgcolor="white",
                                border_visible=True)
    price_plot.overlays.append(PlotAxis(price_plot, orientation='left')),

    # Set the plot's bottom axis to use the Scales ticking system
    bottom_axis = PlotAxis(
        price_plot,
        orientation="bottom",  # mapper=xmapper,
        tick_generator=ScalesTickGenerator(scale=CalendarScaleSystem()))
    price_plot.overlays.append(bottom_axis)
    hgrid, vgrid = add_default_grids(price_plot)
    vgrid.tick_generator = bottom_axis.tick_generator

    price_plot.tools.append(
        PanTool(price_plot, constrain=True, constrain_direction="x"))
    price_plot.overlays.append(
        ZoomTool(
            price_plot,
            drag_button="right",
            always_on=True,
            tool_mode="range",
            axis="index",
            max_zoom_out_factor=10.0,
        ))

    vol_plot = BarPlot(index=time_ds,
                       value=vol_ds,
                       index_mapper=xmapper,
                       value_mapper=vol_mapper,
                       line_color="transparent",
                       fill_color="black",
                       bar_width=1.0,
                       bar_width_type="screen",
                       antialias=False,
                       height=100,
                       resizable="h",
                       bgcolor="white",
                       border_visible=True)

    hgrid, vgrid = add_default_grids(vol_plot)
    # Use the same tick generator as the x-axis on the price plot
    vgrid.tick_generator = bottom_axis.tick_generator
    vol_plot.underlays.append(PlotAxis(vol_plot, orientation='left'))
    vol_plot.tools.append(
        PanTool(vol_plot, constrain=True, constrain_direction="x"))

    container = VPlotContainer(bgcolor="lightblue",
                               spacing=40,
                               padding=50,
                               fill_padding=False)
    container.add(vol_plot)
    container.add(price_plot)
    container.overlays.append(
        PlotLabel(
            "Financial Plot with Date Axis",
            component=container,
            #font="Times New Roman 24"))
            font="Arial 24"))

    return container
def _create_plot_component():

    # Create the data and datasource objects
    numpoints = 500
    index = arange(numpoints)
    returns = random.lognormal(0.01, 0.1, size=numpoints)
    price = 100.0 * cumprod(returns)
    volume = abs(random.normal(1000.0, 1500.0, size=numpoints) + 2000.0)

    time_ds = ArrayDataSource(index)
    vol_ds = ArrayDataSource(volume, sort_order="none")
    price_ds = ArrayDataSource(price, sort_order="none")

    xmapper = LinearMapper(range=DataRange1D(time_ds))
    vol_mapper = LinearMapper(range=DataRange1D(vol_ds))
    price_mapper = LinearMapper(range=DataRange1D(price_ds))

    price_plot = FilledLinePlot(index=time_ds,
                                value=price_ds,
                                index_mapper=xmapper,
                                value_mapper=price_mapper,
                                edge_color="blue",
                                face_color="paleturquoise",
                                alpha=0.5,
                                bgcolor="white",
                                border_visible=True)
    add_default_grids(price_plot)
    price_plot.overlays.append(PlotAxis(price_plot, orientation='left'))
    price_plot.overlays.append(PlotAxis(price_plot, orientation='bottom'))
    price_plot.tools.append(
        PanTool(price_plot, constrain=True, constrain_direction="x"))
    price_plot.overlays.append(
        ZoomTool(price_plot,
                 drag_button="right",
                 always_on=True,
                 tool_mode="range",
                 axis="index"))

    vol_plot = BarPlot(index=time_ds,
                       value=vol_ds,
                       index_mapper=xmapper,
                       value_mapper=vol_mapper,
                       line_color="transparent",
                       fill_color="black",
                       bar_width=1.0,
                       bar_width_type="screen",
                       antialias=False,
                       height=100,
                       resizable="h",
                       bgcolor="white",
                       border_visible=True)

    add_default_grids(vol_plot)
    vol_plot.underlays.append(PlotAxis(vol_plot, orientation='left'))
    vol_plot.tools.append(
        PanTool(vol_plot, constrain=True, constrain_direction="x"))

    container = VPlotContainer(bgcolor="lightblue",
                               spacing=20,
                               padding=50,
                               fill_padding=False)
    container.add(vol_plot)
    container.add(price_plot)
    container.overlays.append(
        PlotLabel(
            "Financial Plot",
            component=container,
            #font="Times New Roman 24"))
            font="Arial 24"))
    return container
Beispiel #27
0
    def _create_plot(self):
        plot_data = ArrayPlotData(image=self.image)
        plot = Plot(plot_data,
                    width=500,
                    height=500,
                    resizable='hv',
                    aspect_ratio=1.0,
                    padding=8,
                    padding_left=32,
                    padding_bottom=32)
        plot.img_plot('image',
                      colormap=jet,
                      xbounds=(self.X[0], self.X[-1]),
                      ybounds=(self.Y[0], self.Y[-1]),
                      name='image')
        image = plot.plots['image'][0]
        fitplot_data = ArrayPlotData(fitimage=self.fitimage)
        fitplot = Plot(fitplot_data,
                       width=500,
                       height=500,
                       resizable='hv',
                       aspect_ratio=1.0,
                       padding=8,
                       padding_left=32,
                       padding_bottom=32)
        fitplot.img_plot('fitimage',
                         colormap=jet,
                         xbounds=(self.Xfit[0], self.Xfit[-1]),
                         ybounds=(self.Yfit[0], self.Yfit[-1]),
                         name='fitimage')
        fitplot.overlays.insert(
            0,
            PlotLabel(text=self.label_text,
                      hjustify='right',
                      vjustify='bottom',
                      position=[880, 590]))
        fitimage = fitplot.plots['fitimage'][0]

        image.x_mapper.domain_limits = (self.confocal.scanner.getXRange()[0],
                                        self.confocal.scanner.getXRange()[1])
        image.y_mapper.domain_limits = (self.confocal.scanner.getYRange()[0],
                                        self.confocal.scanner.getYRange()[1])
        fitimage.x_mapper.domain_limits = (
            self.confocal.scanner.getXRange()[0],
            self.confocal.scanner.getXRange()[1])
        fitimage.y_mapper.domain_limits = (
            self.confocal.scanner.getYRange()[0],
            self.confocal.scanner.getYRange()[1])
        colormap = image.color_mapper
        colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                            color_mapper=colormap,
                            plot=plot,
                            orientation='v',
                            resizable='v',
                            width=16,
                            height=320,
                            padding=8,
                            padding_left=32)
        container = HPlotContainer()
        container.add(plot)
        container.add(colorbar)
        container.add(fitplot)

        container.tools.append(SaveTool(container))

        self.plot_data = plot_data
        self.scan_plot = image
        self.figure = plot
        self.fitplot_data = fitplot_data
        self.fitscan_plot = fitimage
        self.fitfigure = fitplot

        self.figure_container = container
Beispiel #28
0
    def _plot(self, x, y, z, scale):
        pd = ArrayPlotData()
        pd.set_data("imagedata", z)
        plot = Plot(pd, padding_left=60, fill_padding=True)
        plot.bgcolor = 'white'
        cmap = fix(jet, (0, z.max()))
        origin = 'bottom left' # origin = 'top left' # to flip y-axis
        plot.img_plot("imagedata", name="surface2d",
                      xbounds=(np.min(x), np.max(x)),
                      ybounds=(1.0, y[-1,-1]),
                      colormap=cmap, hide_grids=True, interpolation='nearest',
                      origin=origin,
                      )
        plot.default_origin = origin
        plot.x_axis.title = u'Angle (2\u0398)'

        tick_font = settings.tick_font
        plot.x_axis.title_font = settings.axis_title_font
        plot.y_axis.title_font = settings.axis_title_font
        plot.x_axis.tick_label_font = tick_font
        plot.y_axis.tick_label_font = tick_font
        plot.y_axis.title = "Dataset"
        plot.y_axis.tick_interval = 1.0
        actual_plot = plot.plots["surface2d"][0]

        self.plot_zoom_tool = ClickUndoZoomTool(
            plot, tool_mode="box", always_on=True, pointer="cross",
            drag_button=settings.zoom_button,
            undo_button=settings.undo_button,
            x_min_zoom_factor=-np.inf, y_min_zoom_factor=-np.inf,
        )
        plot.overlays.append(self.plot_zoom_tool)
        plot.tools.append(TraitsTool(plot))

        # Add a color bar
        colormap = actual_plot.color_mapper
        colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                        color_mapper=colormap,
                        plot=actual_plot,
                        orientation='v',
                        resizable='v',
                        width=30,
                        padding=40,
                        padding_top=50,
                        fill_padding=True)

        colorbar._axis.title_font = settings.axis_title_font
        colorbar._axis.tick_label_font = settings.tick_font
        # Add pan and zoom tools to the colorbar
        self.colorbar_zoom_tool = ClickUndoZoomTool(colorbar,
                                                    axis="index",
                                                    tool_mode="range",
                                                    always_on=True,
                                                    drag_button=settings.zoom_button,
                                                    undo_button=settings.undo_button)
        pan_tool = PanToolWithHistory(colorbar,
                                      history_tool=self.colorbar_zoom_tool,
                                      constrain_direction="y", constrain=True,
                                      drag_button=settings.pan_button)
        colorbar.tools.append(pan_tool)
        colorbar.overlays.append(self.colorbar_zoom_tool)

        # Add a label to the top of the color bar
        colorbar_label = PlotLabel(
            u'Intensity\n{:^9}'.format('(' + get_value_scale_label(scale) + ')'),
            component=colorbar,
            font=settings.axis_title_font,
        )
        colorbar.overlays.append(colorbar_label)
        colorbar.tools.append(TraitsTool(colorbar))

        # Add the plot and colorbar side-by-side
        container = HPlotContainer(use_backbuffer=True)
        container.add(plot)
        container.add(colorbar)
        return container
Beispiel #29
0
 def _image_label_default(self):
     return PlotLabel(text='',
                      color='red',
                      hjustify='left',
                      vjustify='bottom',
                      position=[10, 10])
Beispiel #30
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