Beispiel #1
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
Beispiel #2
0
    def _plot_default(self):
        plotter = Plot(data=self.data)
        main_plot = plotter.plot(['x','y'])[0]
        self.configure_plot(main_plot, xlabel='')

        plotter2 = Plot(data=self.data)
        zoom_plot = plotter2.plot(['x','y'])[0]
        self.configure_plot(zoom_plot)
        
        outer_container = VPlotContainer(padding=20,
                                         fill_padding=True,
                                         spacing=0,
                                         stack_order='top_to_bottom',
                                         bgcolor='lightgray',
                                         use_backbuffer=True)

        outer_container.add(main_plot)
        outer_container.add(zoom_plot)
        # FIXME: This is set to the windows bg color.  Should get from the system.
        #outer_container.bgcolor = (236/255., 233/255., 216/255., 1.0)

        main_plot.controller = RangeSelection(main_plot)
        
        zoom_overlay = ZoomOverlay(source=main_plot, destination=zoom_plot)
        outer_container.overlays.append(zoom_overlay)

        return outer_container
Beispiel #3
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
Beispiel #4
0
 def _sig_phase_plot_default(self):
     plot = Plot(self.plot_data, padding=[75, 25, 25, 50],
                 title='Signal Spectrum')
     plot.plot(('frequency', 'sig_phase'), index_scale='log', color='black')
     plot.index_axis.title = 'Frequency (Hz)'
     plot.value_axis.title = 'Power (dB)'
     return plot
Beispiel #5
0
def _create_plot_component():

    # Create a random scattering of XY pairs
    x = random.uniform(0.0, 10.0, 50)
    y = random.uniform(0.0, 5.0, 50)
    pd = ArrayPlotData(x=x, y=y)
    plot = Plot(pd, border_visible=True, overlay_border=True)

    scatter = plot.plot(("x", "y"), type="scatter", color="lightblue")[0]

    # Tweak some of the plot properties
    plot.set(title="Scatter Inspector Demo", padding=50)

    # Attach some tools to the plot
    plot.tools.append(PanTool(plot))
    plot.overlays.append(ZoomTool(plot))

    # Attach the inspector and its overlay
    scatter.tools.append(ScatterInspector(scatter))
    overlay = ScatterInspectorOverlay(
        scatter,
        hover_color="red",
        hover_marker_size=6,
        selection_marker_size=6,
        selection_color="yellow",
        selection_outline_color="purple",
        selection_line_width=3,
    )
    scatter.overlays.append(overlay)

    return plot
Beispiel #6
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()
    def _interp_data_button_fired(self):
        x = [row.x for row in self.rows]
        y = [row.y for row in self.rows]

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

        print y2

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

        test_plot = Plot(plotdata)
        test_plot.plot(("x", "y"), type="scatter")
        test_plot.plot(("x", "y"), type="line")
        test_plot_2 = Plot(plotdata2)
        # test_plot_2.plot("y2", type="line")
        # changing type to line w)ill make the
        # plot a line plot! not recommended!
        """
        test_plot = plot(x,y,"b-", bgcolor="white")
        test_plot.hold()
        test_plot = plot(x,y2,"g-")
        """
        container = HPlotContainer(test_plot)  # ,test_plot_2)
        self.aplot = container
Beispiel #8
0
def create_chaco_plot(parent, data, args, type=''):
    #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))
    #if not type:
    #    type = ['plot']
    #else:
    #    type = [type, 'plot']
    # Create some line plots of some of the data
    plot = Plot(data, title="Line Plot", padding=50, border_visible=True)
    plot.legend.visible = True
    #plot_fn = getattr(plot, '_'.join(type))
    if type:
        renderers = plot.plot(args, plot=type)
    else:
        renderers = plot.plot(args)
    #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)
    plot.tools.append(TraitsTool(component=plot))

    # 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)
Beispiel #9
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
    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))
Beispiel #11
0
class PlotExample(HasTraits):
    plot = Instance(Plot)
    traits_view = View(UItem('plot', editor=ComponentEditor()),
                       width=400, height=400, resizable=True, 
                      )

    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)
Beispiel #12
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
 def _plot_default(self):
     data = ArrayPlotData(x=self.model.x, y=self.model.y)
     plot = Plot(data)
     plot.plot(('x', 'y'), style='line', color='green')
     plot.value_range.set_bounds(-self.model.a, self.model.a)
     plot.title = "a * exp(-b*x) * cos(omega*x + phase)"
     return plot
