Skip to content

Commit

Permalink
Merge pull request #545 from nontas/marker_multiple_colouring
Browse files Browse the repository at this point in the history
Different marker colour per label
  • Loading branch information
nontas committed Feb 2, 2015
2 parents 5bcce34 + 6d15e5d commit 6c417bd
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 32 deletions.
4 changes: 2 additions & 2 deletions menpo/image/base.py
Expand Up @@ -553,8 +553,8 @@ def _view_landmarks_2d(self, channels=None, group=None,
interpolation='bilinear', alpha=1.,
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.,
marker_size=20, marker_face_colour=None,
marker_edge_colour=None, marker_edge_width=1.,
render_numbering=False,
numbers_horizontal_align='center',
numbers_vertical_align='bottom',
Expand Down
6 changes: 3 additions & 3 deletions menpo/image/masked.py
Expand Up @@ -394,10 +394,10 @@ def _view_landmarks_2d(self, channels=None, masked=True, group=None,
with_labels=None, without_labels=None,
figure_id=None, new_figure=False,
interpolation='bilinear', alpha=1.,
render_lines=True, line_colour='r', line_style='-',
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.,
marker_size=20, marker_face_colour=None,
marker_edge_colour=None, marker_edge_width=1.,
render_numbering=False,
numbers_horizontal_align='center',
numbers_vertical_align='bottom',
Expand Down
8 changes: 4 additions & 4 deletions menpo/landmark/base.py
Expand Up @@ -586,9 +586,9 @@ 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',
marker_size=20, marker_face_colour=None,
marker_edge_colour=None, 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',
Expand All @@ -603,7 +603,7 @@ def _view_2d(self, with_labels=None, without_labels=None, group='group',
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):
axes_x_limits=None, axes_y_limits=None, figure_size=(10, 8)):
"""
Visualize the landmark group.
Expand Down
2 changes: 1 addition & 1 deletion menpo/shape/graph.py
Expand Up @@ -935,7 +935,7 @@ def _view_2d(self, figure_id=None, new_figure=False, image_view=True,
marker_edge_width=1., 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,
axes_x_limits=None, axes_y_limits=None, figure_size=(10, 8),
label=None):
r"""
Visualization of the PointGraph.
Expand Down
2 changes: 1 addition & 1 deletion menpo/shape/mesh/base.py
Expand Up @@ -196,7 +196,7 @@ def _view_2d(self, figure_id=None, new_figure=False, image_view=True,
marker_edge_width=1., 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,
axes_x_limits=None, axes_y_limits=None, figure_size=(10, 8),
label=None):
r"""
Visualization of the TriMesh.
Expand Down
2 changes: 1 addition & 1 deletion menpo/shape/mesh/coloured.py
Expand Up @@ -124,7 +124,7 @@ def _view_2d(self, figure_id=None, new_figure=False, image_view=True,
marker_edge_width=1., 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,
axes_x_limits=None, axes_y_limits=None, figure_size=(10, 8),
label=None):
import warnings
warnings.warn(Warning('2D Viewing of Coloured TriMeshes is not '
Expand Down
2 changes: 1 addition & 1 deletion menpo/shape/mesh/textured.py
Expand Up @@ -169,7 +169,7 @@ def _view_2d(self, figure_id=None, new_figure=False, image_view=True,
marker_edge_width=1., 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,
axes_x_limits=None, axes_y_limits=None, figure_size=(10, 8),
label=None):
import warnings
warnings.warn(Warning('2D Viewing of Textured TriMeshes is not '
Expand Down
8 changes: 4 additions & 4 deletions menpo/shape/pointcloud.py
Expand Up @@ -205,7 +205,7 @@ def _view_2d(self, figure_id=None, new_figure=False, image_view=True,
marker_edge_width=1., 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,
axes_x_limits=None, axes_y_limits=None, figure_size=(10, 8),
label=None, **kwargs):
r"""
Visualization of the PointCloud.
Expand Down Expand Up @@ -283,10 +283,10 @@ def _view_2d(self, figure_id=None, new_figure=False, image_view=True,
def _view_landmarks_2d(self, group=None, with_labels=None,
without_labels=None, figure_id=None,
new_figure=False, image_view=True, render_lines=True,
line_colour='r', line_style='-', line_width=1,
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.,
marker_size=20, marker_face_colour=None,
marker_edge_colour=None, marker_edge_width=1.,
render_numbering=False,
numbers_horizontal_align='center',
numbers_vertical_align='bottom',
Expand Down
47 changes: 41 additions & 6 deletions menpo/visualize/viewmatplotlib.py
Expand Up @@ -222,6 +222,8 @@ def render(self, interpolation='bilinear', alpha=1., render_axes=False,
l.set_fontweight(axes_font_weight)
else:
plt.axis('off')
plt.xticks([])
plt.yticks([])

# Set axes limits
if axes_x_limits is not None:
Expand Down Expand Up @@ -273,6 +275,8 @@ def render(self, interpolation='bilinear', alpha=1., render_axes=False,
l.set_fontweight(axes_font_weight)
else:
plt.axis('off')
plt.xticks([])
plt.yticks([])

# Set axes limits
if axes_x_limits is not None:
Expand Down Expand Up @@ -353,6 +357,8 @@ def render(self, image_view=False, render_lines=True, line_colour='r',
l.set_fontweight(axes_font_weight)
else:
plt.axis('off')
plt.xticks([])
plt.yticks([])

# Plot on image mode
if image_view:
Expand Down Expand Up @@ -404,18 +410,32 @@ def render(self, image_view=False, render_lines=True, line_colour='r',
axes_font_style='normal', axes_font_weight='normal',
axes_x_limits=None, axes_y_limits=None, figure_size=(10, 8)):
import matplotlib.pyplot as plt
import matplotlib.lines as mlines
from menpo.shape import PointGraph
# Regarding the labels colours, we may get passed either no colours (in
# which case we generate random colours) or a single colour to colour
# all the labels with
# TODO: All marker and line options could be defined as lists...
n_labels = len(self.labels_to_masks)
line_colour = _check_colours_list(
render_lines, line_colour, n_labels,
'Must pass a list of line colours with length n_labels or a single '
'line colour for all labels.')
marker_face_colour = _check_colours_list(
render_markers, marker_face_colour, n_labels,
'Must pass a list of marker face colours with length n_labels or '
'a single marker face colour for all labels.')
marker_edge_colour = _check_colours_list(
render_markers, marker_edge_colour, n_labels,
'Must pass a list of marker edge colours with length n_labels or '
'a single marker edge colour for all labels.')

# Get pointcloud of each label
sub_pointclouds = self._build_sub_pointclouds()

# Initialize legend_handles list
legend_handles = []

for i, (label, pc) in enumerate(sub_pointclouds):
# Set kwargs assuming that the pointclouds are viewed using
# Matplotlib
Expand All @@ -425,15 +445,14 @@ def render(self, image_view=False, render_lines=True, line_colour='r',
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_face_colour=marker_face_colour[i],
marker_edge_colour=marker_edge_colour[i],
marker_edge_width=marker_edge_width,
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=None,
axes_y_limits=None, figure_size=figure_size,
label='{0}: {1}'.format(self.group, label))
axes_y_limits=None, figure_size=figure_size)

ax = plt.gca()

Expand All @@ -448,6 +467,22 @@ def render(self, image_view=False, render_lines=True, line_colour='r',
fontweight=numbers_font_weight,
color=numbers_font_colour)

# set legend entry
if render_legend:
tmp_line = line_style
if not render_lines or not isinstance(pc, PointGraph):
tmp_line = 'None'
tmp_marker = marker_style if render_markers else 'None'
legend_handles.append(
mlines.Line2D([], [], linewidth=line_width,
linestyle=tmp_line, color=line_colour[i],
marker=tmp_marker,
markersize=marker_size ** 0.5,
markeredgewidth=marker_edge_width,
markeredgecolor=marker_edge_colour[i],
markerfacecolor=marker_face_colour[i],
label='{0}: {1}'.format(self.group, label)))

# Plot on image mode
if image_view:
plt.gca().set_aspect('equal', adjustable='box')
Expand All @@ -460,8 +495,8 @@ def render(self, image_view=False, render_lines=True, line_colour='r',
'weight': legend_font_weight}

# Render legend
ax.legend(title=legend_title, prop=prop, loc=legend_location,
bbox_to_anchor=legend_bbox_to_anchor,
ax.legend(handles=legend_handles, title=legend_title, prop=prop,
loc=legend_location, bbox_to_anchor=legend_bbox_to_anchor,
borderaxespad=legend_border_axes_pad,
ncol=legend_n_columns,
columnspacing=legend_horizontal_spacing,
Expand Down
18 changes: 9 additions & 9 deletions menpo/visualize/widgets/base.py
Expand Up @@ -103,14 +103,14 @@ def plot_function(name, value):

renderer = pointclouds[im].view(
figure_id=save_figure_wid.renderer[0].figure_id,
new_figure=False, image_view=axes_mode_wid.value==1,
new_figure=False, image_view=axes_mode_wid.value == 1,
render_lines=tmp1['render_lines'],
line_colour=tmp1['line_colour'][0],
line_style=tmp1['line_style'], line_width=tmp1['line_width'],
render_markers=tmp2['render_markers'],
marker_style=tmp2['marker_style'], marker_size=tmp2['marker_size'],
marker_face_colour=tmp2['marker_face_colour'],
marker_edge_colour=tmp2['marker_edge_colour'],
marker_face_colour=tmp2['marker_face_colour'][0],
marker_edge_colour=tmp2['marker_edge_colour'][0],
marker_edge_width=tmp2['marker_edge_width'],
render_axes=tmp3['render_axes'],
axes_font_name=tmp3['axes_font_name'],
Expand Down Expand Up @@ -391,8 +391,8 @@ def plot_function(name, value):
line_style=tmp1['line_style'], line_width=tmp1['line_width'],
render_markers=tmp2['render_markers'],
marker_style=tmp2['marker_style'], marker_size=tmp2['marker_size'],
marker_face_colour=tmp2['marker_face_colour'],
marker_edge_colour=tmp2['marker_edge_colour'],
marker_face_colour=tmp2['marker_face_colour'][0],
marker_edge_colour=tmp2['marker_edge_colour'][0],
marker_edge_width=tmp2['marker_edge_width'],
render_numbering=tmp3['render_numbering'],
numbers_font_name=tmp3['numbers_font_name'],
Expand Down Expand Up @@ -755,8 +755,8 @@ def plot_function(name, value):
line_style=tmp1['line_style'], line_width=tmp1['line_width'],
render_markers=tmp2['render_markers'],
marker_style=tmp2['marker_style'], marker_size=tmp2['marker_size'],
marker_face_colour=tmp2['marker_face_colour'],
marker_edge_colour=tmp2['marker_edge_colour'],
marker_face_colour=tmp2['marker_face_colour'][0],
marker_edge_colour=tmp2['marker_edge_colour'][0],
marker_edge_width=tmp2['marker_edge_width'],
render_numbering=tmp3['render_numbering'],
numbers_font_name=tmp3['numbers_font_name'],
Expand Down Expand Up @@ -1157,8 +1157,8 @@ def plot_function(name, value):
tmp1['render_lines'], tmp1['line_style'], tmp1['line_width'],
tmp1['line_colour'][:n_labels], tmp2['render_markers'],
tmp2['marker_style'], tmp2['marker_size'],
tmp2['marker_edge_width'], tmp2['marker_edge_colour'],
tmp2['marker_face_colour'], tmp3['render_numbering'],
tmp2['marker_edge_width'], tmp2['marker_edge_colour'][0],
tmp2['marker_face_colour'][0], tmp3['render_numbering'],
tmp3['numbers_font_name'], tmp3['numbers_font_size'],
tmp3['numbers_font_style'], tmp3['numbers_font_weight'],
tmp3['numbers_font_colour'][0], tmp3['numbers_horizontal_align'],
Expand Down

0 comments on commit 6c417bd

Please sign in to comment.