Exemple #1
0
    def format_axes(self, ax):


        ax.set_ylabel(self.ylabel)
        if self.yrange is not None:
            ax.set_ylim(self.yrange)
        if self.yunit is not None:
            #print 'Setting yunit', self.yunit
            ax.set_display_unit(y=self.yunit)


        if self.yticks is not None:
            if isinstance( self.yticks, int):
                ax.set_yaxis_maxnlocator(self.yticks)
            elif is_iterable(self.yticks):

                #print 'yticks', self.yticks
                ax.set_yticks(self.yticks)
            else:
                assert False


        if self.show_yticklabels:
            #print 'yticks', ax.get_yticks()
            ylocs = [float(ytick.rescale(ax.xyUnitDisplay[1])) for ytick in ax.get_yticks()]
            # This call makes sure that we only display as many deciaml places as is sensible.
            yticklabels = float_list_to_string(ylocs)
            ax.set_yticklabels(yticklabels, include_unit=self.show_yticklabels_with_units)
        else:
            ax.set_yticklabels('')

            
        #TODO: Something funky is going on and this is not making a difference
        if self.ymargin is not None:
            ax.set_ymargin(self.ymargin)
Exemple #2
0
    def format_axes(self, ax):

        ax.set_ylabel(self.ylabel)
        if self.yrange is not None:
            ax.set_ylim(self.yrange)
        if self.yunit is not None:
            # print 'Setting yunit', self.yunit
            ax.set_display_unit(y=self.yunit)

        if self.yticks is not None:
            if isinstance(self.yticks, int):
                ax.set_yaxis_maxnlocator(self.yticks)
            elif is_iterable(self.yticks):

                # print 'yticks', self.yticks
                ax.set_yticks(self.yticks)
            else:
                assert False

        if self.show_yticklabels:
            # print 'yticks', ax.get_yticks()
            ylocs = [float(ytick.rescale(ax.xyUnitDisplay[1])) for ytick in ax.get_yticks()]
            # This call makes sure that we only display as many deciaml places as is sensible.
            yticklabels = float_list_to_string(ylocs)
            ax.set_yticklabels(yticklabels, include_unit=self.show_yticklabels_with_units)
        else:
            ax.set_yticklabels("")

        # TODO: Something funky is going on and this is not making a difference
        if self.ymargin is not None:
            ax.set_ymargin(self.ymargin)
Exemple #3
0
    def format_axes(self, ax):


        ax.set_ylabel(self.ylabel)
        if self.yrange is not None:
            ax.set_ylim(self.yrange)
        if self.yunit is not None:
            ax.set_display_unit(y=self.yunit)


        if self.yticks is not None:
            if isinstance( self.yticks, int):
                if self.yticks==0:
                    ax.set_yaxis_nulllocator()
                else:
                    ax.set_yaxis_maxnlocator(self.yticks)
            elif is_iterable(self.yticks):
                ax.set_yaxis_fixedlocator(self.yticks)
            else:
                assert False
            # If we set yticks manually, then we might also set yticklabels.
            if self.yticklabels is not None:
                ax.set_yticklabels(self.yticklabels)

        if self.yticklabels is None:
            ax.set_yticklabel_mode(show_ticklabels=self.show_yticklabels, include_units=self.show_yticklabels_with_units)

        #TODO: Something funky is going on and this is not making a difference
        if self.ymargin is not None:
            ax.set_ymargin(self.ymargin)
Exemple #4
0
    def __init__(
        self,
        srcs,
        plots=None,
        additional_plots=None,
        figtitle=None,
        fig_kwargs=None,
        show=True,
        linkage=None,
        timerange=None,
        mpl_tight_bounds=False,

        share_x_labels=True,

        nxticks=4, 
        show_xlabel='only-once',
        show_xticklabels='only-once',
        show_xticklabels_with_units=True,
        show_xaxis_position='bottom',
        xticks=None

        ):
        """Plot a set of traces.

        Keyword arguments:
        plots -- 
        srcs --
        plots --
        additional_plots -- 
        figtitle --
        fig_kwargs --
        show --
        linkage --
        timerange -- 
        mpl_tight_bounds --
        share_x_labels --

        nxticks=4, 
        show_xlabel -- which plots should the x-axis be displayed on.
        show_xticklabels --
        show_xticklabels_with_units -- 
        show_xaxis_position --
        xticks -- 
        """

        if fig_kwargs is None:
            fig_kwargs = self._default_fig_kwargs

        self.linkage = linkage


        if not is_iterable(srcs):
            srcs = [srcs]

        # For each type of input (in 'srcs'); this should return a list of traces:
        self.all_trace_objs = []
        self.all_event_set_objs = []
        trace_extractors = {
            SimulationResult:   lambda obj: self.all_trace_objs.extend(obj.traces),
            TraceFixedDT:       lambda obj: self.all_trace_objs.append(obj),
            TraceVariableDT:    lambda obj: self.all_trace_objs.append(obj),
            TracePiecewise:     lambda obj: self.all_trace_objs.append(obj),
            EventSet:           lambda obj: self.all_event_set_objs.append(obj)
                            }

        for obj in srcs:
            tr_extractor = trace_extractors[type(obj)]
            tr_extractor(obj)

        # Use the new PlotSpec architecture:
        # Filter out which plots are actually going to display something,
        # and filter out the rest:
        plots = plots if plots is not None else TagViewer._default_plot_specs

        if additional_plots:
            plots = tuple(list(plots) + list(additional_plots))

        self.plot_specs = [plotspec for plotspec in plots if
                            [tr for tr in self.all_trace_objs if plotspec.addtrace_predicate(tr)] or  \
                            [evset for evset in self.all_event_set_objs if plotspec.addeventset_predicate(evset)] \
                          ]


        self.fig_kwargs = fig_kwargs
        self.figtitle = figtitle
        self.mpl_tight_bounds = mpl_tight_bounds

        self.timerange = timerange
        self.share_x_labels = share_x_labels
        self.nxticks = nxticks


        # X-axis configuration:
        self.show_xlabel = show_xlabel
        self.show_xticklabels = show_xticklabels
        self.show_xticklabels_with_units = show_xticklabels_with_units
        self.show_xaxis_position = show_xaxis_position
        self.xticks=xticks
        assert self.show_xlabel in self._options_show_xlabel, 'Invalid'
        assert self.show_xticklabels in self._options_show_xticklabels
        assert self.show_xticklabels_with_units in self._options_show_xticklabels_with_units
        assert self.show_xaxis_position in self._options_show_xaxis_position 
        if is_iterable( self.xticks ) and all( [isinstance(xtick, (int, float)) for xtick in self.xticks]):
            self.xticks = [ xtick*pq.ms for xtick in self.xticks]
        assert self.xticks is None or isinstance(self.xticks, int) or ( is_iterable(self.xticks) and [ unit(xtick) for xtick in self.xticks] )


        self.fig = None
        self.subaxes = []
        self.create_figure()


        if TagViewer.MPL_AUTO_SHOW and show:
            import pylab
            pylab.show()