Beispiel #14
0
def _create_plot_component(obj):
    # Spectrogram plot

    obj.data = fr.getDataSets(".chi")
    frequencies = obj.data[0][0]
    index = ArrayDataSource(data=frequencies)

    values = [obj.data[i][1] for i in xrange(len(obj.data))]
    print len(obj.data[1][1])
    print len(obj.data)
    p = WaterfallRenderer(
        index=index,
        values=values,
        index_mapper=LinearMapper(range=DataRange1D(low=0, high=SPECTROGRAM_LENGTH)),
        value_mapper=LinearMapper(range=DataRange1D(low=0, high=SPECTROGRAM_LENGTH)),
        x2_mapper=LinearMapper(low_pos=0, high_pos=100, range=DataRange1D(low=10.0, high=101.0)),
        y2_mapper=LinearMapper(low_pos=0, high_pos=100, range=DataRange1D(low=0, high=600000)),
    )
    spectrogram_plot = p
    obj.spectrogram_plot = p
    dummy = Plot()
    dummy.padding = 50
    dummy.index_axis.mapper.range = p.index_mapper.range
    dummy.index_axis.title = "Frequency (hz)"
    dummy.add(p)

    c2 = VPlotContainer()
    c2.add(dummy)

    return c2
Beispiel #15
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
Beispiel #16
0
    def _ch_plot_default(self):
        x = 0.26
        y = 0.
        h_cross_x = np.array([self.x_low, self.x_high])
        h_cross_y = np.array([y, y])
        v_cross_x = np.array([x, x])
        v_cross_y = np.array([self.y_low, self.y_high])

        cross_hair_data = ArrayPlotData(h_cross_x=h_cross_x,
                                        h_cross_y=h_cross_y,
                                        v_cross_x=v_cross_x,
                                        v_cross_y=v_cross_y)
        ch_plot = Plot(cross_hair_data)
        ch_plot.plot(("h_cross_x", "h_cross_y"), type="line", color="green",)
        ch_plot.plot(("v_cross_x", "v_cross_y"), type="line", color="green",)
        while len(ch_plot.underlays) > 0:
            ch_plot.underlays.pop(0)
        ch_plot.range2d = self.img_plot.range2d
        cross_hair_tool = CrossHairs(ch_plot)
        ch_plot.tools.append(cross_hair_tool)
        self.crosshair = cross_hair_tool
        self.on_trait_change(self.draw_cross_hairs,
                             "crosshair.selected_x, crosshair.selected_y")
        self.on_trait_change(self.render_julia,
                             "crosshair.selected_x, crosshair.selected_y")
        return ch_plot
Beispiel #17
0
    def __init__(self):
        # Create some data
        x = np.random.random(N_POINTS)
        y = np.random.random(N_POINTS)
        color = np.exp(-(x**2 + y**2))

        # Create a plot data object and give it this data
        data = ArrayPlotData(index=x, value=y, color=color)

        # Create the plot
        plot = Plot(data)
        plot.plot(("index", "value", "color"), type="cmap_scatter",
                  color_mapper=jet)

        # Create the colorbar, handing in the appropriate range and colormap
        colormap = plot.color_mapper
        colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                            color_mapper=colormap,
                            orientation='v',
                            resizable='v',
                            width=30,
                            padding=20)

        colorbar.padding_top = plot.padding_top
        colorbar.padding_bottom = plot.padding_bottom

        # Create a container to position the plot and the colorbar side-by-side
        container = HPlotContainer(plot, colorbar)
        self.plot = container
Beispiel #18
0
 def update_show_curve(self):
     plotdata = ArrayPlotData(x=self.ct_hu, y=self.re_electronic_density)
     plot = Plot(plotdata)
     plot.plot(("x", "y"), type="line", color="blue")              
    
     plot.title = self.name
     self.plot = plot
Beispiel #19
0
def _create_plot_component():
    pd = ArrayPlotData(x=random(100), y=random(100))

    # 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(("x", "y"), color="blue", type="scatter")[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))
    return plot
Beispiel #20
0
 def _create_corr_plot(self):
     plot = Plot(self.plotdata, padding=0)
     plot.padding_left = 25
     plot.padding_bottom = 25
     plot.tools.append(PanTool(plot))
     plot.overlays.append(ZoomTool(plot))
     self.corr_plot = plot
