Exemplo n.º 1
0
def _create_plot_component():
    # Create a GridContainer to hold all of our plots
    container = GridContainer(padding=20, fill_padding=True,
                              bgcolor="lightgray", use_backbuffer=True,
                              shape=(3,3), spacing=(12,12))

    # 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(9):
        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 = 10

        # Set each plot's aspect ratio based on its position in the
        # 3x3 grid of plots.
        n,m = divmod(i, 3)
        plot.aspect_ratio = float(n+1) / (m+1)

        # 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)
    return container
Exemplo n.º 2
0
def _create_plot_component():# Create a scalar field to colormap
    xbounds = (-2*pi, 2*pi, 600)
    ybounds = (-1.5*pi, 1.5*pi, 300)
    xs = linspace(*xbounds)
    ys = linspace(*ybounds)
    x, y = meshgrid(xs,ys)
    z = sin(x)*y

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("imagedata", z)

    # Create the plot
    plot = Plot(pd)
    img_plot = plot.img_plot("imagedata",
                             xbounds = xbounds[:2],
                             ybounds = ybounds[:2],
                             colormap=jet)[0]

    # Tweak some of the plot properties
    plot.title = "My First Image Plot"
    plot.padding = 50

    # Attach some tools to the plot
    plot.tools.append(PanTool(plot))
    zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
    plot.overlays.append(zoom)
    imgtool = ImageInspectorTool(img_plot)
    img_plot.tools.append(imgtool)
    overlay = ImageInspectorOverlay(component=img_plot, image_inspector=imgtool,
                                    bgcolor="white", border_visible=True)

    img_plot.overlays.append(overlay)
    return plot
Exemplo n.º 3
0
    def __init__(self, index, data_series, **kw):
        super(MyPlot, self).__init__(**kw)

        plot_data = ArrayPlotData(index=index)
        plot_data.set_data('data_series', data_series)
        self.plot = Plot(plot_data)
        self.plot.plot(('index', 'data_series'))
Exemplo n.º 4
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))
Exemplo n.º 5
0
    def plotImage(self, image, title, plot):
        '''plot one image
        image:     2d ndarray or ssp matrix
        title:     string, plot title
        plot:      plot instance to be update, if None, a plot instance will be created

        return:    plot instance'''
        if plot == None:
            pd = ArrayPlotData()
            pd.set_data('imagedata', image)
            plot = Plot(pd, default_origin = "bottom left")
            plot.title = title
            plot.bgcolor = 'white'
            if not title == 'Total Intensity':
                plot.x_axis.visible = False
                plot.y_axis.visible = False
                imgPlot = plot.img_plot("imagedata", colormap=jet, name='image')[0]
            # TODO: mess with color maps on else block    
            else:
                imgPlot = plot.img_plot("imagedata", colormap=jet, name='image')[0]

            self._appendTools(imgPlot, title)
        else:
            plot.data.set_data('imagedata', image)
            plot.title = title
        plot.aspect_ratio = float(image.shape[1]) / image.shape[0]
        plot.invalidate_draw()
        return plot
Exemplo n.º 6
0
 def update_labeled_image_data(self):
     im = self.image_data.arrays.get('im')[:, :, 0]
     bw = get_cleared_binary_image(im)
     bx, by = get_region_bounds(bw)
     apd = ArrayPlotData(im=bw)
     for i in range(len(bx)):
         minc, maxc = bx[i]
         minr, maxr = by[i]
         key = "bb" + str(i)
         apd.update({key + 'topx': (minc, maxc),
                     key + 'topy': (maxr, maxr),
                     key + 'botx': (minc, maxc),
                     key + 'boty': (minr, minr),
                     key + 'leftx': (minc, minc),
                     key + 'lefty': (minr, maxr),
                     key + 'rightx': (maxc, maxc),
                     key + 'righty': (minr, maxr)})
     plot = Plot(apd)
     plot.img_plot('im', colormap=gray, origin='bottom left')
     for i in range((len(apd.arrays) - 1) / 8):
         key = 'bb' + str(i)
         plot.plot((key + 'topx', key + 'topy'), color='green',
                   line_width=3)
         plot.plot((key + 'botx', key + 'boty'), color='green',
                   line_width=3)
         plot.plot((key + 'leftx', key + 'lefty'), color='green',
                   line_width=3)
         plot.plot((key + 'rightx', key + 'righty'), color='green',
                   line_width=3)
     self.labeled_image_plot = plot
Exemplo n.º 7
0
 def updateplots(self):
     x = np.sort(np.random.random(100))
     y = np.random.random(100)
     color = np.exp(-(x ** 2 + y ** 2))  # np.random.random(100)
     pd = ArrayPlotData()
     pd.set_data("index", x)
     pd.set_data("value", y)
     pd.set_data("color", color)
     # Create some line plots of some of the data
     plot = Plot(pd)
     # Create a scatter plot and get a reference to it (separate from the
     # Plot object) because we'll need it for the regression tool below.
     scatterplot = plot.plot(
         ("index", "value", "color"),
         type="cmap_scatter",
         color_mapper=reverse(Spectral),
         marker="square",
         fill_alpha=0.9,
         marker_size=6,
         bgcolor=QtGui.QColor(240, 240, 240),
     )[0]
     # Tweak some of the plot properties
     plot.padding = 50
     # Attach some tools to the plot
     plot.tools.append(PanTool(plot, drag_button="right"))
     plot.overlays.append(ZoomTool(plot))
     # Add the regression tool and overlay.  These need to be added
     # directly to the scatterplot instance (and not the Plot instance).
     regression = RegressionLasso(scatterplot, selection_datasource=scatterplot.index)
     scatterplot.tools.append(regression)
     scatterplot.overlays.append(RegressionOverlay(scatterplot, lasso_selection=regression))
     self.chaco_widget1.visualization.plot = plot
     self.chaco_widget2.visualization.plot = plot
