示例#1
0
    def _view_2d(self,
                 with_labels=None,
                 without_labels=None,
                 group='group',
                 figure_id=None,
                 new_figure=False,
                 image_view=True,
                 render_lines=True,
                 line_colour=None,
                 line_style='-',
                 line_width=1,
                 render_markers=True,
                 marker_style='o',
                 marker_size=20,
                 marker_face_colour='r',
                 marker_edge_colour='k',
                 marker_edge_width=1.,
                 render_numbering=False,
                 numbers_horizontal_align='center',
                 numbers_vertical_align='bottom',
                 numbers_font_name='sans-serif',
                 numbers_font_size=10,
                 numbers_font_style='normal',
                 numbers_font_weight='normal',
                 numbers_font_colour='k',
                 render_legend=True,
                 legend_title='',
                 legend_font_name='sans-serif',
                 legend_font_style='normal',
                 legend_font_size=10,
                 legend_font_weight='normal',
                 legend_marker_scale=None,
                 legend_location=2,
                 legend_bbox_to_anchor=(1.05, 1.),
                 legend_border_axes_pad=None,
                 legend_n_columns=1,
                 legend_horizontal_spacing=None,
                 legend_vertical_spacing=None,
                 legend_border=True,
                 legend_border_padding=None,
                 legend_shadow=False,
                 legend_rounded_corners=False,
                 render_axes=True,
                 axes_font_name='sans-serif',
                 axes_font_size=10,
                 axes_font_style='normal',
                 axes_font_weight='normal',
                 axes_x_limits=None,
                 axes_y_limits=None,
                 figure_size=None):
        """
        Visualize the landmark group.

        Parameters
        ----------
        with_labels : ``None`` or `str` or `list` of `str`, optional
            If not ``None``, only show the given label(s). Should **not** be
            used with the ``without_labels`` kwarg.
        without_labels : ``None`` or `str` or `list` of `str`, optional
            If not ``None``, show all except the given label(s). Should **not**
            be used with the ``with_labels`` kwarg.
        group : `str` or `None`, optional
            The landmark group to be visualized. If ``None`` and there are more
            than one landmark groups, an error is raised.
        figure_id : `object`, optional
            The id of the figure to be used.
        new_figure : `bool`, optional
            If ``True``, a new figure is created.
        image_view : `bool`, optional
            If ``True``, the x and y axes are flipped.
        render_lines : `bool`, optional
            If ``True``, the edges will be rendered.
        line_colour : {``r``, ``g``, ``b``, ``c``, ``m``, ``k``, ``w``} or
                      ``(3, )`` `ndarray` or ``None``, optional
            The colour of the lines. If ``None``, a different colour will be
            automatically selected for each label.
        line_style : {``-``, ``--``, ``-.``, ``:``}, optional
            The style of the lines.
        line_width : `float`, optional
            The width of the lines.
        render_markers : `bool`, optional
            If ``True``, the markers will be rendered.
        marker_style : {``.``, ``,``, ``o``, ``v``, ``^``, ``<``, ``>``, ``+``,
                        ``x``, ``D``, ``d``, ``s``, ``p``, ``*``, ``h``, ``H``,
                        ``1``, ``2``, ``3``, ``4``, ``8``}, optional
            The style of the markers.
        marker_size : `int`, optional
            The size of the markers in points^2.
        marker_face_colour : {``r``, ``g``, ``b``, ``c``, ``m``, ``k``, ``w``}
                             or ``(3, )`` `ndarray`, optional
            The face (filling) colour of the markers.
        marker_edge_colour : {``r``, ``g``, ``b``, ``c``, ``m``, ``k``, ``w``}
                             or ``(3, )`` `ndarray`, optional
            The edge colour of the markers.
        marker_edge_width : `float`, optional
            The width of the markers' edge.
        render_numbering : `bool`, optional
            If ``True``, the landmarks will be numbered.
        numbers_horizontal_align : {``center``, ``right``, ``left``}, optional
            The horizontal alignment of the numbers' texts.
        numbers_vertical_align : {``center``, ``top``, ``bottom``,
                                  ``baseline``}, optional
            The vertical alignment of the numbers' texts.
        numbers_font_name : {``serif``, ``sans-serif``, ``cursive``,
                             ``fantasy``, ``monospace``}, optional
            The font of the numbers.
        numbers_font_size : `int`, optional
            The font size of the numbers.
        numbers_font_style : {``normal``, ``italic``, ``oblique``}, optional
            The font style of the numbers.
        numbers_font_weight : {``ultralight``, ``light``, ``normal``,
                               ``regular``, ``book``, ``medium``, ``roman``,
                               ``semibold``, ``demibold``, ``demi``, ``bold``,
                               ``heavy``, ``extra bold``, ``black``}, optional
            The font weight of the numbers.
        numbers_font_colour : {``r``, ``g``, ``b``, ``c``, ``m``, ``k``, ``w``}
                              or ``(3, )`` `ndarray`, optional
            The font colour of the numbers.
        render_legend : `bool`, optional
            If ``True``, the legend will be rendered.
        legend_title : `str`, optional
            The title of the legend.
        legend_font_name : {``serif``, ``sans-serif``, ``cursive``,
                            ``fantasy``, ``monospace``}, optional
            The font of the legend.
        legend_font_style : {``normal``, ``italic``, ``oblique``}, optional
            The font style of the legend.
        legend_font_size : `int`, optional
            The font size of the legend.
        legend_font_weight : {``ultralight``, ``light``, ``normal``,
                              ``regular``, ``book``, ``medium``, ``roman``,
                              ``semibold``, ``demibold``, ``demi``, ``bold``,
                              ``heavy``, ``extra bold``, ``black``}, optional
            The font weight of the legend.
        legend_marker_scale : `float`, optional
            The relative size of the legend markers with respect to the original
        legend_location : `int`, optional
            The location of the legend. The predefined values are:

            =============== ===
            'best'          0
            'upper right'   1
            'upper left'    2
            'lower left'    3
            'lower right'   4
            'right'         5
            'center left'   6
            'center right'  7
            'lower center'  8
            'upper center'  9
            'center'        10
            =============== ===

        legend_bbox_to_anchor : (`float`, `float`), optional
            The bbox that the legend will be anchored.
        legend_border_axes_pad : `float`, optional
            The pad between the axes and legend border.
        legend_n_columns : `int`, optional
            The number of the legend's columns.
        legend_horizontal_spacing : `float`, optional
            The spacing between the columns.
        legend_vertical_spacing : `float`, optional
            The vertical space between the legend entries.
        legend_border : `bool`, optional
            If ``True``, a frame will be drawn around the legend.
        legend_border_padding : `float`, optional
            The fractional whitespace inside the legend border.
        legend_shadow : `bool`, optional
            If ``True``, a shadow will be drawn behind legend.
        legend_rounded_corners : `bool`, optional
            If ``True``, the frame's corners will be rounded (fancybox).
        render_axes : `bool`, optional
            If ``True``, the axes will be rendered.
        axes_font_name : {``serif``, ``sans-serif``, ``cursive``, ``fantasy``,
                          ``monospace``}, optional
            The font of the axes.
        axes_font_size : `int`, optional
            The font size of the axes.
        axes_font_style : {``normal``, ``italic``, ``oblique``}, optional
            The font style of the axes.
        axes_font_weight : {``ultralight``, ``light``, ``normal``, ``regular``,
                            ``book``, ``medium``, ``roman``, ``semibold``,
                            ``demibold``, ``demi``, ``bold``, ``heavy``,
                            ``extra bold``, ``black``}, optional
            The font weight of the axes.
        axes_x_limits : (`float`, `float`) or `None`, optional
            The limits of the x axis.
        axes_y_limits : (`float`, `float`) or `None`, optional
            The limits of the y axis.
        figure_size : (`float`, `float`) or `None`, optional
            The size of the figure in inches.

        Raises
        ------
        ValueError
            If both ``with_labels`` and ``without_labels`` are passed.
        """
        from menpo.visualize import LandmarkViewer2d
        if with_labels is not None and without_labels is not None:
            raise ValueError('You may only pass one of `with_labels` or '
                             '`without_labels`.')
        elif with_labels is not None:
            lmark_group = self.with_labels(with_labels)
        elif without_labels is not None:
            lmark_group = self.without_labels(without_labels)
        else:
            lmark_group = self  # Fall through
        landmark_viewer = LandmarkViewer2d(figure_id, new_figure, group,
                                           lmark_group._pointcloud,
                                           lmark_group._labels_to_masks)
        return landmark_viewer.render(
            image_view=image_view,
            render_lines=render_lines,
            line_colour=line_colour,
            line_style=line_style,
            line_width=line_width,
            render_markers=render_markers,
            marker_style=marker_style,
            marker_size=marker_size,
            marker_face_colour=marker_face_colour,
            marker_edge_colour=marker_edge_colour,
            marker_edge_width=marker_edge_width,
            render_numbering=render_numbering,
            numbers_horizontal_align=numbers_horizontal_align,
            numbers_vertical_align=numbers_vertical_align,
            numbers_font_name=numbers_font_name,
            numbers_font_size=numbers_font_size,
            numbers_font_style=numbers_font_style,
            numbers_font_weight=numbers_font_weight,
            numbers_font_colour=numbers_font_colour,
            render_legend=render_legend,
            legend_title=legend_title,
            legend_font_name=legend_font_name,
            legend_font_style=legend_font_style,
            legend_font_size=legend_font_size,
            legend_font_weight=legend_font_weight,
            legend_marker_scale=legend_marker_scale,
            legend_location=legend_location,
            legend_bbox_to_anchor=legend_bbox_to_anchor,
            legend_border_axes_pad=legend_border_axes_pad,
            legend_n_columns=legend_n_columns,
            legend_horizontal_spacing=legend_horizontal_spacing,
            legend_vertical_spacing=legend_vertical_spacing,
            legend_border=legend_border,
            legend_border_padding=legend_border_padding,
            legend_shadow=legend_shadow,
            legend_rounded_corners=legend_rounded_corners,
            render_axes=render_axes,
            axes_font_name=axes_font_name,
            axes_font_size=axes_font_size,
            axes_font_style=axes_font_style,
            axes_font_weight=axes_font_weight,
            axes_x_limits=axes_x_limits,
            axes_y_limits=axes_y_limits,
            figure_size=figure_size)
