コード例 #1
0
ファイル: scales_test.py プロジェクト: pingleewu/ShareRoot
def add_default_axes(plot, orientation="normal", vtitle="", htitle=""):
    """
    Creates left and bottom axes for a plot.  Assumes that the index is
    horizontal and value is vertical by default; set orientation to
    something other than "normal" if they are flipped.
    """
    if orientation in ("normal", "h"):
        v_mapper = plot.value_mapper
        h_mapper = plot.index_mapper
    else:
        v_mapper = plot.index_mapper
        h_mapper = plot.value_mapper

    left = PlotAxis(orientation='left',
                    title=vtitle,
                    mapper=v_mapper,
                    component=plot)

    bottom = PlotAxis(orientation='bottom',
                      title=htitle,
                      mapper=h_mapper,
                      component=plot)

    plot.underlays.append(left)
    plot.underlays.append(bottom)
    return left, bottom
コード例 #2
0
 def test_plot_axis(self):
     axis = PlotAxis()
     with warnings.catch_warnings(record=True) as w:
         axis._tick_positions = np.arange(10)
         axis._tick_label_list = np.arange(10)
         axis._tick_label_positions = np.arange(10)
     self.assertEqual(w, [])
コード例 #3
0
    def _init_components(self):
        # Since this is called after the HasTraits constructor, we have to make
        # sure that we don't blow away any components that the caller may have
        # already set.

        if self.range2d is None:
            self.range2d = DataRange2D()

        if self.index_mapper is None:
            if self.index_scale == "linear":
                imap = LinearMapper(range=self.range2d.x_range)
            else:
                imap = LogMapper(range=self.range2d.x_range)
            self.index_mapper = imap

        if self.value_mapper is None:
            if self.value_scale == "linear":
                vmap = LinearMapper(range=self.range2d.y_range)
            else:
                vmap = LogMapper(range=self.range2d.y_range)
            self.value_mapper = vmap

        if self.x_ticks is None:
            self.x_ticks = ScalesTickGenerator(
                scale=self._make_scale(self.index_scale))
        if self.y_ticks is None:
            self.y_ticks = ScalesTickGenerator(
                scale=self._make_scale(self.value_scale))

        if self.x_grid is None:
            self.x_grid = PlotGrid(mapper=self.x_mapper,
                                   orientation="vertical",
                                   line_color="lightgray",
                                   line_style="dot",
                                   component=self,
                                   tick_generator=self.x_ticks)
        if self.y_grid is None:
            self.y_grid = PlotGrid(mapper=self.y_mapper,
                                   orientation="horizontal",
                                   line_color="lightgray",
                                   line_style="dot",
                                   component=self,
                                   tick_generator=self.y_ticks)
        if self.x_axis is None:
            self.x_axis = PlotAxis(mapper=self.x_mapper,
                                   orientation="bottom",
                                   component=self,
                                   tick_generator=self.x_ticks)
        if self.y_axis is None:
            self.y_axis = PlotAxis(mapper=self.y_mapper,
                                   orientation="left",
                                   component=self,
                                   tick_generator=self.y_ticks)
コード例 #4
0
    def __init__(self,
                 xs,
                 ys,
                 index_bounds=None,
                 value_bounds=None,
                 *args,
                 **kw):
        index = ArrayDataSource(xs)
        value = ArrayDataSource(ys)
        if index_bounds is not None:
            index_range = DataRange1D(low=index_bounds[0],
                                      high=index_bounds[1])
        else:
            index_range = DataRange1D()
        index_range.add(index)
        index_mapper = LinearMapper(range=index_range)
        index_range.tight_bounds = False
        if value_bounds is not None:
            value_range = DataRange1D(low=value_bounds[0],
                                      high=value_bounds[1])
        else:
            value_range = DataRange1D()
        value_range.add(value)
        value_mapper = LinearMapper(range=value_range)
        value_range.tight_bounds = False

        self.index = index
        self.value = value
        self.index_mapper = index_mapper
        self.value_mapper = value_mapper
        # self.color = "red"
        # self.line_width = 1.0
        # self.line_style = "solid"

        super(BaseInset, self).__init__(*args, **kw)

        tick_label_font = 'Helvetica 8'
        left = PlotAxis(orientation='left',
                        mapper=value_mapper,
                        bgcolor=self.bgcolor,
                        tick_label_font=tick_label_font)

        bottom = PlotAxis(orientation='bottom',
                          mapper=index_mapper,
                          bgcolor=self.bgcolor,
                          tick_label_font=tick_label_font)

        self.underlays.append(left)
        self.underlays.append(bottom)