Exemplo n.º 8
0
class DataChooser(HasTraits):

    plot = Instance(Plot)
    data_name = Enum("jn0", "jn1", "jn2")
    traits_view = View(Item('data_name', label="Y data"),
                       Item('plot', editor=ComponentEditor(), show_label=False),
                       width=800, height=600, resizable=True,
                       title="Data Chooser")

    def __init__(self):
        x = linspace(-5, 10, 100)
        self.data = {"jn0": jn(0, x),
                     "jn1": jn(1, x),
                     "jn2": jn(2, x)}

        # Create the data and the PlotData object
        self.plotdata = ArrayPlotData(x=x, y=self.data["jn0"])

        # Create a Plot and associate it with the PlotData
        plot = Plot(self.plotdata)
        # Create a line plot in the Plot
        plot.plot(("x", "y"), type="line", color="blue")
        self.plot = plot

    def _data_name_changed(self, old, new):
        self.plotdata.set_data("y", self.data[self.data_name])
Exemplo n.º 9
0
    def __init__(self):

        super(HHCurrentTraits, self).__init__()

        # gates
        self.vm = linspace(-120,65,1000)
        (M, N, H) = self.__gates()
        nA = self.__iv()
        self.gatedata = ArrayPlotData(x=self.vm, M=M, N=N, H=H)
        self.ivdata = ArrayPlotData(x=self.vm, nA=nA)
        
        gateplot = Plot(self.gatedata)
        gateplot.plot(("x", "M"), type = "line", color = "blue")
        gateplot.plot(("x", "N"), type = "line", color = "green")
        gateplot.plot(("x", "H"), type = "line", color = "red")

        ivplot = Plot(self.ivdata)
        ivplot.plot(("x", "nA"), type = "line", color = "black")

        container = VPlotContainer(ivplot, gateplot)
        container.spacing = 0
        gateplot.x_axis.orientation = "top"
        gateplot.padding_bottom = 0
        ivplot.padding_top = 0
        
        self.plots = container
Exemplo n.º 10
0
def _create_plot_component():
    # Create a scalar field to colormap
    xs = linspace(0, 10, 600)
    ys = linspace(0, 5, 600)
    x, y = meshgrid(xs,ys)
    z = exp(-(x**2+y**2)/100)

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("imagedata", z)

    # Create the plot
    plot = Plot(pd)
    img_plot = plot.img_plot("imagedata",
                             xbounds=(0, 10),
                             ybounds=(0, 5),
                             colormap=jet)[0]

    # Tweak some of the plot properties
    plot.title = "My First Image Plot"
    plot.padding = 50

    # Attach some tools to the plot
    plot.tools.append(PanTool(plot))
    zoom = ZoomTool(component=img_plot, tool_mode="box", always_on=False)
    img_plot.overlays.append(zoom)
    return plot
Exemplo n.º 11
0
def _create_plot_component():

    # Create some data
    numpts = 5000
    x = sort(random(numpts))
    y = random(numpts)

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

    # Create the plot
    plot = Plot(pd)
    plot.plot(("index", "value"),
              type="scatter",
              marker="circle",
              index_sort="ascending",
              color="orange",
              marker_size=3,
              bgcolor="white")

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

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

    return plot
Exemplo n.º 12
0
def _create_plot_component():

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

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

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

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

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

    return container
Exemplo n.º 13
0
    def __init__(self, index, series_a, series_b, series_c, **kw):
        super(PlotExample, self).__init__(**kw)

        plot_data = ArrayPlotData(index=index)
        plot_data.set_data('series_a', series_a)
        plot_data.set_data('series_b', series_b)
        plot_data.set_data('series_c', series_c)
        self.plot = Plot(plot_data)
        self.plot.plot(('index', 'series_a'), type='bar', bar_width=0.8, color='auto')
        self.plot.plot(('index', 'series_b'), type='bar', bar_width=0.8, color='auto')
        self.plot.plot(('index', 'series_c'), type='bar', bar_width=0.8, color='auto')

        # set the plot's value range to 0, otherwise it may pad too much
        self.plot.value_range.low = 0

        # replace the index values with some nicer labels
        label_axis = LabelAxis(self.plot, orientation='bottom',
                               title='Months',
                               positions = list(range(1, 10)),
                               labels = ['jan', 'feb', 'march', 'april', 'may'],
                               small_haxis_style=True)

        self.plot.underlays.remove(self.plot.index_axis)
        self.plot.index_axis = label_axis
        self.plot.underlays.append(label_axis)
Exemplo n.º 14
0
def _create_plot_component():

    # Create some RGBA image data
    image = zeros((200,400,4), dtype=uint8)
    image[:,0:40,0] += 255     # Vertical red stripe
    image[0:25,:,1] += 255     # Horizontal green stripe; also yellow square
    image[-80:,-160:,2] += 255 # Blue square
    image[:,:,3] = 255

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("imagedata", image)

    # Create the plot
    plot = Plot(pd, default_origin="top left")
    plot.x_axis.orientation = "top"
    img_plot = plot.img_plot("imagedata")[0]

    # Tweak some of the plot properties
    plot.bgcolor = "white"

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

    imgtool = ImageInspectorTool(img_plot)
    img_plot.tools.append(imgtool)
    plot.overlays.append(ImageInspectorOverlay(component=img_plot,
                                               image_inspector=imgtool))
    return plot
Exemplo n.º 15
0
Arquivo: quiver.py Projeto: 5n1p/chaco
    def _plot_default(self):
        # Create starting points for the vectors.
        numpts = self.numpts
        x = sort(random(numpts))
        y = random(numpts)

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

        data = ArrayPlotData()
        data.set_data('index', x)
        data.set_data('value', y)
        data.set_data('vectors', vectors)
        quiverplot = Plot(data)
        quiverplot.quiverplot(('index', 'value', 'vectors'))

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

        container = OverlayPlotContainer(quiverplot, padding=50)

        return container
Exemplo n.º 16
0
 def _plot_data_default(self):
     """Filling the ArrayPlotData before plotting"""
     data = ArrayPlotData()
     for i in range(self.polyg_nb):
         data.set_data("polyg"+str(i)+"_x", x_[i])
         data.set_data("polyg"+str(i)+"_y", y_[i])
     return data