示例#2
0
    def _view_2d(
            self,
            with_labels=None,
            without_labels=None,
            group="group",
            figure_id=None,
            new_figure=False,
            image_view=True,
            render_lines=True,
            line_colour=None,
            line_style="-",
            line_width=1,
            render_markers=True,
            marker_style="o",
            marker_size=5,
            marker_face_colour=None,
            marker_edge_colour=None,
            marker_edge_width=1.0,
            render_numbering=False,
            numbers_horizontal_align="center",
            numbers_vertical_align="bottom",
            numbers_font_name="sans-serif",
            numbers_font_size=10,
            numbers_font_style="normal",
            numbers_font_weight="normal",
            numbers_font_colour="k",
            render_legend=True,
            legend_title="",
            legend_font_name="sans-serif",
            legend_font_style="normal",
            legend_font_size=10,
            legend_font_weight="normal",
            legend_marker_scale=None,
            legend_location=2,
            legend_bbox_to_anchor=(1.05, 1.0),
            legend_border_axes_pad=None,
            legend_n_columns=1,
            legend_horizontal_spacing=None,
            legend_vertical_spacing=None,
            legend_border=True,
            legend_border_padding=None,
            legend_shadow=False,
            legend_rounded_corners=False,
            render_axes=True,
            axes_font_name="sans-serif",
            axes_font_size=10,
            axes_font_style="normal",
            axes_font_weight="normal",
            axes_x_limits=None,
            axes_y_limits=None,
            axes_x_ticks=None,
            axes_y_ticks=None,
            figure_size=(10, 8),
    ):
        """
        Visualize the labelled point undirected graph.

        Parameters
        ----------
        with_labels : ``None`` or `str` or `list` of `str`, optional
            If not ``None``, only show the given label(s). Should **not** be
            used with the ``without_labels`` kwarg.
        without_labels : ``None`` or `str` or `list` of `str`, optional
            If not ``None``, show all except the given label(s). Should **not**
            be used with the ``with_labels`` kwarg.
        group : `str` or `None`, optional
            The name of the labelled point undirected graph. It is used in
            the legend.
        figure_id : `object`, optional
            The id of the figure to be used.
        new_figure : `bool`, optional
            If ``True``, a new figure is created.
        image_view : `bool`, optional
            If ``True``, the x and y axes are flipped.
        render_lines : `bool`, optional
            If ``True``, the edges will be rendered.
        line_colour : See Below, optional
            The colour of the lines.
            Example options::

                {r, g, b, c, m, k, w}
                or
                (3, ) ndarray

            It can either be one of the above or a `list` of those defining a
            value per label.
        line_style : ``{'-', '--', '-.', ':'}``, optional
            The style of the lines.
        line_width : `float`, optional
            The width of the lines.
        render_markers : `bool`, optional
            If ``True``, the markers will be rendered.
        marker_style : See Below, optional
            The style of the markers. Example options ::

                {., ,, o, v, ^, <, >, +, x, D, d, s, p, *, h, H, 1, 2, 3, 4, 8}

        marker_size : `int`, optional
            The size of the markers in points.
        marker_face_colour : See Below, optional
            The face (filling) colour of the markers.
            Example options ::

                {r, g, b, c, m, k, w}
                or
                (3, ) ndarray

            It can either be one of the above or a `list` of those defining a
            value per label.
        marker_edge_colour : See Below, optional
            The edge colour of the markers.
            Example options ::

                {r, g, b, c, m, k, w}
                or
                (3, ) ndarray

            It can either be one of the above or a `list` of those defining a
            value per label.
        marker_edge_width : `float`, optional
            The width of the markers' edge.
        render_numbering : `bool`, optional
            If ``True``, the landmarks will be numbered.
        numbers_horizontal_align : ``{center, right, left}``, optional
            The horizontal alignment of the numbers' texts.
        numbers_vertical_align : ``{center, top, bottom, baseline}``, optional
            The vertical alignment of the numbers' texts.
        numbers_font_name : See Below, optional
            The font of the numbers. Example options ::

                {serif, sans-serif, cursive, fantasy, monospace}

        numbers_font_size : `int`, optional
            The font size of the numbers.
        numbers_font_style : ``{normal, italic, oblique}``, optional
            The font style of the numbers.
        numbers_font_weight : See Below, optional
            The font weight of the numbers.
            Example options ::

                {ultralight, light, normal, regular, book, medium, roman,
                semibold, demibold, demi, bold, heavy, extra bold, black}

        numbers_font_colour : See Below, optional
            The font colour of the numbers.
            Example options ::

                {r, g, b, c, m, k, w}
                or
                (3, ) ndarray

        render_legend : `bool`, optional
            If ``True``, the legend will be rendered.
        legend_title : `str`, optional
            The title of the legend.
        legend_font_name : See Below, optional
            The font of the legend.
            Possible options ::

                {serif, sans-serif, cursive, fantasy, monospace}

        legend_font_style : {``normal``, ``italic``, ``oblique``}, optional
            The font style of the legend.
        legend_font_size : `int`, optional
            The font size of the legend.
        legend_font_weight : See Below, optional
            The font weight of the legend.
            Possible options ::

                {ultralight, light, normal, regular, book, medium, roman,
                 semibold, demibold, demi, bold, heavy, extra bold, black}

        legend_marker_scale : `float`, optional
            The relative size of the legend markers with respect to the original
        legend_location : `int`, optional
            The location of the legend. The predefined values are:

            =============== ===
            'best'          0
            'upper right'   1
            'upper left'    2
            'lower left'    3
            'lower right'   4
            'right'         5
            'center left'   6
            'center right'  7
            'lower center'  8
            'upper center'  9
            'center'        10
            =============== ===

        legend_bbox_to_anchor : (`float`, `float`), optional
            The bbox that the legend will be anchored.
        legend_border_axes_pad : `float`, optional
            The pad between the axes and legend border.
        legend_n_columns : `int`, optional
            The number of the legend's columns.
        legend_horizontal_spacing : `float`, optional
            The spacing between the columns.
        legend_vertical_spacing : `float`, optional
            The vertical space between the legend entries.
        legend_border : `bool`, optional
            If ``True``, a frame will be drawn around the legend.
        legend_border_padding : `float`, optional
            The fractional whitespace inside the legend border.
        legend_shadow : `bool`, optional
            If ``True``, a shadow will be drawn behind legend.
        legend_rounded_corners : `bool`, optional
            If ``True``, the frame's corners will be rounded (fancybox).
        render_axes : `bool`, optional
            If ``True``, the axes will be rendered.
        axes_font_name : See Below, optional
            The font of the axes.
            Example options ::

                {serif, sans-serif, cursive, fantasy, monospace}

        axes_font_size : `int`, optional
            The font size of the axes.
        axes_font_style : {``normal``, ``italic``, ``oblique``}, optional
            The font style of the axes.
        axes_font_weight : See Below, optional
            The font weight of the axes.
            Example options ::

                {ultralight, light, normal, regular, book, medium, roman,
                semibold, demibold, demi, bold, heavy, extra bold, black}

        axes_x_limits : `float` or (`float`, `float`) or ``None``, optional
            The limits of the x axis. If `float`, then it sets padding on the
            right and left of the LabelledPointUndirectedGraph as a percentage
            of the LabelledPointUndirectedGraph's width. If `tuple` or `list`,
            then it defines the axis limits. If ``None``, then the limits are
            set automatically.
        axes_y_limits : (`float`, `float`) `tuple` or ``None``, optional
            The limits of the y axis. If `float`, then it sets padding on the
            top and bottom of the LabelledPointUndirectedGraph as a percentage
            of the LabelledPointUndirectedGraph's height. If `tuple` or `list`,
            then it defines the axis limits. If ``None``, then the limits are
            set automatically.
        axes_x_ticks : `list` or `tuple` or ``None``, optional
            The ticks of the x axis.
        axes_y_ticks : `list` or `tuple` or ``None``, optional
            The ticks of the y axis.
        figure_size : (`float`, `float`) or `None`, optional
            The size of the figure in inches.

        Raises
        ------
        ValueError
            If both ``with_labels`` and ``without_labels`` are passed.
        """
        from menpo.visualize import LandmarkViewer2d

        if with_labels is not None and without_labels is not None:
            raise ValueError("You may only pass one of `with_labels` or "
                             "`without_labels`.")
        elif with_labels is not None:
            lmark_group = self.with_labels(with_labels)
        elif without_labels is not None:
            lmark_group = self.without_labels(without_labels)
        else:
            lmark_group = self  # Fall through
        landmark_viewer = LandmarkViewer2d(figure_id, new_figure, group,
                                           lmark_group)
        return landmark_viewer.render(
            image_view=image_view,
            render_lines=render_lines,
            line_colour=line_colour,
            line_style=line_style,
            line_width=line_width,
            render_markers=render_markers,
            marker_style=marker_style,
            marker_size=marker_size,
            marker_face_colour=marker_face_colour,
            marker_edge_colour=marker_edge_colour,
            marker_edge_width=marker_edge_width,
            render_numbering=render_numbering,
            numbers_horizontal_align=numbers_horizontal_align,
            numbers_vertical_align=numbers_vertical_align,
            numbers_font_name=numbers_font_name,
            numbers_font_size=numbers_font_size,
            numbers_font_style=numbers_font_style,
            numbers_font_weight=numbers_font_weight,
            numbers_font_colour=numbers_font_colour,
            render_legend=render_legend,
            legend_title=legend_title,
            legend_font_name=legend_font_name,
            legend_font_style=legend_font_style,
            legend_font_size=legend_font_size,
            legend_font_weight=legend_font_weight,
            legend_marker_scale=legend_marker_scale,
            legend_location=legend_location,
            legend_bbox_to_anchor=legend_bbox_to_anchor,
            legend_border_axes_pad=legend_border_axes_pad,
            legend_n_columns=legend_n_columns,
            legend_horizontal_spacing=legend_horizontal_spacing,
            legend_vertical_spacing=legend_vertical_spacing,
            legend_border=legend_border,
            legend_border_padding=legend_border_padding,
            legend_shadow=legend_shadow,
            legend_rounded_corners=legend_rounded_corners,
            render_axes=render_axes,
            axes_font_name=axes_font_name,
            axes_font_size=axes_font_size,
            axes_font_style=axes_font_style,
            axes_font_weight=axes_font_weight,
            axes_x_limits=axes_x_limits,
            axes_y_limits=axes_y_limits,
            axes_x_ticks=axes_x_ticks,
            axes_y_ticks=axes_y_ticks,
            figure_size=figure_size,
        )