Beispiel #21
0
 def _sig_waveform_plot_default(self):
     plot = Plot(self.plot_data, padding=[75, 25, 25, 50],
                 title='Signal Waveform')
     plot.plot(('time', 'sig_waveform'), color='black')
     plot.index_axis.title = 'Time (sec)'
     plot.value_axis.title = 'Signal (V)'
     return plot
Beispiel #22
0
    def _create_returns_plot(self):
        plot = Plot(self.plotdata)
        plot.legend.visible = True
        #FIXME: The legend move tool doesn't seem to quite work right now
        #plot.legend.tools.append(LegendTool(plot.legend))
        plot.x_axis = None
        x_axis = PlotAxis(plot, orientation="bottom",
                        tick_generator=ScalesTickGenerator(scale=CalendarScaleSystem()))
        plot.overlays.append(x_axis)
        plot.x_grid.tick_generator = x_axis.tick_generator
        for i, name in enumerate(self.plotdata.list_data()):
            if name == "times":
                continue
            renderer = plot.plot(("times", name), type="line", name=name,
                                  color=tuple(COLOR_PALETTE[i]))[0]

        # Tricky: need to set auto_handle_event on the RangeSelection
        # so that it passes left-clicks to the PanTool
        # FIXME: The range selection is still getting the initial left down
        renderer.tools.append(RangeSelection(renderer, left_button_selects = False,
            auto_handle_event = False))
        plot.tools.append(PanTool(plot, drag_button="left", constrain=True,
            constrain_direction="x"))
        plot.overlays.append(ZoomTool(plot, tool_mode="range", max_zoom_out=1.0))
        # Attach the range selection to the last renderer; any one will do
        self._range_selection_overlay = RangeSelectionOverlay(renderer,
                                    metadata_name="selections")
        renderer.overlays.append(self._range_selection_overlay)
        # Grab a reference to the Time axis datasource and add a listener to its
        # selections metadata
        self.times_ds = renderer.index
        self.times_ds.on_trait_change(self._selections_changed, 'metadata_changed')
        self.returns_plot = plot
    def _plot_default(self):
        # Create a GridContainer to hold all of our plots: 2 rows, 4 columns:
        container = GridContainer(fill_padding=True,
                                  bgcolor="lightgray", use_backbuffer=True,
                                  shape=(2, 4))

        arrangements = [('top left', 'h'),
                        ('top right', 'h'),
                        ('top left', 'v'),
                        ('top right', 'v'),
                        ('bottom left', 'h'),
                        ('bottom right', 'h'),
                        ('bottom left', 'v'),
                        ('bottom right', 'v')]
        orientation_name = {'h': 'horizontal', 'v': 'vertical'}

        pd = ArrayPlotData(image=lena())
        # Plot some bessel functions and add the plots to our container
        for origin, orientation in arrangements:
            plot = Plot(pd, default_origin=origin, orientation=orientation)
            plot.img_plot('image')

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

            title = '{0}, {1}'
            plot.title = title.format(orientation_name[orientation],
                                      origin.replace(' ', '-'))

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

        return container
Beispiel #24
0
    def plot_spectrum(self,x,y,field):
        for i in range(len(self.x_koords)):
            x_gap=abs(x-self.x_koords[i])
            y_gap=abs(y-self.y_koords[i])
            if x_gap <self.toleranz and y_gap<self.toleranz:
                spectrum=self.spectra[i]
                wavelength=self.ivCamera.create_wavelength_for_plotting()
                xm = [self.plotrangemarker,self.plotrangemarker] #for red line in plot
                ym = [0,16000] #self.plotrangey
                plotdata = ArrayPlotData(x=wavelength, y=spectrum,xm=xm,ym=ym)
                plot = Plot(plotdata)
                plot.plot(("x", "y"), type="line", color="blue")
                plot.x_axis.title="Wavelength [nm]"
                plot.y_axis.title="Counts"

                #catch error if apd counts not loaded
                try:
                    apd_counts = str(self.apd_counts[i])
                except:
                    apd_counts = str("0")

                plot.title = 'spectrum of QD ' +str(self.x_koords[i])+' '+str(self.y_koords[i])+' with APD at '+str(apd_counts)
                plot.overlays.append(ZoomTool(component=plot,tool_mode="box", always_on=False)) # damit man im Plot zoomen kann
                plot.tools.append(PanTool(plot, constrain_key="shift")) # damit man mit der Maus den Plot verschieben kann
                if field=='current':
                    self.plot_current=plot
                    if self.plotsetalways:
                        self._plotrangeset_fired()
                if field=='compare':
                    self.plot_compare=plot
                    if self.plotsetalways:
                        self._plotrangeset_fired()
