def hist(P, edges, **kwargs):
  r'''
Plot histogram.
  '''

  from matplotlib.collections import PatchCollection
  from matplotlib.patches     import Polygon

  # extract local options
  axis      = kwargs.pop( 'axis'      , plt.gca() )
  cindex    = kwargs.pop( 'cindex'    , None      )
  autoscale = kwargs.pop( 'autoscale' , True      )

  # set defaults
  kwargs.setdefault('edgecolor','k')

  # no color-index -> set transparent
  if cindex is None:
    kwargs.setdefault('facecolor',(0.,0.,0.,0.))

  # convert -> list of Polygons
  poly = []
  for p, xl, xu in zip(P, edges[:-1], edges[1:]):
    coor = np.array([
      [xl, 0.],
      [xu, 0.],
      [xu, p ],
      [xl, p ],
    ])
    poly.append(Polygon(coor))
  args = (poly)

  # convert patches -> matplotlib-objects
  p = PatchCollection(args,**kwargs)
  # add colors to patches
  if cindex is not None:
    p.set_array(cindex)
  # add patches to axis
  axis.add_collection(p)

  # rescale the axes manually
  if autoscale:
    # - get limits
    xlim = [ edges[0], edges[-1] ]
    ylim = [ 0       , np.max(P) ]
    # - set limits +/- 10% extra margin
    axis.set_xlim([xlim[0]-.1*(xlim[1]-xlim[0]),xlim[1]+.1*(xlim[1]-xlim[0])])
    axis.set_ylim([ylim[0]-.1*(ylim[1]-ylim[0]),ylim[1]+.1*(ylim[1]-ylim[0])])

  return p
def hist ( P , edges , ** kwargs ) : from matplotlib . collections import PatchCollection from matplotlib . patches import Polygon axis = kwargs . pop ( 'axis' , plt . gca ( ) ) cindex = kwargs . pop ( 'cindex' , None ) autoscale = kwargs . pop ( 'autoscale' , True ) kwargs . setdefault ( 'edgecolor' , 'k' ) if cindex is None : kwargs . setdefault ( 'facecolor' , ( 0. , 0. , 0. , 0. ) ) poly = [ ] for p , xl , xu in zip ( P , edges [ : - 1 ] , edges [ 1 : ] ) : coor = np . array ( [ [ xl , 0. ] , [ xu , 0. ] , [ xu , p ] , [ xl , p ] , ] ) poly . append ( Polygon ( coor ) ) args = ( poly ) p = PatchCollection ( args , ** kwargs ) if cindex is not None : p . set_array ( cindex ) axis . add_collection ( p ) if autoscale : xlim = [ edges [ 0 ] , edges [ - 1 ] ] ylim = [ 0 , np . max ( P ) ] axis . set_xlim ( [ xlim [ 0 ] - .1 * ( xlim [ 1 ] - xlim [ 0 ] ) , xlim [ 1 ] + .1 * ( xlim [ 1 ] - xlim [ 0 ] ) ] ) axis . set_ylim ( [ ylim [ 0 ] - .1 * ( ylim [ 1 ] - ylim [ 0 ] ) , ylim [ 1 ] + .1 * ( ylim [ 1 ] - ylim [ 0 ] ) ] ) return p
r'''
Plot histogram.