Exemplo n.º 17
0
	def update_plotdata(self):
		''' This will create overwrite primary data sources!  Plots are programmed to redraw
		    when these are overwritten.  This should only occur when a global variable is changed
		    all local variabel changes are built into the plot objects already.'''

		#### ALL LISTENERS ARE HOOKED UP, THIS FUNCTION IS PROBABLY CAUSING THE ISSUE... MAYBE
		#### OVERWRITING THE DATA ARRAYS IS CAUSING THIS

		print 'Updating all ctprimary data sources'
	
		specdata=ArrayPlotData() 
		timedata=ArrayPlotData()

		xarray=linspace(0, len(self.x_label), len(self.x_label) )
		tarray=linspace(0, len(self.t_label), len(self.t_label) )

		specdata.set_data('x', xarray)
		timedata.set_data('x', tarray)        #TIME DATA NOT SET EXCEPT FOR LABE

		for i in range(len(tarray)):
			specdata.set_data(self.t_label[i], self.twoD_data_full[:,i])

		for i in range(len(xarray)):
			timedata.set_data(self.x_label[i], self.twoD_data_full[i,:])  #LABELS ARE STRINGED AS KEYS

		self.specdata=specdata ; self.timedata=timedata 
Exemplo n.º 18
0
    def plotImage(self, image, plot=None):
        '''plot one image
        image:     Image object
        plot:      plot instance to be update, if None, a plot instance will be created
        return:    plot instance'''
        if plot == None:
            pd = ArrayPlotData()
            pd.set_data('imagedata', image.data)
            plot = Plot(pd, default_origin = "bottom left", padding=0)
            #plot.title = image.name
            plot.bgcolor = 'white'
            plot.fixed_preferred_size = (100, 100)
            plot.x_axis.visible = False
            plot.y_axis.visible = False
            self.imageplot = plot

            # TODO: mess with color maps on else block    
            imgPlot = plot.img_plot("imagedata", colormap=jet, name='image')[0]
            self.imgPlot = imgPlot
            self._appendImageTools(imgPlot)
            #plot.overlays.append(MyLineDrawer(plot))
        else:
            plot.data.set_data('imagedata', image.data)
            imgPlot = plot.plots['image'][0]
            #plot.title = image.name
        plot.aspect_ratio = float(image.data.shape[1]) / image.data.shape[0]
        plot.invalidate_draw()
        return plot
Exemplo n.º 19
0
def createWindow(widget):
    ''' Example on creating a new plot window in the
        main window MDI-Area
    '''
    import plotWidget
    from PySide import QtGui
    from numpy import linspace
    from scipy.special import jn
    from chaco.api import ArrayPlotData, Plot

    window = widget.createNewWindow()
    container = plotWidget.plotContainer(window)
    plotWidget = plotWidget.PlotWidget(container)
    container.setPlotWidget(plotWidget)

    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))
    plot = Plot(pd, title=None, padding_left=60, padding_right=5, padding_top=5, padding_bottom=30, border_visible=True)
    plot.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")
    plotWidget.setPlot(plot)

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

        container = HPlotContainer()
        container.add(plot1)
        
        self.zoom.on_trait_change(self.selection_changed, 'ratio')
    
        return container
Exemplo n.º 21
0
def _create_plot_component():

    # Use n_gon to compute center locations for our polygons
    points = n_gon(center=(0,0), r=3, nsides=4)

    # Choose some colors for our polygons
    colors = {3:0xaabbcc,   4:'orange', 5:'yellow', 6:'lightgreen'}

    # Create a PlotData object to store the polygon data
    pd = ArrayPlotData()

    # Create a Polygon Plot to draw the regular polygons
    polyplot = Plot(pd)

    # Store path data for each polygon, and plot
    nsides = 3
    for p in points:
        npoints = n_gon(center=p, r=2, nsides=nsides)
        nxarray, nyarray = transpose(npoints)
        pd.set_data("x" + str(nsides), nxarray)
        pd.set_data("y" + str(nsides), nyarray)
        plot = polyplot.plot(("x"+str(nsides), "y"+str(nsides)), type="polygon",
                             face_color=colors[nsides], hittest_type="poly")[0]

        plot.tools.append(DataspaceMoveTool(plot, drag_button="left"))
        nsides = nsides + 1

    # Tweak some of the plot properties
    polyplot.padding = 50
    polyplot.title = "Polygon Plot"
    polyplot.x_axis.mapper.range.set(low=-10, high=10)
    polyplot.y_axis.mapper.range.set(low=-10, high=10)

    return polyplot
Exemplo n.º 22
0
 def _create_data(self, names):
     plotdata = ArrayPlotData(times = np.squeeze(dateArray))
     i = 0
     for name in names:
         plotdata.set_data(name, data[:,i])
         i += 1
     self.plotdata = plotdata
Exemplo n.º 23
0
def _create_plot_component():

    # Create some x-y data series (with NaNs) to plot
    x = linspace(-5.0, 15.0, 500)
    x[75:125] = nan
    x[200:250] = nan
    x[300:330] = nan
    pd = ArrayPlotData(index = x)
    pd.set_data("value1", jn(0, x))
    pd.set_data("value2", jn(1, x))

    # Create some line and scatter plots of the data
    plot = Plot(pd)
    plot.plot(("index", "value1"), name="j_0(x)", color="red", width=2.0)
    plot.plot(("index", "value2"), type="scatter", marker_size=1,
              name="j_1(x)", color="green")

    # Tweak some of the plot properties
    plot.title = "Plots with NaNs"
    plot.padding = 50
    plot.legend.visible = True

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

    return plot
