function pwc_bars_2d ( nxc, nyc, xc, yc, vc )

%*****************************************************************************80
%
%% pwc_bars_2d() plots a piecewise constant function of (X,Y) as bars.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    07 April 2019
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer NXC, NYC, the number of columns and rows of data.
%
%    real XC(NXC+1), YC(NYC+1), the breakpoint coordinates.
%
%    real VC(NXC,NYC), the values.
%
  figure ( );
%
%  Determine the mapping between colors and values.
%
  zmax = max ( max ( vc ) );
  zmin = min ( min ( vc ) );
  caxis ( [ zmin, zmax ] );
%
%  Pick the colors that will correspond to the minimum and maximum
%  values of Z.
%
  rmax = 0.8;
  gmax = 0.2;
  bmax = 0.1;

  rmin = 0.1;
  gmin = 0.3;
  bmin = 0.7;
%
%  Start drawing!
%
  hold ( 'on' );

  for i = 1 : nyc

    y1 = yc(i);
    y2 = yc(i);
    y3 = yc(i+1);
    y4 = yc(i+1);

    for j = 1 : nxc

      x1 = xc(j);
      x2 = xc(j+1);
      x3 = xc(j+1);
      x4 = xc(j);

      z = vc(j,i);
%
%  Draw the top of the prism, using a color corresponding to the height.
%
      r = ( ( zmax - z ) * rmin + ( z - zmin ) * rmax ) / ( zmax - zmin );
      g = ( ( zmax - z ) * gmin + ( z - zmin ) * gmax ) / ( zmax - zmin );
      b = ( ( zmax - z ) * bmin + ( z - zmin ) * bmax ) / ( zmax - zmin );
    
      patch ( [ x1, x2, x3, x4 ], [ y1, y2, y3, y4 ], [ z, z, z, z ], z );
%
%  Draw the bottom of the prism, using black.
%
      rgb = zmin;
      patch ( [ x1, x2, x3, x4 ], [ y1, y2, y3, y4 ], [ 0, 0, 0, 0 ], rgb );
%
%  Draw the sides of the prism, using a lighter shade of the top color.
%
      rgb = zmin + 0.95 * ( z - zmin );
    
      patch ( [ x1, x2, x2, x1 ], [ y1, y2, y2, y1 ], [ 0, 0, z, z ], rgb );
      patch ( [ x2, x3, x3, x2 ], [ y2, y3, y3, y2 ], [ 0, 0, z, z ], rgb );
      patch ( [ x3, x4, x4, x3 ], [ y3, y4, y4, y3 ], [ 0, 0, z, z ], rgb );
      patch ( [ x4, x1, x1, x4 ], [ y4, y1, y1, y4 ], [ 0, 0, z, z ], rgb );

    end
  end

  xlabel ( '<--X-->', 'FontName', 'Helvetica', 'FontWeight', 'bold', ...
    'FontSize', 16 );

  ylabel ( '<--Y-->', 'FontName', 'Helvetica', 'FontWeight', 'bold', ...
    'FontSize', 16, 'Rotation', 0 );

  zlabel ( '<--Z(X,Y)-->', 'FontName', 'Helvetica', 'FontWeight', 'bold', ...
    'FontSize', 16 );

  datestring = datestr ( datevec ( now ), 0 );
  title ( { 'pwc bars 2d'; datestring }, 'fontsize', 16 );

  colorbar ( );

  view ( 3 );

  hold ( 'off' );

  filename = 'pwc_bars_2d.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  pause ( 5 );

  close ( );
  
  return
end
