コード例 #1
0
    def __init__(self, **traits):
        super(LassoDemoPlot, self).__init__(**traits)
        x = np.random.random(N)
        y = np.random.random(N)
        x2 = np.array([])
        y2 = np.array([])

        data = ArrayPlotData(x=x, y=y, x2=x2, y2=y2)

        plot1 = Plot(data, padding=10)
        scatter_plot1 = plot1.plot(("x", "y"),
                                   type="scatter",
                                   marker="circle",
                                   color="blue")[0]

        self.lasso = LassoSelection(scatter_plot1,
                                    incremental_select=True,
                                    selection_datasource=scatter_plot1.index)
        self.lasso.on_trait_change(self._selection_changed,
                                   'selection_changed')
        scatter_plot1.tools.append(self.lasso)
        scatter_plot1.overlays.append(
            LassoOverlay(scatter_plot1, lasso_selection=self.lasso))

        plot2 = Plot(data, padding=10)
        plot2.index_range = plot1.index_range
        plot2.value_range = plot1.value_range
        plot2.plot(("x2", "y2"), type="scatter", marker="circle", color="red")

        self.plot = HPlotContainer(plot1, plot2)
        self.plot2 = plot2
        self.data = data
コード例 #2
0
  def __init__(self, **traits):
      super(LassoDemoPlot, self).__init__(**traits)
      x = np.random.random(N)
      y = np.random.random(N)
      x2 = np.array([])
      y2 = np.array([])
 
      data = ArrayPlotData(x=x, y=y, x2=x2, y2=y2) 
      
      
      plot1 = Plot(data, padding=10) 
      scatter_plot1 = plot1.plot(("x", "y"), type="scatter", marker="circle", color="blue")[0]
     
      self.lasso = LassoSelection(scatter_plot1, incremental_select=True,  
          selection_datasource=scatter_plot1.index)
      self.lasso.on_trait_change(self._selection_changed, 'selection_changed') 
      scatter_plot1.tools.append(self.lasso)
      scatter_plot1.overlays.append(LassoOverlay(scatter_plot1, lasso_selection=self.lasso)) 
      
      plot2 = Plot(data, padding=10)
      plot2.index_range = plot1.index_range
      plot2.value_range = plot1.value_range
      plot2.plot(("x2", "y2"), type="scatter", marker="circle", color="red")
      
      
      self.plot = HPlotContainer(plot1, plot2)
      self.plot2 = plot2
      self.data = data
コード例 #3
0
ファイル: data_cube.py プロジェクト: brycehendrix/chaco
    def _create_window(self):
        # Create the model
        #try:
        #    self.model = model = BrainModel()
        #    cmap = bone
        #except SystemExit:
        #    sys.exit()
        #except:
        #    print "Unable to load BrainModel, using generated data cube."
        self.model = model = Model()
        cmap = jet
        self._update_model(cmap)

        datacube = self.colorcube

        # Create the plot
        self.plotdata = ArrayPlotData()
        self._update_images()

        # Center Plot
        centerplot = Plot(self.plotdata, padding=0)
        imgplot = centerplot.img_plot("xy",
                                xbounds=(model.xs[0], model.xs[-1]),
                                ybounds=(model.ys[0], model.ys[-1]),
                                colormap=cmap)[0]
        self._add_plot_tools(imgplot, "xy")
        self.center = imgplot

        # Right Plot
        rightplot = Plot(self.plotdata, width=150, resizable="v", padding=0)
        rightplot.value_range = centerplot.value_range
        imgplot = rightplot.img_plot("yz",
                                xbounds=(model.zs[0], model.zs[-1]),
                                ybounds=(model.ys[0], model.ys[-1]),
                                colormap=cmap)[0]
        self._add_plot_tools(imgplot, "yz")
        self.right = imgplot

        # Bottom Plot
        bottomplot = Plot(self.plotdata, height=150, resizable="h", padding=0)
        bottomplot.index_range = centerplot.index_range
        imgplot = bottomplot.img_plot("xz",
                                xbounds=(model.xs[0], model.xs[-1]),
                                ybounds=(model.zs[0], model.zs[-1]),
                                colormap=cmap)[0]
        self._add_plot_tools(imgplot, "xz")
        self.bottom = imgplot

        # Create Container and add all Plots
        container = GridPlotContainer(padding=20, fill_padding=True,
                                      bgcolor="white", use_backbuffer=True,
                                      shape=(2,2), spacing=(12,12))
        container.add(centerplot)
        container.add(rightplot)
        container.add(bottomplot)

        self.container = container
        return Window(self, -1, component=container)
