Пример #1
0
    def open_axes(self, ax, props):
        """Setup a new axes object (subplot in plotly).

        Plotly stores information about subplots in different 'xaxis' and
        'yaxis' objects which are numbered. These are just dictionaries
        included in the layout dictionary. This function takes information
        from the Exporter, fills in appropriate dictionary entries,
        and updates the layout dictionary. PlotlyRenderer keeps track of the
        number of plots by incrementing the axis_ct attribute.

        Setting the proper plot domain in plotly is a bit tricky. Refer to
        the documentation for mpltools.convert_x_domain and
        mpltools.convert_y_domain.

        Positional arguments:
        ax -- an mpl axes object. This will become a subplot in plotly.
        props.keys() -- [
            'axesbg',           (background color for axes obj)
            'axesbgalpha',      (alpha, or opacity for background)
            'bounds',           ((x0, y0, width, height) for axes)
            'dynamic',          (zoom/pan-able?)
            'axes',             (list: [xaxis, yaxis])
            'xscale',           (log, linear, or date)
            'yscale',
            'xlim',             (range limits for x)
            'ylim',
            'xdomain'           (xdomain=xlim, unless it's a date)
            'ydomain'
            ]

        """
        self.msg += "  Opening axes\n"
        self.current_mpl_ax = ax
        self.bar_containers = [c for c in ax.containers  # empty is OK
                               if c.__class__.__name__ == 'BarContainer']
        self.current_bars = []
        self.axis_ct += 1
        # set defaults in axes
        xaxis = go.layout.XAxis(
            anchor='y{0}'.format(self.axis_ct),
            zeroline=False,
            ticks='inside')
        yaxis = go.layout.YAxis(
            anchor='x{0}'.format(self.axis_ct),
            zeroline=False,
            ticks='inside')
        # update defaults with things set in mpl
        mpl_xaxis, mpl_yaxis = mpltools.prep_xy_axis(
            ax=ax,
            props=props,
            x_bounds=self.mpl_x_bounds,
            y_bounds=self.mpl_y_bounds)
        xaxis.update(mpl_xaxis)
        yaxis.update(mpl_yaxis)
        bottom_spine = mpltools.get_spine_visible(ax, 'bottom')
        top_spine = mpltools.get_spine_visible(ax, 'top')
        left_spine = mpltools.get_spine_visible(ax, 'left')
        right_spine = mpltools.get_spine_visible(ax, 'right')
        xaxis['mirror'] = mpltools.get_axis_mirror(bottom_spine, top_spine)
        yaxis['mirror'] = mpltools.get_axis_mirror(left_spine, right_spine)
        xaxis['showline'] = bottom_spine
        yaxis['showline'] = top_spine

        # put axes in our figure
        self.plotly_fig['layout']['xaxis{0}'.format(self.axis_ct)] = xaxis
        self.plotly_fig['layout']['yaxis{0}'.format(self.axis_ct)] = yaxis

        # let all subsequent dates be handled properly if required

        if 'type' in dir(xaxis) and xaxis['type'] == 'date':
            self.x_is_mpl_date = True
Пример #2
0
    def open_axes(self, ax, props):
        """Setup a new axes object (subplot in plotly).

        Plotly stores information about subplots in different 'xaxis' and
        'yaxis' objects which are numbered. These are just dictionaries
        included in the layout dictionary. This function takes information
        from the Exporter, fills in appropriate dictionary entries,
        and updates the layout dictionary. PlotlyRenderer keeps track of the
        number of plots by incrementing the axis_ct attribute.

        Setting the proper plot domain in plotly is a bit tricky. Refer to
        the documentation for mpltools.convert_x_domain and
        mpltools.convert_y_domain.

        Positional arguments:
        ax -- an mpl axes object. This will become a subplot in plotly.
        props.keys() -- [
            'axesbg',           (background color for axes obj)
            'axesbgalpha',      (alpha, or opacity for background)
            'bounds',           ((x0, y0, width, height) for axes)
            'dynamic',          (zoom/pan-able?)
            'axes',             (list: [xaxis, yaxis])
            'xscale',           (log, linear, or date)
            'yscale',
            'xlim',             (range limits for x)
            'ylim',
            'xdomain'           (xdomain=xlim, unless it's a date)
            'ydomain'
            ]

        """
        self.msg += "  Opening axes\n"
        self.current_mpl_ax = ax
        self.bar_containers = [c for c in ax.containers  # empty is OK
                               if c.__class__.__name__ == 'BarContainer']
        self.current_bars = []
        self.axis_ct += 1
        # set defaults in axes
        xaxis = go.XAxis(
            anchor='y{0}'.format(self.axis_ct),
            zeroline=False,
            ticks='inside')
        yaxis = go.YAxis(
            anchor='x{0}'.format(self.axis_ct),
            zeroline=False,
            ticks='inside')
        # update defaults with things set in mpl
        mpl_xaxis, mpl_yaxis = mpltools.prep_xy_axis(
            ax=ax,
            props=props,
            x_bounds=self.mpl_x_bounds,
            y_bounds=self.mpl_y_bounds)
        xaxis.update(mpl_xaxis)
        yaxis.update(mpl_yaxis)
        bottom_spine = mpltools.get_spine_visible(ax, 'bottom')
        top_spine = mpltools.get_spine_visible(ax, 'top')
        left_spine = mpltools.get_spine_visible(ax, 'left')
        right_spine = mpltools.get_spine_visible(ax, 'right')
        xaxis['mirror'] = mpltools.get_axis_mirror(bottom_spine, top_spine)
        yaxis['mirror'] = mpltools.get_axis_mirror(left_spine, right_spine)
        xaxis['showline'] = bottom_spine
        yaxis['showline'] = top_spine

        # put axes in our figure
        self.plotly_fig['layout']['xaxis{0}'.format(self.axis_ct)] = xaxis
        self.plotly_fig['layout']['yaxis{0}'.format(self.axis_ct)] = yaxis

        # let all subsequent dates be handled properly if required
        if xaxis.get('type') == 'date':
            self.x_is_mpl_date = True