コード例 #5
0
def add_axes(plot, x_label='', y_label=''):
    y_axis = PlotAxis(orientation='left',
                      title=y_label,
                      mapper=plot.y_mapper,
                      component=plot,
                      **AXIS_DEFAULTS)

    x_axis = PlotAxis(orientation='bottom',
                      title=x_label,
                      mapper=plot.x_mapper,
                      component=plot,
                      **AXIS_DEFAULTS)

    plot.underlays.append(x_axis)
    plot.underlays.append(y_axis)
コード例 #6
0
def get_jitter_plot():
    boston = datasets.load_boston()
    prices = boston['target']

    x, y = get_data_sources(y=prices)
    x_mapper, y_mapper = get_mappers(x, y)

    jitter_plot = JitterPlot(
        index=y,
        mapper=y_mapper,
        marker='circle',
        jitter_width=100,
        **PLOT_DEFAULTS
    )
    jitter_plot.line_width = 1.

    x_axis = PlotAxis(orientation='bottom',
                      title='Median house prices',
                      mapper=jitter_plot.mapper,
                      component=jitter_plot,
                      **AXIS_DEFAULTS)

    jitter_plot.underlays.append(x_axis)

    return jitter_plot
コード例 #7
0
ファイル: graph.py プロジェクト: ael-noblegas/pychron
    def add_aux_axis(self, po, p, title='', color='black'):
        """
        """

        axis = PlotAxis(p,
                        orientation='right',
                        title=title,
                        axis_line_visible=False,
                        tick_color=color,
                        tick_label_color=color,
                        title_color=color)

        p.underlays.append(axis)
        po.add(p)

        po.x_grid.visible = False
        po.y_grid.visible = False
コード例 #8
0
ファイル: graph.py プロジェクト: sgallet/pychron
    def add_aux_axis(self, po, p, title='', color='black'):
        '''
        '''
        #        from chaco.axis import PlotAxis

        axis = PlotAxis(p,
                        orientation='right',
                        title=title,
                        axis_line_visible=False,
                        tick_color=color,
                        tick_label_color=color,
                        title_color=color)

        p.underlays.append(axis)
        po.add(p)
        #        po.plots['aux'] = [p]

        po.x_grid.visible = False
        po.y_grid.visible = False
コード例 #9
0
ファイル: graph.py プロジェクト: sgallet/pychron
    def _plot_axis_factory(self, p, key, normal, **kw):
        if key == 'x':
            m = p.index_mapper
            if normal:
                o = 'bottom'
            else:
                o = 'top'
                kw['tick_label_formatter'] = lambda x: ''
        else:
            if normal:
                o = 'left'
            else:
                o = 'right'
                kw['tick_label_formatter'] = lambda x: ''
            m = p.value_mapper

        ax = PlotAxis(component=p,
                      mapper=m,
                      orientation=o,
                      axis_line_visible=False,
                      **kw)
        return ax
コード例 #10
0
def plotEigenvalues(model, gui):
    ''' This function calculates the linearization of model as well as additional information
        (eigenvalues, damping ...) if this was not done before.
        It opens a new plotting tab and displays this information
    '''
    if model is None:
        print("No model selected!")
        return

    # Check if already linearized, do so otherwise:
    try:
        data = model.pluginData["EigenvalueAnalysis"]
    except:
        print "Performing linearization"
        data = EigenvalueAnalysis()
        data._performLinearization(model)
        model.pluginData["EigenvalueAnalysis"] = data


    # Open new plotting tab:
    parent = QtGui.QApplication.activeWindow()
    widgetContainer = parent._newPlotContainer()
    widget = widgetContainer.activeWidget

    # Plot the data:
    x = numpy.real(data.eigenvalues[:])
    y = numpy.imag(data.eigenvalues[:])
    plotdata = ArrayPlotData(x=x, y=y, border_visible=True, overlay_border=True)
    plot = Plot(plotdata, title="Eigenvalues of %s" % data.modelName)
    scatter = plot.plot(("x", "y"), type="scatter", color="blue")[0]

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

    # Add axis titles:
    x_axis = PlotAxis(orientation="bottom")
    x_axis.mapper = plot.index_mapper
    x_axis.title = "real part"
    plot.underlays.append(x_axis)
    y_axis = PlotAxis(orientation="left")
    y_axis.mapper = plot.value_mapper
    y_axis.title = "imag. part"
    plot.underlays.append(y_axis)

    # Attach the inspector and its overlay
    scatter.tools.append(ScatterInspector(scatter))
    overlay = myScatterInspectorOverlay(scatter,
                    hover_color="red",
                    hover_marker_size=6,
                    selection_marker_size=6,
                    selection_color="yellow",
                    selection_outline_color="purple",
                    selection_line_width=3,
                    stateNames=data.StateNames,
                    eigenVectors=data.eigenvectors,
                    frequencies=data.frequencies,
                    damping=data.damping,
                    observability=data.observability,
                    controllability=data.controllability)
    scatter.overlays.append(overlay)
    # Activate Plot:
    widget.setPlot(plot)
    widgetContainer.activeWidget = widget