Exemplo n.º 24
0
    def plotImage(self, image, plot=None):
        '''Plots a tiff image.

        |  image -- Image object
        |  plot  -- plot instance to be updated 
        |           if None, a plot instance will be created

        Returns the plot instance.
        '''
        if plot == None:
            pd = ArrayPlotData()
            pd.set_data('imagedata', image.data)
            plot = Plot(pd, default_origin = "bottom left", padding=0)
            plot.bgcolor = 'white'
            plot.fixed_preferred_size = (100, 100)
            plot.x_axis.visible = False
            plot.y_axis.visible = False
            self.imageplot = plot

            imgPlot = plot.img_plot("imagedata", colormap=self.cmap, 
                                                    name='image')[0]
            self.imgPlot = imgPlot
            self.appendImageTools(imgPlot)
        else:
            plot.data.set_data('imagedata', image.data)
        plot.aspect_ratio = float(image.data.shape[1]) / image.data.shape[0]
        plot.invalidate_and_redraw()
        return plot
Exemplo n.º 25
0
def _fuel_cycle_plot_component(x, y, x_name, y_name):
    # Create some data

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("index", x)
    pd.set_data("value", y)
    # Create the plot
    plot = Plot(pd)
    plot.plot(("index", "value"),
              type="line",
              marker="circle",
              index_sort="ascending",
              color="red",
              marker_size=3,
              bgcolor="white")
    # Tweak some of the plot properties
    plot.title = "Fuel Cycle Plot"
    plot.line_width = 0.5
    plot.padding = 100

    plot.x_axis.title = x_name
    plot.x_axis.title_font = "Roman 16"
    plot.x_axis.tick_label_font = "Roman 12"
        
    plot.y_axis.title = y_name
    plot.y_axis.title_font = "Roman 16"
    plot.y_axis.tick_label_font = "Roman 12"

    # Attach some tools to the plot
    plot.tools.append(PanTool(plot))
    zoom = ZoomTool(component=plot, tool_mode="box", always_on=False)
    plot.overlays.append(zoom)
   
    return plot
Exemplo n.º 26
0
    def _plot_default(self):
        # Create a GridContainer to hold all of our plots: 2 rows, 3 columns
        container = GridPlotContainer(shape=(2,3),
                                      spacing=(10,5),
                                      valign='top',
                                      bgcolor='lightgray')

        # Create x 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):
            data_name = 'y{}'.format(i)
            pd.set_data(data_name, jn(i,x))

            plot = Plot(pd)
            plot.plot(('index', data_name),
                      color=COLOR_PALETTE[i],
                      line_width=3.0)

            # Set each plot's aspect based on its position in the grid
            plot.set(height=((i % 3) + 1)*50,
                     resizable='h')

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

        return container
Exemplo n.º 27
0
class Viewer1D(Viewer):
    image = Array
    result = Array

    def _reconstruction_default(self):
        rows, cols = self.image.shape[:2]
        self.plot_data = ArrayPlotData(original=self.image[0],
                                       reconstruction=self.result[0])

        aspect = cols/float(rows)

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

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

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

        return container

    def update_plot(self):
        self.plot_data.set_data('reconstruction', self.result[0])
        self.new.request_redraw()
Exemplo n.º 28
0
def _create_plot_component():  # Create a scalar field to colormap
    xbounds = (-2 * pi, 2 * pi, 600)
    ybounds = (-1.5 * pi, 1.5 * pi, 300)
    xs = linspace(*xbounds)
    ys = linspace(*ybounds)
    x, y = meshgrid(xs, ys)
    z = sin(x) * y

    # Create a plot data obect and give it this data
    pd = ArrayPlotData()
    pd.set_data("imagedata", z)

    # Create the plot
    plot = Plot(pd)
    img_plot = plot.img_plot("imagedata", xbounds=xbounds[:2], ybounds=ybounds[:2], colormap=jet)[0]

    # Tweak some of the plot properties
    plot.title = "Image Plot with Lasso"
    plot.padding = 50

    lasso_selection = LassoSelection(component=img_plot)
    lasso_selection.on_trait_change(lasso_updated, "disjoint_selections")
    lasso_overlay = LassoOverlay(lasso_selection=lasso_selection, component=img_plot)
    img_plot.tools.append(lasso_selection)
    img_plot.overlays.append(lasso_overlay)
    return plot
Exemplo n.º 29
0
class Plotter():
    def __init__(self, parent):
        self.plotdata = ArrayPlotData(x=array([]),  y=array([]))
        self.window = self.create_plot(parent)
        self.widget = self.window.control
        
    def update_data(self, x, y):
        self.plotdata.set_data("x", x)
        self.plotdata.set_data("y", y)

    def create_plot(self, parent):
		x = linspace(-2.0, 10.0, 100)
		pd = ArrayPlotData(index = x)
		for i in range(5):
			pd.set_data("y" + str(i), jn(i,x))

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

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

		# This Window object bridges the Enable and Qt4 worlds, and handles events
		# and drawing.  We can create whatever hierarchy of nested containers we
		# want, as long as the top-level item gets set as the .component attribute
		# of a Window.
		return Window(parent, -1, component=plot)
Exemplo n.º 30
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, padding=50)
    plot1.plot(("index", "y0", "y1", "y2"), name="j_n, n<3", color="red")
    plot1.plot(("index", "y3"), name="j_3", color="blue")

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

    # Add the scrollbar
    hscrollbar = PlotScrollBar(component=plot1, axis="index", resizable="h",
                               height=15)
    plot1.padding_top = 0
    hscrollbar.force_data_update()

    # Create a container and add our plots
    container = VPlotContainer()
    container.add(plot1)
    container.add(hscrollbar)

    return container
Exemplo n.º 31
0
 def __init__(self):
     # Create the data and the PlotData object.  For a 2D plot, we need to
     # take the row of X points and Y points and create a grid from them
     # using meshgrid().
     x = linspace(0, 8, 50)
     y = linspace(0, 6, 50)
     xgrid, ygrid = meshgrid(x, y)
     z = exp(-(xgrid * xgrid + ygrid * ygrid) / 100)
     plotdata = ArrayPlotData(imagedata=z)
     # Create a Plot and associate it with the PlotData
     plot = Plot(plotdata)
     # Create an image plot in the Plot
     self.renderer = plot.img_plot("imagedata",
                                   name="plot1",
                                   xbounds=xgrid,
                                   ybounds=ygrid,
                                   colormap=jet)[0]
     self.plot = plot
