This is an archival dump of old wiki content --- see scipy.org for current material.
Please see http://scipy-cookbook.readthedocs.org/

Attachment 'histNofill.py'

Download

 1 import matplotlib
 2 import numarray as na
 3 
 4 def hist(binsIn, dataIn, normed=False):
 5  """
 6  Make a histogram that can be plotted with plot() so that
 7  the histogram just has the outline rather than bars as it
 8  usually does.
 9 
 10  Example Usage:
 11  binsIn = numarray.arange(0, 1, 0.1)
 12  angle = pylab.rand(50)
 13 
 14  (bins, data) = histOutline(binsIn, angle)
 15  plot(bins, data, 'k-', linewidth=2)
 16 
 17  """
 18  (en, eb) = matplotlib.mlab.hist(dataIn, bins=binsIn, normed=normed)
 19 
 20  stepSize = binsIn[1] - binsIn[0]
 21 
 22  bins = na.zeros(len(eb)*2 + 2, type=na.Float)
 23  data = na.zeros(len(eb)*2 + 2, type=na.Float) 
 24  for bb in range(len(binsIn)):
 25  bins[2*bb + 1] = binsIn[bb]
 26  bins[2*bb + 2] = binsIn[bb] + stepSize
 27  data[2*bb + 1] = en[bb]
 28  data[2*bb + 2] = en[bb]
 29 
 30  bins[0] = bins[1]
 31  bins[-1] = bins[-2]
 32  data[0] = 0
 33  data[-1] = 0
 34  
 35  return (bins, data)
 36 
 37 def convertForPlot(binsIn, histIn):
 38  """
 39  Take the output from a normal histogram and turn it into
 40  a histogram that can be plotted (square tops, etc.).
 41 
 42  binsIn - The bins output by matplotlib.mlab.hist()
 43  histIn - The histogram output by matplotlib.mlab.hist()
 44  """
 45  stepSize = binsIn[1] - binsIn[0]
 46 
 47  bins = na.zeros(len(binsIn)*2 + 2, type=na.Float)
 48  data = na.zeros(len(binsIn)*2 + 2, type=na.Float) 
 49  for bb in range(len(binsIn)):
 50  bins[2*bb + 1] = binsIn[bb]
 51  bins[2*bb + 2] = binsIn[bb] + stepSize
 52  data[2*bb + 1] = histIn[bb]
 53  data[2*bb + 2] = histIn[bb]
 54 
 55  bins[0] = bins[1]
 56  bins[-1] = bins[-2]
 57  data[0] = 0
 58  data[-1] = 0
 59  
 60  return (bins, data)

New Attachment

File to upload
Rename to
Overwrite existing attachment of same name

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2007年12月06日 20:35:33, 1.6 KB) [[attachment:histNofill.py]]
  • [get | view] (2009年07月01日 22:45:26, 1.4 KB) [[attachment:histOutline.py]]
  • [get | view] (2007年12月06日 20:35:06, 12.0 KB) [[attachment:hist_outline.png]]

AltStyle によって変換されたページ (->オリジナル) /