コード例 #4
0
    def __init__(self):
        super(CyclesPlot, self).__init__()

        # Normally you'd pass in the data, but I'll hardwire things for this
        #    one-off plot.

        srecs = read_time_series_from_csv("./biz_cycles.csv", date_col=0, date_format="%Y-%m-%d")

        dt = srecs["Date"]

        # Industrial production compared with trend (plotted on value axis)
        iprod_vs_trend = srecs["Metric 1"]

        # Industrial production change in last 6 Months (plotted on index axis)
        iprod_delta = srecs["Metric 2"]

        self._dates = dt
        self._series1 = self._selected_s1 = iprod_delta
        self._series2 = self._selected_s2 = iprod_vs_trend

        end_x = np.array([self._selected_s1[-1]])
        end_y = np.array([self._selected_s2[-1]])

        plotdata = ArrayPlotData(
            x=self._series1,
            y=self._series2,
            dates=self._dates,
            selected_x=self._selected_s1,
            selected_y=self._selected_s2,
            endpoint_x=end_x,
            endpoint_y=end_y,
        )

        cycles = Plot(plotdata, padding=20)

        cycles.plot(("x", "y"), type="line", color=(0.2, 0.4, 0.5, 0.4))

        cycles.plot(
            ("selected_x", "selected_y"), type="line", marker="circle", line_width=3, color=(0.2, 0.4, 0.5, 0.9)
        )

        cycles.plot(
            ("endpoint_x", "endpoint_y"),
            type="scatter",
            marker_size=4,
            marker="circle",
            color=(0.2, 0.4, 0.5, 0.2),
            outline_color=(0.2, 0.4, 0.5, 0.6),
        )

        cycles.index_range = DataRange1D(low_setting=80.0, high_setting=120.0)

        cycles.value_range = DataRange1D(low_setting=80.0, high_setting=120.0)

        # dig down to use actual Plot object
        cyc_plot = cycles.components[0]

        # Add the labels in the quadrants
        cyc_plot.overlays.append(
            PlotLabel(
                "\nSlowdown" + 40 * " " + "Expansion",
                component=cyc_plot,
                font="swiss 24",
                color=(0.2, 0.4, 0.5, 0.6),
                overlay_position="inside top",
            )
        )

        cyc_plot.overlays.append(
            PlotLabel(
                "Downturn" + 40 * " " + "Recovery\n ",
                component=cyc_plot,
                font="swiss 24",
                color=(0.2, 0.4, 0.5, 0.6),
                overlay_position="inside bottom",
            )
        )

        timeline = Plot(plotdata, resizable="h", height=50, padding=20)
        timeline.plot(("dates", "x"), type="line", color=(0.2, 0.4, 0.5, 0.8), name="x")
        timeline.plot(("dates", "y"), type="line", color=(0.5, 0.4, 0.2, 0.8), name="y")

        # Snap on the tools
        zoomer = ZoomTool(
            timeline, drag_button="right", always_on=True, tool_mode="range", axis="index", max_zoom_out_factor=1.1
        )

        panner = PanTool(timeline, constrain=True, constrain_direction="x")

        # dig down to get Plot component I want
        x_plt = timeline.plots["x"][0]

        range_selection = RangeSelection(x_plt, left_button_selects=True)
        range_selection.on_trait_change(self.update_interval, "selection")

        x_plt.tools.append(range_selection)
        x_plt.overlays.append(RangeSelectionOverlay(x_plt))

        # Set the plot's bottom axis to use the Scales ticking system
        scale_sys = CalendarScaleSystem(fill_ratio=0.4, default_numlabels=5, default_numticks=10)
        tick_gen = ScalesTickGenerator(scale=scale_sys)

        bottom_axis = ScalesPlotAxis(timeline, orientation="bottom", tick_generator=tick_gen)

        # Hack to remove default axis - FIXME: how do I *replace* an axis?
        del (timeline.underlays[-2])

        timeline.overlays.append(bottom_axis)

        container = GridContainer(
            padding=20, fill_padding=True, bgcolor="lightgray", use_backbuffer=True, shape=(2, 1), spacing=(30, 30)
        )

        # add a central "x" and "y" axis

        x_line = LineInspector(cyc_plot, is_listener=True, color="gray", width=2)
        y_line = LineInspector(cyc_plot, is_listener=True, color="gray", width=2, axis="value")

        cyc_plot.overlays.append(x_line)
        cyc_plot.overlays.append(y_line)

        cyc_plot.index.metadata["selections"] = 100.0
        cyc_plot.value.metadata["selections"] = 100.0

        container.add(cycles)
        container.add(timeline)

        container.title = "Business Cycles"

        self.plot = container