Exemplo n.º 32
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
Exemplo n.º 33
0
    def _create_filter_function_plot(self):
        plot_data_filter_function = ArrayPlotData(freq=np.array((0., 1.)),
                                                  value=np.array((0., 0.)),
                                                  fit=np.array((0., 0.)))
        plot = Plot(plot_data_filter_function,
                    width=50,
                    height=40,
                    padding=8,
                    padding_left=64,
                    padding_bottom=32)
        plot.plot(('freq', 'value'), color='red', type='line', line_width=3)
        plot.index_axis.title = 'frequency [MHz]'
        plot.value_axis.title = 'Filter Function Fourier Transform'
        #plot.title='Fourier transform of filter function'

        self.plot_data_filter_function = plot_data_filter_function
        self.filter_function_plot = plot
        return self.filter_function_plot
Exemplo n.º 34
0
 def _create_matrix_plot(self):
     matrix_data = ArrayPlotData(image=np.zeros((2, 2)))
     plot = Plot(matrix_data,
                 width=500,
                 height=500,
                 resizable='hv',
                 padding=8,
                 padding_left=48,
                 padding_bottom=36)
     plot.index_axis.title = 'time [ns]'
     plot.value_axis.title = 'laser pulse #'
     plot.img_plot('image',
                   xbounds=(0, 1),
                   ybounds=(0, 1),
                   colormap=Spectral)[0]
     plot.tools.append(SaveTool(plot))
     self.matrix_data = matrix_data
     self.matrix_plot = plot
Exemplo n.º 35
0
 def _create_pulse_plot(self):
     pulse_data = ArrayPlotData(x=np.array((0., 100)), y=np.array((0, 1)))
     plot = Plot(pulse_data, padding=8, padding_left=64, padding_bottom=36)
     line = plot.plot(('x', 'y'), style='line', color='blue',
                      name='data')[0]
     plot.index_axis.title = 'time bins'
     plot.value_axis.title = 'intensity'
     edge_marker = LinePlot(
         index=ArrayDataSource(np.array((0, 0))),
         value=ArrayDataSource(np.array((0, 1e9))),
         color='red',
         index_mapper=LinearMapper(range=plot.index_range),
         value_mapper=LinearMapper(range=plot.value_range),
         name='marker')
     plot.add(edge_marker)
     plot.tools.append(SaveTool(plot))
     self.pulse_data = pulse_data
     self.pulse_plot = plot
Exemplo n.º 36
0
  def __init__(self, link):
    super(BaselineView, self).__init__()

    self.log_file = None

    self.num_hyps = 0

    self.plot_data = ArrayPlotData(n=[0.0], e=[0.0], d=[0.0], t=[0.0], ref_n=[0.0], ref_e=[0.0], ref_d=[0.0])
    self.plot = Plot(self.plot_data)

    self.plot.plot(('e', 'n'), type='line', name='line', color=(0, 0, 0, 0.1))
    self.plot.plot(('e', 'n'), type='scatter', name='points', color='blue', marker='dot', line_width=0.0, marker_size=1.0)
    self.plot.plot(('ref_e', 'ref_n'),
        type='scatter',
        color='red',
        marker='plus',
        marker_size=5,
        line_width=1.5
    )

    self.plot.index_axis.tick_label_position = 'inside'
    self.plot.index_axis.tick_label_color = 'gray'
    self.plot.index_axis.tick_color = 'gray'
    self.plot.value_axis.tick_label_position = 'inside'
    self.plot.value_axis.tick_label_color = 'gray'
    self.plot.value_axis.tick_color = 'gray'
    self.plot.padding = (0, 1, 0, 1)

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

    self.week = None
    self.nsec = 0

    self.link = link
    self.link.add_callback(sbp_messages.SBP_BASELINE_NED, self._baseline_callback_ned)
    self.link.add_callback(sbp_messages.SBP_BASELINE_ECEF, self._baseline_callback_ecef)
    self.link.add_callback(sbp_messages.IAR_STATE, self.iar_state_callback)
    self.link.add_callback(sbp_messages.SBP_GPS_TIME, self.gps_time_callback)

    self.python_console_cmds = {
      'baseline': self
    }
Exemplo n.º 37
0
    def __init__(self, link):
        super(MagView, self).__init__()

        self.mag = np.zeros((NUM_POINTS, 3))

        self.plot_data = ArrayPlotData(t=np.arange(NUM_POINTS),
                                       mag_x=[0.0],
                                       mag_y=[0.0],
                                       mag_z=[0.0])

        self.plot = Plot(self.plot_data,
                         auto_colors=colours_list,
                         emphasized=True)
        self.plot.title = 'Raw Magnetometer Data'
        self.plot.title_color = [0, 0, 0.43]
        self.plot.value_axis.orientation = 'right'
        self.plot.value_axis.axis_line_visible = False
        call_repeatedly(0.2, self.mag_set_data)

        self.legend_visible = True
        self.plot.legend.visible = True
        self.plot.legend.align = 'll'
        self.plot.legend.line_spacing = 1
        self.plot.legend.font = 'modern 8'
        self.plot.legend.draw_layer = 'overlay'
        self.plot.legend.tools.append(
            LegendTool(self.plot.legend, drag_button="right"))

        mag_x = self.plot.plot(('t', 'mag_x'),
                               type='line',
                               color='auto',
                               name='Mag. X (uT)')
        mag_y = self.plot.plot(('t', 'mag_y'),
                               type='line',
                               color='auto',
                               name='Mag. Y (uT)')
        mag_z = self.plot.plot(('t', 'mag_z'),
                               type='line',
                               color='auto',
                               name='Mag. Z (uT)')

        self.link = link
        self.link.add_callback(self.mag_raw_callback, SBP_MSG_MAG_RAW)
        self.python_console_cmds = {'track': self}