Beispiel #25
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()
    def _time_plot_default(self):
        time_plot = Plot(self.time_plot_data)

        time_plot.plot(('t', 'y'))

        time_plot.index_axis.title = "Time"

        time_plot.tools.append(PanTool(time_plot))

        zoomtool = ZoomTool(time_plot, drag_button='right',
                                                    always_on=True)
        time_plot.overlays.append(zoomtool)

        lines1 = CoordinateLineOverlay(component=time_plot,
                    index_data=self.x1,
                    value_data=self.y1,
                    color=(0.75, 0.25, 0.25, 0.75),
                    line_style='dash', line_width=1)
        time_plot.underlays.append(lines1)
        self.line_overlay1 = lines1

        lines2 = CoordinateLineOverlay(component=time_plot,
                    index_data=self.x2,
                    value_data=self.y2,
                    color=(0.2, 0.5, 1.0, 0.75),
                    line_width=3)
        time_plot.underlays.append(lines2)
        self.line_overlay2 = lines2

        return time_plot
Beispiel #27
0
    def _create_plot_component():
        # Create a fake dataset from which 2 dimensions will be displayed in a
        # scatter plot:
        x = np.random.uniform(0.0, 10.0, 50)
        y = np.random.uniform(0.0, 5.0, 50)
        data = pd.DataFrame({"x": x, "y": y,
                             "dataset": np.random.choice(list("abcdefg"), 50)})
        plot_data = ArrayPlotData(x=x, y=y)
        plot = Plot(plot_data)
        scatter = plot.plot(("x", "y"), type="scatter")[0]

        # Attach the inspector and its overlays
        inspector = DataframeScatterInspector(
            component=scatter, data=data
        )
        scatter.tools.append(inspector)

        text_overlay = DataframeScatterOverlay(component=plot,
                                               inspector=inspector,
                                               bgcolor="black", alpha=0.6,
                                               text_color="white",
                                               border_color='none')
        plot.overlays.append(text_overlay)

        # Optional: add an overlay on the point to confirm what is hovered over
        # Note that this overlay magically knows about hovered points by
        # listening to renderer events rather than inspector events:
        point_overlay = ScatterInspectorOverlay(component=scatter,
                                                hover_color="red",
                                                hover_marker_size=6)
        scatter.overlays.append(point_overlay)
        return plot
Beispiel #28
0
    def _hist2d_default(self):
        plot = Plot(self.hist2d_data, padding=(20, 0, 0, 40))
        plot.img_plot("H", xbounds=self.xedges, ybounds=self.yedges, colormap=jet)
        plot.index_axis.title = "Voxel dist."
        plot.value_axis.title = "Root Square Error"

        # Create a colorbar
        colormap = plot.color_mapper
        colorbar = ColorBar(index_mapper=LinearMapper(range=colormap.range),
                            color_mapper=colormap,
                            plot=plot,
                            orientation='v',
                            resizable='v',
                            width=20,
                            padding=(20, 30, 0, 0))
        colorbar.padding_top = plot.padding_top
        colorbar.padding_bottom = plot.padding_bottom

        # Create a container to position the plot and the colorbar side-by-side
        container = HPlotContainer(use_backbuffer=True, padding=0)
        container.add(colorbar)
        container.add(plot)
        container.bgcolor = "lightgray"

        return container
Beispiel #29
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
Beispiel #30
0
def _do_plot_boilerplate(kwargs, image=False):
    """ Used by various plotting functions.  Checks/handles hold state,
    returns a Plot object for the plotting function to use.
    """

    if "hold" in kwargs:
        hold(kwargs["hold"])
        del kwargs["hold"]

    # Check for an active window; if none, open one.
    if len(session.windows) == 0:
        if image:
            win = session.new_window(is_image=True)
            activate(win)
        else:
            figure()

    cont = session.active_window.get_container()

    if not cont:
        cont = Plot(session.data)
        session.active_window.set_container(cont)

    existing_tools = [type(t) for t in (cont.tools + cont.overlays)]
    if not PanTool in existing_tools:
        cont.tools.append(PanTool(cont))
    if not ZoomTool in existing_tools:
        cont.overlays.append(ZoomTool(cont, tool_mode="box", always_on=True, drag_button="right"))

    if not session.hold:
        cont.delplot(*list(cont.plots.keys()))

    return cont