コード例 #11
0
def plotEigenvalues(model, gui):
    ''' This function calculates the linearization of model as well as additional information
        (eigenvalues, damping ...) if this was not done before.
        It opens a new plotting tab and displays this information
    '''
    if model is None:
        print("No model selected!")
        return

    # Check if already linearized, do so otherwise:
    try:
        data = model.pluginData["EigenvalueAnalysis"]
    except:
        print "Performing linearization"
        data = EigenvalueAnalysis()
        data._performLinearization(model)
        model.pluginData["EigenvalueAnalysis"] = data

    # Open new plotting tab:
    parent = QtGui.QApplication.activeWindow()
    widgetContainer = parent._newPlotContainer()
    widget = widgetContainer.activeWidget

    # Plot the data:
    x = numpy.real(data.eigenvalues[:])
    y = numpy.imag(data.eigenvalues[:])
    plotdata = ArrayPlotData(x=x,
                             y=y,
                             border_visible=True,
                             overlay_border=True)
    plot = Plot(plotdata, title="Eigenvalues of %s" % data.modelName)
    scatter = plot.plot(("x", "y"), type="scatter", color="blue")[0]

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

    # Add axis titles:
    x_axis = PlotAxis(orientation="bottom")
    x_axis.mapper = plot.index_mapper
    x_axis.title = "real part"
    plot.underlays.append(x_axis)
    y_axis = PlotAxis(orientation="left")
    y_axis.mapper = plot.value_mapper
    y_axis.title = "imag. part"
    plot.underlays.append(y_axis)

    # Attach the inspector and its overlay
    scatter.tools.append(ScatterInspector(scatter))
    overlay = myScatterInspectorOverlay(scatter,
                                        hover_color="red",
                                        hover_marker_size=6,
                                        selection_marker_size=6,
                                        selection_color="yellow",
                                        selection_outline_color="purple",
                                        selection_line_width=3,
                                        stateNames=data.StateNames,
                                        eigenVectors=data.eigenvectors,
                                        frequencies=data.frequencies,
                                        damping=data.damping,
                                        observability=data.observability,
                                        controllability=data.controllability)
    scatter.overlays.append(overlay)
    # Activate Plot:
    widget.setPlot(plot)
    widgetContainer.activeWidget = widget