Exemplo n.º 38
0
 def addVariable(self, model, variable):
     dPoints = 1
     if not self.plotActive:
         self.activatePlot()
     PlotWidget.addVariable(self, model, variable)
     if (model.integrationResults.isAvailable):
         y, x, interpolationMethod = model.integrationResults.readData(variable)
         if len(x) > self.maxDisplayPoints:
             dPoints = max(1, math.ceil(float(len(x)) / self.maxDisplayPoints))
             x = x[::dPoints]
             y = y[::dPoints]
     else:
         return
     if (self.plot.data == None):
             self.plot.data = ArrayPlotData()
     if not x == None and not y == None:
         self.plot.data.set_data(model.numberedModelName + ":" + variable + ".values", x)
         self.plot.data.set_data(model.numberedModelName + ":" + variable + ".time", y)
         lPlots = self.plot.legend.plots
         name = self._idVariableUnit(model, variable)
         color, style = getColor(self.plot.plots)
         p = self.plot.plot((model.numberedModelName + ":" + variable + ".time", model.numberedModelName + ":" + variable + ".values"), name=name, color=color, linestyle=style, line_width=1.5, render_style=("connectedhold" if interpolationMethod == "constant" else "connectedpoints"))
         legendLabel = self._idVariableUnit(model, variable, dPoints)
         if not hasattr(self.plot, 'legendLabel'):
             self.plot.legendLabel = dict()
         self.plot.legendLabel[name] = legendLabel
         self.plot.legend.labels.append(legendLabel)
         self.plot.legend.plots = lPlots
         self.plot.legend.plots[legendLabel] = p
     if y == None and not x == None:
         self.plot.data.set_data(model.numberedModelName + ":" + variable + ".values", x)
         self.plot.data.set_data(model.numberedModelName + ":" + variable + ".time", [0])
         lPlots = self.plot.legend.plots
         name = self._idVariableUnit(model, variable)
         color, style = getColor(self.plot.plots)
         p = self.plot.add_xy_plot(model.numberedModelName + ":" + variable + ".time", model.numberedModelName + ":" + variable + ".values", ConstPlot, name=name, color=color, linestyle=style, line_width=1.5)
         legendLabel = self._idVariableUnit(model, variable, dPoints)
         if not hasattr(self.plot, 'legendLabel'):
             self.plot.legendLabel = dict()
         self.plot.legendLabel[name] = legendLabel
         self.plot.legend.labels.append(legendLabel)
         self.plot.legend.plots = lPlots
         self.plot.legend.plots[legendLabel] = p
     self.plot.request_redraw()
Exemplo n.º 39
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
Exemplo n.º 40
0
    def _plot_factory(self, legend_kw=None, **kw):
        """
        """
        p = Plot(data=ArrayPlotData(), **kw)

        vis = kw.get('show_legend', False)

        if not isinstance(vis, bool):
            align = vis
            vis = True
        else:
            align = 'lr'

        p.legend.visible = vis
        p.legend.align = align
        if legend_kw:
            p.legend.trait_set(**legend_kw)

        return p
Exemplo n.º 41
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)
Exemplo n.º 42
0
 def _create_line_plot(self):
     line_data = ArrayPlotData(index=np.array((0, 1)),
                               counts=np.array((0, 0)),
                               pulse_indices=np.array((0, 0)),
                               pulse_values=np.array((0, 0)))
     plot = Plot(line_data, padding=8, padding_left=64, padding_bottom=36)
     plot.plot(('index', 'counts'), color='blue', name='counts')
     plot.plot(('pulse_indices', 'pulse_values'),
               type='scatter',
               marker='circle',
               color='none',
               outline_color='red',
               line_width=1.0,
               name='pulses')
     plot.index_axis.title = 'time [ns]'
     plot.value_axis.title = 'spin state'
     #plot.overlays.insert(0, PlotLabel(text=self.label_text, hjustify='left', vjustify='bottom', position=[64,32]) )
     self.line_data = line_data
     self.line_plot = plot
def _create_plot_component():
    # make 10 random points
    x = arange(10)
    x = ArrayDataSource(x, sort_order="ascending")
    y = random_sample(10)

    # Plot the data
    pd = ArrayPlotData(x=x, y=y)

    plot = Plot(pd)
    plot.orientation = 'v'
    line_plot = plot.plot(("x", "y"))[0]

    # Add the tool to the plot both as a tool and as an overlay
    tool = HittestTool(component=plot, line_plot=line_plot)
    plot.tools.append(tool)
    plot.overlays.append(tool)

    return plot
Exemplo n.º 44
0
    def _create_normxy8_plot(self):
        plot_data_normxy8_line = ArrayPlotData(normalized_counts=np.array(
            (0., 1.)),
                                               time=np.array((0., 0.)),
                                               fit=np.array((0., 0.)))
        plot = Plot(plot_data_normxy8_line,
                    width=50,
                    height=40,
                    padding=8,
                    padding_left=64,
                    padding_bottom=32)
        plot.plot(('time', 'normalized_counts'), color='green', line_width=2)
        plot.index_axis.title = 't_prime [ns]'
        plot.value_axis.title = 'f(t, t_prime)'
        #plot.title='normalized counts'

        self.plot_data_normxy8_line = plot_data_normxy8_line
        self.normxy8_plot = plot
        return self.normxy8_plot
    def _cost_plot_data_default(self):
        if self.cost_data is None or len(self.cost_data) == 0:
            return

        self.reset_filtered_cost_data()

        cols = {}
        # Collect 1D arrays
        for col_name in self.filtered_cost_data.columns:
            if col_name != SIM_COL_NAME:
                cols[col_name] = self.filtered_cost_data[col_name].values

        # Collect 2D arrays if y_axis_param not set as output:
        if self.y_axis_param in self.param_list:
            cost_data_2d = self.pivot_filtered_data()
            cols[TWO_D_DATA_NAME] = cost_data_2d.values

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

        self.plot = container
