Пример #1
0
    def _make_ts_plot(self, data, **kwargs):
        from pandas.tseries.plotting import tsplot

        plotf = self._get_plot_function()

        if isinstance(data, Series):
            if self.subplots: # shouldn't even allow users to specify
                ax = self.axes[0]
            else:
                ax = self.ax

            label = com._stringify(self.label)
            tsplot(data, plotf, ax=ax, label=label, **kwargs)
            ax.grid(self.grid)
        else:
            for i, col in enumerate(data.columns):
                if self.subplots:
                    ax = self.axes[i]
                else:
                    ax = self.ax
                label = com._stringify(col)
                tsplot(data[col], plotf, ax=ax, label=label, **kwargs)
                ax.grid(self.grid)

        self.fig.subplots_adjust(wspace=0, hspace=0)
Пример #2
0
    def _make_ts_plot(self, data, **kwargs):
        from pandas.tseries.plotting import tsplot

        plotf = self._get_plot_function()

        if isinstance(data, Series):
            ax, _ = self._get_ax_and_style(0) #self.axes[0]

            label = com._stringify(self.label)
            tsplot(data, plotf, ax=ax, label=label, style=self.style,
                   **kwargs)
            ax.grid(self.grid)
        else:
            for i, col in enumerate(data.columns):
                ax, _ = self._get_ax_and_style(i)
                label = com._stringify(col)
                tsplot(data[col], plotf, ax=ax, label=label, **kwargs)
                ax.grid(self.grid)
Пример #3
0
    def _iter_data(self):
        from pandas.core.frame import DataFrame
        if isinstance(self.data, (Series, np.ndarray)):
            yield com._stringify(self.label), np.asarray(self.data)
        elif isinstance(self.data, DataFrame):
            df = self.data

            if self.sort_columns:
                columns = com._try_sort(df.columns)
            else:
                columns = df.columns

            for col in columns:
                empty = df[col].count() == 0
                # is this right?
                values = df[col].values if not empty else np.zeros(len(df))

                col = com._stringify(col)
                yield col, values
Пример #4
0
    def _iter_data(self):
        from pandas.core.frame import DataFrame
        if isinstance(self.data, (Series, np.ndarray)):
            yield com._stringify(self.label), np.asarray(self.data)
        elif isinstance(self.data, DataFrame):
            df = self.data

            if self.sort_columns:
                columns = com._try_sort(df.columns)
            else:
                columns = df.columns

            for col in columns:
                empty = df[col].count() == 0
                # is this right?
                values = df[col].values if not empty else np.zeros(len(df))

                col = com._stringify(col)
                yield col, values
Пример #5
0
    def format(self, vertical=False):
        """
        Render a string representation of the Index
        """
        if self.is_all_dates():
            to_join = []
            zero_time = time(0, 0)
            for dt in self:
                if dt.time() != zero_time or dt.tzinfo is not None:
                    return ['%s' % x for x in self]
                to_join.append(dt.strftime("%Y-%m-%d"))
            return to_join

        return [_stringify(x) for x in self]
Пример #6
0
    def _make_ts_plot(self, data, **kwargs):
        from pandas.tseries.plotting import tsplot

        plotf = self._get_plot_function()

        if isinstance(data, Series):
            if self.subplots:  # shouldn't even allow users to specify
                ax = self.axes[0]
            else:
                ax = self.ax

            label = com._stringify(self.label)
            tsplot(data, plotf, ax=ax, label=label, style=self.style, **kwargs)
            ax.grid(self.grid)
        else:
            for i, col in enumerate(data.columns):
                if self.subplots:
                    ax = self.axes[i]
                else:
                    ax = self.ax
                label = com._stringify(col)
                tsplot(data[col], plotf, ax=ax, label=label, **kwargs)
                ax.grid(self.grid)
Пример #7
0
    def _make_plot(self):
        from scipy.stats import gaussian_kde
        plotf = self._get_plot_function()
        for i, (label, y) in enumerate(self._iter_data()):
            ax, style = self._get_ax_and_style(i, label)

            label = com._stringify(label)

            gkde = gaussian_kde(y)
            sample_range = max(y) - min(y)
            ind = np.linspace(min(y) - 0.5 * sample_range,
                max(y) + 0.5 * sample_range, 1000)
            ax.set_ylabel("Density")
            plotf(ax, ind, gkde.evaluate(ind), style, label=label, **self.kwds)
            ax.grid(self.grid)