コード例 #5
0
ファイル: biz_cycles.py プロジェクト: eshioji/experimental
    def __init__(self):
        super(CyclesPlot, self).__init__()

        # Normally you'd pass in the data, but I'll hardwire things for this
        #    one-off plot.

        srecs = read_time_series_from_csv("./biz_cycles2.csv",
                                          date_col=0,
                                          date_format="%Y-%m-%d")

        dt = srecs["Date"]

        # Industrial production compared with trend (plotted on value axis)
        iprod_vs_trend = srecs["Metric 1"]

        # Industrial production change in last 6 Months (plotted on index axis)
        iprod_delta = srecs["Metric 2"]

        self._dates = dt
        self._series1 = self._selected_s1 = iprod_delta
        self._series2 = self._selected_s2 = iprod_vs_trend

        end_x = np.array([self._selected_s1[-1]])
        end_y = np.array([self._selected_s2[-1]])

        plotdata = ArrayPlotData(x=self._series1,
                                 y=self._series2,
                                 dates=self._dates,
                                 selected_x=self._selected_s1,
                                 selected_y=self._selected_s2,
                                 endpoint_x=end_x,
                                 endpoint_y=end_y)

        cycles = Plot(plotdata, padding=20)

        cycles.plot(("x", "y"), type="line", color=(.2, .4, .5, .4))

        cycles.plot(("selected_x", "selected_y"),
                    type="line",
                    marker="circle",
                    line_width=3,
                    color=(.2, .4, .5, .9))

        cycles.plot(("endpoint_x", "endpoint_y"),
                    type="scatter",
                    marker_size=4,
                    marker="circle",
                    color=(.2, .4, .5, .2),
                    outline_color=(.2, .4, .5, .6))

        cycles.index_range = DataRange1D(low_setting=80., high_setting=120.)

        cycles.value_range = DataRange1D(low_setting=80., high_setting=120.)

        # dig down to use actual Plot object
        cyc_plot = cycles.components[0]

        # Add the labels in the quadrants
        cyc_plot.overlays.append(
            PlotLabel("\nSlowdown" + 40 * " " + "Expansion",
                      component=cyc_plot,
                      font="swiss 24",
                      color=(.2, .4, .5, .6),
                      overlay_position="inside top"))

        cyc_plot.overlays.append(
            PlotLabel("Downturn" + 40 * " " + "Recovery\n ",
                      component=cyc_plot,
                      font="swiss 24",
                      color=(.2, .4, .5, .6),
                      overlay_position="inside bottom"))

        timeline = Plot(plotdata, resizable='h', height=50, padding=20)
        timeline.plot(("dates", "x"),
                      type="line",
                      color=(.2, .4, .5, .8),
                      name='x')
        timeline.plot(("dates", "y"),
                      type="line",
                      color=(.5, .4, .2, .8),
                      name='y')

        # Snap on the tools
        zoomer = ZoomTool(timeline,
                          drag_button="right",
                          always_on=True,
                          tool_mode="range",
                          axis="index",
                          max_zoom_out_factor=1.1)

        panner = PanTool(timeline, constrain=True, constrain_direction="x")

        # dig down to get Plot component I want
        x_plt = timeline.plots['x'][0]

        range_selection = RangeSelection(x_plt, left_button_selects=True)
        range_selection.on_trait_change(self.update_interval, 'selection')

        x_plt.tools.append(range_selection)
        x_plt.overlays.append(RangeSelectionOverlay(x_plt))

        # Set the plot's bottom axis to use the Scales ticking system
        scale_sys = CalendarScaleSystem(
            fill_ratio=0.4,
            default_numlabels=5,
            default_numticks=10,
        )
        tick_gen = ScalesTickGenerator(scale=scale_sys)

        bottom_axis = ScalesPlotAxis(timeline,
                                     orientation="bottom",
                                     tick_generator=tick_gen)

        # Hack to remove default axis - FIXME: how do I *replace* an axis?
        del (timeline.underlays[-2])

        timeline.overlays.append(bottom_axis)

        container = GridContainer(padding=20,
                                  fill_padding=True,
                                  bgcolor="lightgray",
                                  use_backbuffer=True,
                                  shape=(2, 1),
                                  spacing=(30, 30))

        # add a central "x" and "y" axis

        x_line = LineInspector(cyc_plot,
                               is_listener=True,
                               color="gray",
                               width=2)
        y_line = LineInspector(cyc_plot,
                               is_listener=True,
                               color="gray",
                               width=2,
                               axis="value")

        cyc_plot.overlays.append(x_line)
        cyc_plot.overlays.append(y_line)

        cyc_plot.index.metadata["selections"] = 100.0
        cyc_plot.value.metadata["selections"] = 100.0

        container.add(cycles)
        container.add(timeline)

        container.title = "Business Cycles"

        self.plot = container