Exemplo n.º 47
0
def plot_factory(legend_kw=None, **kw):
    """
    """
    p = Plot(data=ArrayPlotData(), **kw)

    vis = kw['show_legend'] if 'show_legend' in kw else False

    if not isinstance(vis, bool):
        align = vis
        vis = True
    else:
        align = 'lr'

    p.legend.visible = vis
    p.legend.align = align
    if legend_kw:
        p.legend.trait_set(**legend_kw)

    return p
Exemplo n.º 48
0
    def __init__(self, time, buy, sell, weighted_buy, weighted_sell):

        t = numpy.array(time)       # Convert lists to numpy arrays in preparation for plotting
        b = numpy.array(buy)
        s = numpy.array(sell)
        wb = numpy.array(weighted_buy)
        ws = numpy.array(weighted_sell)

        self.t = t
        self.b = b
        self.s = s

        plot_data = ArrayPlotData(t=t, b=b, s=s, wb=wb, ws=ws)

        plot = Plot(plot_data)
        self.plot = plot

        # Calculate range of plot so it shows latest 1 day of data
        end = t[-1]
        start = end - 86400

        self._configure_plot(plot, start, end)

        # Scatter point for prices
        buy_renderer = plot.plot(("t", "b"), type="scatter", color=RED)[0]
        sell_renderer = plot.plot(("t", "s"), type="scatter", color=GREEN)[0]

        # Line plot to connect the scatter points together
        plot.plot(("t", "b"), type="line", color=LIGHT_RED)        # Using RGBA color tuple to get a lighter color
        plot.plot(("t", "s"), type="line", color=LIGHT_GREEN)

        # Line plot of moving average of prices (thicker to indicate this fact)
        plot.plot(("t", "wb"), type="line", color=RED, line_width=2)
        plot.plot(("t", "ws"), type="line", color=GREEN, line_width=2)

        buy_renderer.marker_size = 3
        buy_renderer.marker = "circle"

        sell_renderer.marker_size = 3
        sell_renderer.marker = "circle"

        plot.title = "Current Price - Buy: ${} - Sell: ${}".format(buy[-1], sell[-1])       # Display current price in title
Exemplo n.º 49
0
    def _RegionsPlot_default(self):

        plotdata = ArrayPlotData(imagedata=self.RegionsAndLabels[0],
                                 x=self.XPositions,
                                 y=self.YPositions)
        plot = Plot(plotdata, width=500, height=500, resizable='hv')
        RegionsImage = plot.img_plot(
            'imagedata',
            colormap=gray,
            xbounds=(self.X[0], self.X[-1]),
            ybounds=(self.Y[0], self.Y[-1]),
        )[0]
        RegionsImage.x_mapper.domain_limits = (self.X[0], self.X[-1])
        RegionsImage.y_mapper.domain_limits = (self.Y[0], self.Y[-1])
        RegionsImage.overlays.append(ZoomTool(RegionsImage))

        scatterplot = plot.plot(('x', 'y'),
                                type='scatter',
                                marker='plus',
                                color='yellow')

        colormap = RegionsImage.color_mapper
        colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                            color_mapper=colormap,
                            plot=plot,
                            orientation='v',
                            resizable='v',
                            width=10,
                            padding=20)
        colorbar.padding_top = plot.padding_top
        colorbar.padding_bottom = plot.padding_bottom

        self.RegionsData = plotdata
        self.RegionsImage = RegionsImage

        container = HPlotContainer(padding=20,
                                   fill_padding=True,
                                   use_backbuffer=True)
        container.add(colorbar)
        container.add(plot)

        return container
Exemplo n.º 50
0
   def createPlot( self, showDataTag ):
      
      # picks the desired channel out of the interleaved data
      stride = self.header.getChannels()

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

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

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

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

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

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

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

      colorbar = self.createColorbar( plot.color_mapper )
      container = HPlotContainer( use_backbuffer = True )
      container.add( plot )
      container.add( colorbar )
      
      return container
Exemplo n.º 51
0
 def _plot_data_default(self):
     self.debug_print('_plot_data_default')
     data = ArrayPlotData()
     data['abscissa'] = []
     data['ordinate'] = []
     data['time'] = []
     data['axspan_y_lim'] = [-800, 800, 800, -800]
     self.data_to_keep.append('axspan_y_lim')
     data['x'] = []
     data['y'] = []
     data['scan_x'] = []
     data['scan_y'] = []
     data['pause_x'] = []
     data['pause_y'] = []
     data['cl_abscissa'] = []
     data['cl_ordinate'] = []
     data['cl_time'] = []
     data['cl_x'] = []
     data['cl_y'] = []
     return data
Exemplo n.º 52
0
 def _create_xy8_plot(self):
     plot_data_xy8_line = ArrayPlotData(counts2=np.array((0., 1.)),
                                        time=np.array((0., 0.)),
                                        fit=np.array((0., 0.)),
                                        time1=np.array((0., 0.)),
                                        point_x=np.array((0., 0.)),
                                        point_y=np.array((0., 0.)))
     plot = Plot(plot_data_xy8_line,
                 width=50,
                 height=40,
                 padding=8,
                 padding_left=64,
                 padding_bottom=32)
     plot.plot(('time', 'counts2'), color='green', line_width=2)
     plot.index_axis.title = 'time [ns]'
     plot.value_axis.title = 'counts'
     #plot.title='counts'
     self.plot_data_xy8_line = plot_data_xy8_line
     self.xy8_plot = plot
     return self.xy8_plot
Exemplo n.º 53
0
    def _plot_default(self):
        x = linspace(-14, 14, 100)
        y = sin(x) * x**3
        plotdata = ArrayPlotData(x=x, y=y)

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

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

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

        scatter.padding_right = 0

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

        return container