コード例 #12
0
    def initiate(self):
        if len(self.pp_specs) == 0:
            return False

        # only positive values are accepted
        x = self.p0.x_data[pl.where(self.p0.x_data > 0)]
        y = self.p0.y_data[pl.where(self.p0.y_data > 0)]

        x_min = pl.amin(x)
        x_max = pl.amax(x)
        y_min = pl.amin(y)
        y_max = pl.amax(y)
        value_min = x_min if x_min < y_min else y_min
        self.value_max = x_max if x_max > y_max else y_max

        self.pd = ArrayPlotData()
        self.pd.set_data("index", x)
        self.pd.set_data("value", y)

        index_ds = ArrayDataSource(x)
        value_ds = ArrayDataSource(y)

        # Create the plot
        self._plot = Plot(self.pd)

        axis_defaults = {
                         #'axis_line_weight': 2,
                         #'tick_weight': 2,
                         #'tick_label_color': 'green',
                         'title_font': self.axis_font,
                         }
        if self.tick_font:
            axis_defaults['tick_label_font'] = self.tick_font

        #a very important and weird trick; used to remove default ticks labels
        self._plot.x_axis = None
        self._plot.y_axis = None
        #end trick

        #add new x label and x's ticks labels
        x_axis = PlotAxis(orientation='bottom',
                  title=nvl(self.manager.x_label, 'RR(n) [ms]'),
                  mapper=self._plot.x_mapper,
                  **axis_defaults)
        self._plot.overlays.append(x_axis)

        #add new y label and y's ticks labels
        y_axis = PlotAxis(orientation='left',
                   title=nvl(self.manager.y_label, 'RR(n+1) [ms]'),
                   mapper=self._plot.y_mapper,
                   **axis_defaults)
        self._plot.overlays.append(y_axis)

        self._plot.index_range.add(index_ds)
        self._plot.value_range.add(value_ds)

        self._plot.index_mapper.stretch_data = False
        self._plot.value_mapper.stretch_data = False
        self._plot.value_range.set_bounds(value_min, self.value_max)
        self._plot.index_range.set_bounds(value_min, self.value_max)

        # Create the index and value mappers using the plot data ranges
        imapper = LinearMapper(range=self._plot.index_range)
        vmapper = LinearMapper(range=self._plot.value_range)

        color = "white"

        self.scatter = __PoincarePlotScatterPlot__(
                        self.p0,
                        self.manager,
                        index=index_ds,
                        value=value_ds,
                        #color_data=color_ds,
                        #color_mapper=color_mapper,
                        #fill_alpha=0.4,
                        color=color,
                        index_mapper=imapper,
                        value_mapper=vmapper,
                        marker='circle',
                        marker_size=self.manager.active_point_size,
                        line_width=0
                        #outline_color='white'
                        )
        self._plot.add(self.scatter)

        #self._plot.plots['var_size_scatter'] = [self.scatter]

        # Tweak some of the plot properties
        _title = nvl(self.manager.movie_title, "Poincare plot")
        if len(_title) > 0:
            self._plot.title = _title
            self._plot.title_font = self.title_font

        self._plot.line_width = 0.5
        self._plot.padding = self.frame_pad

        self._plot.do_layout(force=True)
        self._plot.outer_bounds = [self.manager.movie_width,
                                   self.manager.movie_height]

        self.gc = PlotGraphicsContext(self._plot.outer_bounds,
                                      dpi=self.manager.movie_dpi)
        self.gc.render_component(self._plot)
        self.gc.set_line_width(0)

        self.gc.save(self._get_filename(self.p0))

        self.x_mean_old = None
        self.y_mean_old = None
        self._time_label_font = None

        return True
コード例 #13
0
ファイル: model.py プロジェクト: NMBGMR/wellpy
    def initialize_plot(self):
        data = self.data_model

        container = self.plot_container
        self._series = []
        self._plots = {}
        index, rr = None, None
        for i, (a, title) in enumerate((
            ('water_head', 'Head'),
            ('adjusted_water_head', 'Adj. Head'),

                # ('temp', 'Temp.'),
                # ('water_level_elevation', 'Elev.')
        )):
            plot = Plot(
                data=ArrayPlotData(**{
                    'x': data.x,
                    a: getattr(data, a)
                }),
                padding=[70, 10, 10, 10],
                # resizable='h',
                # bounds=(1, 125)
            )

            if index is None:
                index = plot.index_mapper
                rr = plot.index_range
            else:
                plot.index_mapper = index
                plot.index_range = rr

            series = plot.plot(('x', a))[0]
            plot.plot(('x', a), marker_size=1.5, type='scatter')

            dt = DataTool(plot=series,
                          component=plot,
                          normalize_time=False,
                          use_date_str=True)
            dto = DataToolOverlay(component=series, tool=dt)
            series.tools.append(dt)
            series.overlays.append(dto)

            plot.y_axis.title = title
            if i != 0:
                plot.x_axis.visible = False
            else:

                zoom = ZoomTool(plot,
                                tool_mode="range",
                                axis='index',
                                color=(0, 1, 0, 0.5),
                                enable_wheel=False,
                                always_on=False)
                plot.overlays.append(zoom)

                tool = RangeSelection(series,
                                      left_button_selects=True,
                                      listeners=[self])
                self._tool = tool

                series.tools.append(tool)
                # series.active_tool = tool
                # plot.x_axis.title = 'Time'
                bottom_axis = PlotAxis(
                    plot,
                    orientation="bottom",  # mapper=xmapper,
                    tick_generator=ScalesTickGenerator(
                        scale=CalendarScaleSystem()))
                plot.x_axis = bottom_axis

                plot.padding_bottom = 50

            series.overlays.append(RangeSelectionOverlay(component=series))
            container.add(plot)
            self._series.append(series)
            self._plots[a] = plot

        container.invalidate_and_redraw()