Exemple #5
0
    def __init__(self,
                 srcs,
                 plots=None,
                 additional_plots=None,
                 figtitle=None,
                 fig_kwargs=None,
                 show=True,
                 linkage=None,
                 timerange=None,
                 mpl_tight_bounds=False,
                 share_x_labels=True,
                 nxticks=4,
                 show_xlabel='only-once',
                 show_xticklabels='only-once',
                 show_xticklabels_with_units=True,
                 show_xaxis_position='bottom',
                 xticks=None):
        """Plot a set of traces.

        Keyword arguments:
        plots -- 
        srcs --
        plots --
        additional_plots -- 
        figtitle --
        fig_kwargs --
        show --
        linkage --
        timerange -- 
        mpl_tight_bounds --
        share_x_labels --

        nxticks=4, 
        show_xlabel -- which plots should the x-axis be displayed on.
        show_xticklabels --
        show_xticklabels_with_units -- 
        show_xaxis_position --
        xticks -- 
        """

        if fig_kwargs is None:
            fig_kwargs = self._default_fig_kwargs

        self.linkage = linkage

        if not is_iterable(srcs):
            srcs = [srcs]

        # For each type of input (in 'srcs'); this should return a list of traces:
        self.all_trace_objs = []
        self.all_event_set_objs = []
        trace_extractors = {
            SimulationResult:
            lambda obj: self.all_trace_objs.extend(obj.traces),
            TraceFixedDT: lambda obj: self.all_trace_objs.append(obj),
            TraceVariableDT: lambda obj: self.all_trace_objs.append(obj),
            TracePiecewise: lambda obj: self.all_trace_objs.append(obj),
            EventSet: lambda obj: self.all_event_set_objs.append(obj)
        }

        for obj in srcs:
            tr_extractor = trace_extractors[type(obj)]
            tr_extractor(obj)

        # Use the new PlotSpec architecture:
        # Filter out which plots are actually going to display something,
        # and filter out the rest:
        plots = plots if plots is not None else TagViewer._default_plot_specs

        if additional_plots:
            plots = tuple(list(plots) + list(additional_plots))

        self.plot_specs = [plotspec for plotspec in plots if
                            [tr for tr in self.all_trace_objs if plotspec.addtrace_predicate(tr)] or  \
                            [evset for evset in self.all_event_set_objs if plotspec.addeventset_predicate(evset)] \
                          ]

        self.fig_kwargs = fig_kwargs
        self.figtitle = figtitle
        self.mpl_tight_bounds = mpl_tight_bounds

        self.timerange = timerange
        self.share_x_labels = share_x_labels
        self.nxticks = nxticks

        # X-axis configuration:
        self.show_xlabel = show_xlabel
        self.show_xticklabels = show_xticklabels
        self.show_xticklabels_with_units = show_xticklabels_with_units
        self.show_xaxis_position = show_xaxis_position
        self.xticks = xticks
        assert self.show_xlabel in self._options_show_xlabel, 'Invalid'
        assert self.show_xticklabels in self._options_show_xticklabels
        assert self.show_xticklabels_with_units in self._options_show_xticklabels_with_units
        assert self.show_xaxis_position in self._options_show_xaxis_position
        if is_iterable(self.xticks) and all(
            [isinstance(xtick, (int, float)) for xtick in self.xticks]):
            self.xticks = [xtick * pq.ms for xtick in self.xticks]
        assert self.xticks is None or isinstance(
            self.xticks, int) or (is_iterable(self.xticks)
                                  and [unit(xtick) for xtick in self.xticks])

        self.fig = None
        self.subaxes = []
        self.create_figure()

        if TagViewer.MPL_AUTO_SHOW and show:
            import pylab
            pylab.show()