Exemplo n.º 54
0
    def _plot_default(self):
        x = np.linspace(0, 2 * np.pi)
        plotdata = ArrayPlotData(x=x, y=np.sin(x))
        plot = Plot(plotdata)
        plot.plot(('x', 'y'), type='line')

        plot.tools.append(ZoomTool(plot))
        plot.tools.append(PanTool(plot))

        # A standard minor plot axis.
        xminor = MinorPlotAxis(
            orientation='bottom',
            mapper=plot.x_mapper,
            component=plot,
        )
        plot.underlays.append(xminor)

        # A customized minor plot axis.
        yminor = MinorPlotAxis(
            orientation='left',
            mapper=plot.y_mapper,
            component=plot,
            tick_color='red',
            tick_weight=2,
            tick_in=4,
            tick_out=2,
        )

        # To avoid the (heavily customized) minor axis painting over the major
        # axis, we insert it at the front of the underlays array, so that it
        # gets drawn ahead of everything else.
        plot.underlays.insert(0, yminor)

        # Customizations for the y-major axis to make it stand out a little.
        ymajor = plot.y_axis
        ymajor.tick_color = 'blue'
        ymajor.tick_weight = 3
        ymajor.tick_in = 7
        ymajor.tick_out = 3

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

        self._add_tools(self.plot)

        self.container.add(plot)
        self.container.request_redraw()
Exemplo n.º 56
0
    def __init__(self):
        x = linspace(-14, 14, 100)
        y = sin(x) * x**3
        plotdata = ArrayPlotData(x=x, y=y)

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

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

        self.container = HPlotContainer(scatter, line)

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

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

        #scatter.range2d = line.range2d
        scatter.index_range = line.index_range
Exemplo n.º 57
0
    def test_initialize_range_from_manual_plot_with_transform(self):
        style = SingleLinePlotStyle()
        plot = Plot(ArrayPlotData(x=[1.1, 2.1], y=[3.1, 4.1]))
        plot.plot(("x", "y"))

        self.assertNotEqual(style.x_axis_style.range_low, 1.1)
        self.assertNotEqual(style.x_axis_style.range_high, 2.1)
        self.assertNotEqual(style.y_axis_style.range_low, 3.1)
        self.assertNotEqual(style.y_axis_style.range_high, 4.1)

        self.assertNotEqual(style.x_axis_style.auto_range_low, 1.1)
        self.assertNotEqual(style.x_axis_style.auto_range_high, 2.1)
        self.assertNotEqual(style.y_axis_style.auto_range_low, 3.1)
        self.assertNotEqual(style.y_axis_style.auto_range_high, 4.1)

        style.initialize_axis_ranges(plot)

        self.assertEqual(style.x_axis_style.range_low, 1.1)
        self.assertEqual(style.x_axis_style.range_high, 2.1)
        self.assertEqual(style.y_axis_style.range_low, 3.1)
        self.assertEqual(style.y_axis_style.range_high, 4.1)

        self.assertEqual(style.x_axis_style.auto_range_low, 1.1)
        self.assertEqual(style.x_axis_style.auto_range_high, 2.1)
        self.assertEqual(style.y_axis_style.auto_range_low, 3.1)
        self.assertEqual(style.y_axis_style.auto_range_high, 4.1)

        # Initialize rounding numbers at the integer level:
        style.range_transform = lambda x: int(x)
        style.initialize_axis_ranges(plot)

        self.assertEqual(style.x_axis_style.range_low, 1)
        self.assertEqual(style.x_axis_style.range_high, 2)
        self.assertEqual(style.y_axis_style.range_low, 3)
        self.assertEqual(style.y_axis_style.range_high, 4)

        self.assertEqual(style.x_axis_style.auto_range_low, 1)
        self.assertEqual(style.x_axis_style.auto_range_high, 2)
        self.assertEqual(style.y_axis_style.auto_range_low, 3)
        self.assertEqual(style.y_axis_style.auto_range_high, 4)
Exemplo n.º 58
0
	def _data_default(self):
		data = ArrayPlotData()
		
		# set bins
		min_bin, max_bin = self._get_minmax()
		x = 10 ** np.linspace(min_bin, max_bin, self.n_bins)
		data.set_data("bins", x[:-1])

		# set freqs
		for sample_name in self._samples:
			samples = self._samples[sample_name]
			freqs, bin_edges = np.histogram(samples, bins=x)
			probs = freqs / float(self.n_sims)
			data.set_data(sample_name, probs)

		return data
Exemplo n.º 59
0
class Viewer(HasTraits):
    """
    """

    def __init__(self, *args, **kw):
        super(Viewer, self).__init__(*args, **kw)

        self.pd = ArrayPlotData()
        self.pd.set_data('index', [])
        self.pd.set_data('sindex', [])

        self.pd.set_data('intensity', [])
        self.pd.set_data('sintensity', [])

        self.plot = Plot(data=self.pd)
        self.plot.value_range.tight_bounds = False
        self.plot.value_range.margin = 0.25
        self.plot.plot(('index','intensity'), type='scatter', marker='circle', marker_size=1.5)
        self.plot.plot(('sindex','sintensity'), color='green', line_width=1.5)

    def traits_view(self):
        v = View(UItem('plot', editor=ComponentEditor()))
        return v
Exemplo n.º 60
0
    def get_colorbar_plot(self, bounds=(0, 1)):
        """
        Create a colorbar plot to be added to a plot-container
        
        Arguments:
        bounds -- (min, max) tuple sets the intensity range for the colormap
        
        Returns a Chaco2 Plot object containing the colorbar.        
        """
        cb_rgba = array_to_rgba(N.repeat(N.linspace(1, 0, num=1024)[:,
                                                                    N.newaxis],
                                         20,
                                         axis=1),
                                cmap=self.get_colormap_object())
        if self._cbar_orientation is 'h':
            cb_rgba = cb_rgba.T[::-1]
        data = ArrayPlotData(colorbar=cb_rgba)

        # Create the plot object
        cb = Plot(data,
                  width=self._cbar_width,
                  resizable=self._cbar_orientation,
                  padding_left=0,
                  padding_top=0)
        cb.img_plot('colorbar',
                    name='colorbar',
                    xbounds=bounds,
                    ybounds=bounds,
                    origin='top left')

        # Plot tweaks
        if self._cbar_orientation is 'v':
            cb.x_axis.visible = False
            cb.y_axis.orientation = 'right'
        else:
            cb.y_axis.visible = False
            cb.x_axis.orientation = 'bottom'

        return cb