function lvmPrintPlot(model, lbls, capName, experimentNo, colour)

% LVMPRINTPLOT Print latent space for learnt model.
%
%	Description:
%
%	LVMPRINTPLOT(MODEL, LBLS, CAPNAME, EXPERIMENTNO) prints a latent
%	space repsresentation for an LVM model.
%	 Arguments:
%	  MODEL - the model to use for plotting the latent space.
%	  LBLS - any lables that are available for plotting.
%	  CAPNAME - the name of the saved plots.
%	  EXPERIMENTNO - the experiment number to assign to the files.
%	
%
%	See also
%	LVMSCATTERPLOT

%   Copyright (c) 2013 ZhaoJing
%	Copyright (c) 2006 Neil D. Lawrence
% 	lvmPrintPlot.m SVN version 589
% 	last update 2009-11-08T13:06:39.000000Z
%   last update 2013-05-28

  if nargin < 5
    colour = 0;
  end
  if colour
    lvmScatterPlotColor(model, lbls);
  else
    lvmScatterPlot(model, lbls);
  end
  modelType = model.type;
  modelType(1) = upper(modelType(1));
  capName(1) = upper(capName(1));
  fileName = ['dem' capName modelType num2str(experimentNo)];
  %% modified by ZhaoJing 
  % ../tex/diagrams->tex/diagrams
  % ../html->html
 
  directory = ['tex/diagrams'];
  htmldir=['html'];
  %  2013-05-28 
  %%
  printPlot(fileName, directory, htmldir);
  
  figure
  clf
  ax = axes('position', [0.05 0.05 0.9 0.9]);
  hold on
  if size(model.X, 2)==2
    if ~isempty(lbls)
      if iscell(lbls) && ~strcmp(lbls{1}, 'connect')
        lvmTwoDPlot(model.X, lbls, getSymbols(size(lbls{1}, 2)));
      elseif  ~strcmp(lbls, 'connect') 
        lvmTwoDPlot(model.X, lbls, getSymbols(size(lbls, 2)));
      end
    else
      lvmTwoDPlot(model.X, lbls);
    end
  elseif size(model.X, 2)==3
    set(gca, 'cameraPosition', [-0.0901445 0.0899564 4.51826], ...
             'CameraPositionMode', 'auto', ...
             'CameraTarget', [-0.0901445 0.0899564 0.0139032], ...
             'CameraTargetMode', 'auto', ...
             'CameraUpVector', [0 1 0], ...
             'CameraUpVectorMode', 'auto', ...
             'CameraViewAngle', [6.60861], ...
             'CameraViewAngleMode', 'auto');
    
    hold on
    if ~isempty(lbls) && ~strcmp(lbls, 'connect')
      lvmThreeDPlot(model.X, lbls, getSymbols(size(lbls, 2)));
    else
      lvmThreeDPlot(model.X, lbls);
    end
  end
  for i = 1:size(model.X, 2)
    x1Min = min(model.X(:, i));
    x1Max = max(model.X(:, i));
    x1Span = x1Max - x1Min;
    x1Min = x1Min - 0.05*x1Span;
    x1Max = x1Max + 0.05*x1Span;
    lim{i} = [x1Min x1Max];
  end
  
  set(ax, 'xLim', lim{1});
  set(ax, 'yLim', lim{2});
  if size(model.X, 2) > 2
    set(ax, 'zLim', lim{3});
  end
  set(ax, 'fontname', 'arial');
  set(ax, 'fontsize', 20);
  %% modified by ZhaoJing 
  % ../tex/diagrams->tex/diagrams
  % ../html->html
  htmldir='html';
  % 2013-05-28
  %%
  printPlot([fileName 'NoGray'], directory, htmldir);
  %print('-depsc', ['../tex/diagrams/' fileName 'NoGray'])
  %print('-deps', ['../tex/diagrams/' fileName 'NoGrayNoColour'])
end