Пример #8
0
    def _make_plot(self):
        colors = self.kwds.get('color', 'brgyk')
        rects = []
        labels = []

        ax = self._get_ax(0) #self.axes[0]

        bar_f = self.bar_f

        pos_prior = neg_prior = np.zeros(len(self.data))

        K = self.nseries

        for i, (label, y) in enumerate(self._iter_data()):
            label = com._stringify(label)
            kwds = self.kwds.copy()
            kwds['color'] = colors[i % len(colors)]

            if self.subplots:
                ax = self._get_ax(i) #self.axes[i]
                rect = bar_f(ax, self.ax_pos, y, 0.5, start=pos_prior,
                             linewidth=1, **kwds)
                ax.set_title(label)
            elif self.stacked:
                mask = y > 0
                start = np.where(mask, pos_prior, neg_prior)

                rect = bar_f(ax, self.ax_pos, y, 0.5, start=start,
                             label=label, linewidth=1, **kwds)
                pos_prior = pos_prior + np.where(mask, y, 0)
                neg_prior = neg_prior + np.where(mask, 0, y)
            else:
                rect = bar_f(ax, self.ax_pos + i * 0.75 / K, y, 0.75 / K,
                             start=pos_prior, label=label, **kwds)
            rects.append(rect)
            labels.append(label)

        if self.legend and not self.subplots:
            patches =[r[0] for r in rects]

            # Legend to the right of the plot
            # ax.legend(patches, labels, bbox_to_anchor=(1.05, 1),
            #           loc=2, borderaxespad=0.)
            # self.fig.subplots_adjust(right=0.80)

            ax.legend(patches, labels, loc='best',
                      title=self.legend_title)
Пример #9
0
def _replot_ax(ax, freq, plotf, kwargs):
    data = getattr(ax, '_plot_data', None)
    ax._plot_data = []
    ax.clear()
    _decorate_axes(ax, freq, kwargs)

    lines = []
    labels = []
    if data is not None:
        for series, kwds in data:
            series = series.copy()
            idx = series.index.asfreq(freq)
            series.index = idx
            ax._plot_data.append(series)
            args = _maybe_mask(series)
            lines.append(plotf(ax, *args, **kwds)[0])
            labels.append(com._stringify(series.name))

    return lines, labels
Пример #10
0
    def format(self, name=False):
        """
        Render a string representation of the Index
        """
        result = []

        if name:
            result.append(str(self.name) if self.name is not None else '')

        if self.is_all_dates():
            zero_time = time(0, 0)
            for dt in self:
                if dt.time() != zero_time or dt.tzinfo is not None:
                    return result + ['%s' % x for x in self]
                result.append(dt.strftime("%Y-%m-%d"))
            return result

        result.extend(_stringify(x) for x in self)

        return result
Пример #11
0
    def format(self, name=False):
        """
        Render a string representation of the Index
        """
        result = []

        if name:
            result.append(str(self.name) if self.name is not None else "")

        if self.is_all_dates():
            zero_time = time(0, 0)
            for dt in self:
                if dt.time() != zero_time or dt.tzinfo is not None:
                    return result + ["%s" % x for x in self]
                result.append(dt.strftime("%Y-%m-%d"))
            return result

        result.extend(_stringify(x) for x in self)

        return result
Пример #12
0
    def _make_plot(self):
        # this is slightly deceptive
        if self.use_index and self._use_dynamic_x():
            data = self._maybe_convert_index(self.data)
            self._make_ts_plot(data)
        else:
            x = self._get_xticks(convert_period=True)

            plotf = self._get_plot_function()

            for i, (label, y) in enumerate(self._iter_data()):
                ax, style = self._get_ax_and_style(i, label)

                label = com._stringify(label)

                mask = com.isnull(y)
                if mask.any():
                    y = np.ma.array(y)
                    y = np.ma.masked_where(mask, y)

                plotf(ax, x, y, style, label=label, **self.kwds)
                ax.grid(self.grid)
Пример #13
0
 def _strify(x):
     return _stringify(x, print_config.encoding)
Пример #14
0
 def _strify(x):
     return _stringify(x, print_config.encoding)