コード例 #6
0
ファイル: Plot3D.py プロジェクト: liq07lzucn/radpy
    def add_plot(self, label, beam):

        #        container = GridPlotContainer(padding=20, fill_padding=True,
        #                                      bgcolor="white", use_backbuffer=True,
        #                                      shape=(2,2), spacing=(12,12))
        #        self.container = container
        self.plotdata = ArrayPlotData()
        self.model = beam.Data
        self.model.z_axis = self.model.z_axis[::-1]
        cmap = jet
        self._update_model(cmap)
        self.plotdata.set_data("xy", self.model.dose)
        self._update_images()

        # Center Plot
        centerplot = Plot(self.plotdata,
                          resizable='hv',
                          height=150,
                          width=150,
                          padding=0)
        centerplot.default_origin = 'top left'
        imgplot = centerplot.img_plot("xy",
                                      xbounds=(self.model.x_axis[0],
                                               self.model.x_axis[-1]),
                                      ybounds=(self.model.y_axis[0],
                                               self.model.y_axis[-1]),
                                      colormap=cmap)[0]

        imgplot.origin = 'top left'
        self._add_plot_tools(imgplot, "xy")
        left_axis = PlotAxis(centerplot, orientation='left', title='y')
        bottom_axis = PlotAxis(centerplot,
                               orientation='bottom',
                               title='x',
                               title_spacing=30)
        centerplot.underlays.append(left_axis)
        centerplot.underlays.append(bottom_axis)
        self.center = imgplot

        # Right Plot
        rightplot = Plot(self.plotdata,
                         height=150,
                         width=150,
                         resizable="hv",
                         padding=0)
        rightplot.default_origin = 'top left'
        rightplot.value_range = centerplot.value_range
        imgplot = rightplot.img_plot("yz",
                                     xbounds=(self.model.z_axis[0],
                                              self.model.z_axis[-1]),
                                     ybounds=(self.model.y_axis[0],
                                              self.model.y_axis[-1]),
                                     colormap=cmap)[0]
        imgplot.origin = 'top left'
        self._add_plot_tools(imgplot, "yz")
        left_axis = PlotAxis(rightplot, orientation='left', title='y')
        bottom_axis = PlotAxis(rightplot,
                               orientation='bottom',
                               title='z',
                               title_spacing=30)
        rightplot.underlays.append(left_axis)
        rightplot.underlays.append(bottom_axis)
        self.right = imgplot

        # Bottom Plot
        bottomplot = Plot(self.plotdata,
                          height=150,
                          width=150,
                          resizable="hv",
                          padding=0)
        bottomplot.index_range = centerplot.index_range
        imgplot = bottomplot.img_plot("xz",
                                      xbounds=(self.model.x_axis[0],
                                               self.model.x_axis[-1]),
                                      ybounds=(self.model.z_axis[0],
                                               self.model.z_axis[-1]),
                                      colormap=cmap)[0]
        self._add_plot_tools(imgplot, "xz")
        left_axis = PlotAxis(bottomplot, orientation='left', title='z')
        bottom_axis = PlotAxis(bottomplot,
                               orientation='bottom',
                               title='x',
                               title_spacing=30)
        bottomplot.underlays.append(left_axis)
        bottomplot.underlays.append(bottom_axis)
        self.bottom = imgplot

        # Create Container and add all Plots
        #        container = GridPlotContainer(padding=20, fill_padding=True,
        #                                      bgcolor="white", use_backbuffer=True,
        #                                      shape=(2,2), spacing=(12,12))
        self.container.add(centerplot)
        self.container.add(rightplot)
        self.container.add(bottomplot)

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

        #        return container

        return label
