function show_mixtures(X,C);

[m n] = size(X);

if isfield(C,'c');
  absoluteassignment = 1;
else
  absoluteassignment = 0;
end

color = colormap;
color = color(ceil((.5:C.K)/C.K*size(color,1)),:);

subplot(122);
plot(C.J);
hold on
hj = plot(1,C.J(1),'x');
hold off
title('objective');

subplot(121);
if absoluteassignment == 0
  [r c] = max(C.r{1},[],1);
else
  c = C.c{1};
end
hl = zeros(1,m);
for i = 1:m
  hl(i) = plot([X(i,1) C.mu{1}(c(i),1)],[X(i,2) C.mu{1}(c(i),2)],'-',...
        'linewidth',1,'color',[.8 .8 .8]);
  hold on
end
hx = zeros(1,m);
for i = 1:m
  if absoluteassignment == 0
    col = C.r{1}(:,i)'*color;
  else
    col = color(C.c{1}(i),:);
  end
  hx(i) = plot(X(i,1),X(i,2),'.','markersize',10,'color',col);
end
hm = zeros(1,C.K);
hv = zeros(1,C.K);
for k = 1:C.K
  hm(k) = plot(C.mu{1}(k,1),C.mu{1}(k,2),'x',...
        'markersize',10,'linewidth',3,'color',color(k,:));
end
hold off
axis equal
title('cluster assignments');
drawnow

for iter = 2:C.iter

  set(hj,'xdata',iter,'ydata',C.J(iter));

  if absoluteassignment == 0
    [r c] = max(C.r{iter},[],1);
  else
    c = C.c{iter};
  end
  for i = 1:m
    set(hl(i),'xdata',[X(i,1) C.mu{iter}(c(i),1)],...
              'ydata',[X(i,2) C.mu{iter}(c(i),2)]);
  end
  for i = 1:m
    if absoluteassignment == 0
      col = C.r{iter}(:,i)'*color;
    else
      col = color(C.c{iter}(i),:);
    end
    set(hx(i),'color',col);
  end
  for k = 1:C.K
    set(hm(k),'xdata',C.mu{iter}(k,1),'ydata',C.mu{iter}(k,2));
  end
  drawnow
end
