Ejemplo n.º 1
0
    def _resolve(self, permute, concat):
        """Determine what data to plot on which axis"""
        pivot_vals, len_pivots = self.c_mgr.generate_pivots(permute)
        pivot_vals = list(pivot_vals)

        num_of_axes = len(self.c_mgr) if concat else len_pivots

        # Create a 2D Layout
        self._layout = PlotLayout(self._attr["per_line"],
                                  num_of_axes,
                                  width=self._attr["width"],
                                  length=self._attr["length"],
                                  title=self._attr['title'])

        self._fig = self._layout.get_fig()

        # Determine what constraint to plot and the corresponding pivot value
        if permute:
            legend_len = self.c_mgr._max_len
            pivots = [y for _, y in pivot_vals]
            c_dict = {c: str(c) for c in self.c_mgr}
            c_list = sorted(c_dict.items(),
                            key=lambda x:
                            (x[1].split(":")[-1], x[1].split(":")[0]))
            constraints = [c[0] for c in c_list]
            cp_pairs = [(c, p) for c in constraints
                        for p in sorted(set(pivots))]
        else:
            legend_len = len_pivots if concat else len(self.c_mgr)
            pivots = pivot_vals
            cp_pairs = [(c, p) for c in self.c_mgr for p in pivots
                        if p in c.result]

        # Initialise legend data and colormap
        self._attr["_legend_handles"] = [None] * legend_len
        self._attr["_legend_labels"] = [None] * legend_len

        if "colors" in self._attr:
            self._cmap = ColorMap.rgb_cmap(self._attr["colors"])
        else:
            self._cmap = ColorMap(legend_len)

        # Group constraints/series with the axis they are to be plotted on
        figure_data = ddict(list)
        for i, (constraint, pivot) in enumerate(cp_pairs):
            axis = self._layout.get_axis(
                constraint.trace_index if concat else i)
            figure_data[axis].append((constraint, pivot))

        # Plot each axis
        for axis, series_list in figure_data.items():
            self.plot_axis(axis, series_list, permute, self._attr["concat"],
                           self._attr["args_to_forward"])
            if self._attr["xlim"]:
                axis.set_xlim(self._attr["xlim"])
            if self._attr["ylim"]:
                axis.set_ylim(self._attr["ylim"])

        # Show legend
        legend = self._fig.legend(self._attr["_legend_handles"],
                                  self._attr["_legend_labels"],
                                  loc='lower center',
                                  ncol=self._attr["legend_ncol"],
                                  borderaxespad=0.)
        legend.get_frame().set_facecolor('#F4F4F4')

        self._layout.finish(num_of_axes)
Ejemplo n.º 2
0
    def _resolve(self, permute, concat):
        """Determine what data to plot on which axis"""
        pivot_vals, len_pivots = self.c_mgr.generate_pivots(permute)
        pivot_vals = list(pivot_vals)

        num_of_axes = len(self.c_mgr) if concat else len_pivots

        # Create a 2D Layout
        self._layout = PlotLayout(
            self._attr["per_line"],
            num_of_axes,
            width=self._attr["width"],
            length=self._attr["length"],
            title=self._attr['title'])

        self._fig = self._layout.get_fig()

        # Determine what constraint to plot and the corresponding pivot value
        if permute:
            legend_len = self.c_mgr._max_len
            pivots = [y for _, y in pivot_vals]
            c_dict = {c : str(c) for c in self.c_mgr}
            c_list = sorted(c_dict.items(), key=lambda x: (x[1].split(":")[-1], x[1].split(":")[0]))
            constraints = [c[0] for c in c_list]
            cp_pairs = [(c, p) for c in constraints for p in sorted(set(pivots))]
        else:
            legend_len = len_pivots if concat else len(self.c_mgr)
            pivots = pivot_vals
            cp_pairs = [(c, p) for c in self.c_mgr for p in pivots if p in c.result]

        # Initialise legend data and colormap
        self._attr["_legend_handles"] = [None] * legend_len
        self._attr["_legend_labels"] = [None] * legend_len

        if "colors" in self._attr:
            self._cmap = ColorMap.rgb_cmap(self._attr["colors"])
        else:
            self._cmap = ColorMap(legend_len)

        # Group constraints/series with the axis they are to be plotted on
        figure_data = ddict(list)
        for i, (constraint, pivot) in enumerate(cp_pairs):
            axis = self._layout.get_axis(constraint.trace_index if concat else i)
            figure_data[axis].append((constraint, pivot))

        # Plot each axis
        for axis, series_list in figure_data.iteritems():
            self.plot_axis(
                axis,
                series_list,
                permute,
                self._attr["concat"],
                self._attr["args_to_forward"]
            )
            if self._attr["xlim"]:
                axis.set_xlim(self._attr["xlim"])
            if self._attr["ylim"]:
                axis.set_ylim(self._attr["ylim"])

        # Show legend
        legend = self._fig.legend(self._attr["_legend_handles"],
                         self._attr["_legend_labels"],
                         loc='lower center',
                         ncol=self._attr["legend_ncol"],
                         borderaxespad=0.)
        legend.get_frame().set_facecolor('#F4F4F4')

        self._layout.finish(num_of_axes)