コード例 #7
0
ファイル: Plot3D.py プロジェクト: sparkpoints/radpy
    def add_plot(self, label, beam):
        
#        container = GridPlotContainer(padding=20, fill_padding=True,
#                                      bgcolor="white", use_backbuffer=True,
#                                      shape=(2,2), spacing=(12,12))
#        self.container = container
        self.plotdata = ArrayPlotData()
        self.model = beam.Data
        self.model.z_axis = self.model.z_axis[::-1]
        cmap = jet
        self._update_model(cmap)
        self.plotdata.set_data("xy",self.model.dose)
        self._update_images()

        # Center Plot
        centerplot = Plot(self.plotdata, resizable='hv', height=150, width=150, padding=0)
        centerplot.default_origin = 'top left'
        imgplot = centerplot.img_plot("xy", 
                                xbounds=(self.model.x_axis[0], self.model.x_axis[-1]),
                                ybounds=(self.model.y_axis[0], self.model.y_axis[-1]), 
                                colormap=cmap)[0]
       
        imgplot.origin = 'top left'
        self._add_plot_tools(imgplot, "xy")
        left_axis = PlotAxis(centerplot, orientation='left', title='y')
        bottom_axis = PlotAxis(centerplot, orientation='bottom', title='x',
                               title_spacing=30)
        centerplot.underlays.append(left_axis)
        centerplot.underlays.append(bottom_axis)
        self.center = imgplot

        # Right Plot
        rightplot = Plot(self.plotdata, height=150, width=150, resizable="hv", padding=0)
        rightplot.default_origin = 'top left'
        rightplot.value_range = centerplot.value_range
        imgplot = rightplot.img_plot("yz", 
                                xbounds=(self.model.z_axis[0], self.model.z_axis[-1]), 
                                ybounds=(self.model.y_axis[0], self.model.y_axis[-1]),
                                colormap=cmap)[0]
        imgplot.origin = 'top left'
        self._add_plot_tools(imgplot, "yz")
        left_axis = PlotAxis(rightplot, orientation='left', title='y')
        bottom_axis = PlotAxis(rightplot, orientation='bottom', title='z',
                               title_spacing=30)
        rightplot.underlays.append(left_axis)
        rightplot.underlays.append(bottom_axis)
        self.right = imgplot
       

        # Bottom Plot
        bottomplot = Plot(self.plotdata, height=150, width=150, resizable="hv", padding=0)
        bottomplot.index_range = centerplot.index_range
        imgplot = bottomplot.img_plot("xz", 
                                xbounds=(self.model.x_axis[0], self.model.x_axis[-1]),
                                ybounds=(self.model.z_axis[0], self.model.z_axis[-1]),
                                colormap=cmap)[0]
        self._add_plot_tools(imgplot, "xz")
        left_axis = PlotAxis(bottomplot, orientation='left', title='z')
        bottom_axis = PlotAxis(bottomplot, orientation='bottom', title='x',
                               title_spacing=30)
        bottomplot.underlays.append(left_axis)
        bottomplot.underlays.append(bottom_axis)
        self.bottom = imgplot

        # Create Container and add all Plots
#        container = GridPlotContainer(padding=20, fill_padding=True,
#                                      bgcolor="white", use_backbuffer=True,
#                                      shape=(2,2), spacing=(12,12))
        self.container.add(centerplot)
        self.container.add(rightplot)
        self.container.add(bottomplot)

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


#        return container

        return label