# histogram question

I need to generate a set of histograms, but would like to plot only the "skyline"
of the histogram, and leave out the vertical lines where adjencent bars touch.
I have looked at the docs, but nothing jumped out at me as the right keyword
for this. Is this possible? and if so, how?

Cheers
Tommy

I believe that you can do the same thing using the regular plot command with linestyles='steps' (but I think you need to fiddle with the x values so that the steps are aligned properly. But it would be nice if hist could do this too.

Perry

···

On Sep 24, 2007, at 2:32 PM, Tommy Grav wrote:

I need to generate a set of histograms, but would like to plot only
the "skyline"
of the histogram, and leave out the vertical lines where adjencent
bars touch.
I have looked at the docs, but nothing jumped out at me as the right
keyword
for this. Is this possible? and if so, how?

I wrote the following code to do this for me...it is not entirely general (in the sense that it doesn't accept all kwargs beyond bins and hatch) and also allows me to do my own normalization.... But you should be able to use it pretty easily.

def open_hist(arr,bins=10,norm=None,hatch=None):
import matplotlib as mpl
import pylab

# Get all of the scaling right by allowing pylab to do it.
d = pylab.hist(arr,bins)
ax = pylab.gca()
for i in d[2]:
ax.patches.remove(i)
width = d[1][1]-d[1][0]

if norm is None:
norm = 1.
else:
norm = float(norm)
# Determine the vertices of the no-line histogram.
verts = []
for i in range(len(d[0])):
if i==0:
x = d[1][i]
y = 0.
verts.append((x,y))
if i==len(d[0])-1:
x = d[1][i]
y = d[0][i]/norm
verts.append((x,y))
x = d[1][i]+width
verts.append((x,y))
y = 0.
verts.append((x,y))
else:
x = d[1][i]
y = d[0][i]/norm
verts.append((x,y))
x = d[1][i]+width
verts.append((x,y))

# Let pylab do its thing....
p = pylab.Polygon(verts,transform=ax.transData,hatch=hatch)
p.set_fill(0)

···

On Mon, 24 Sep 2007, Tommy Grav wrote:

I need to generate a set of histograms, but would like to plot only
the "skyline"
of the histogram, and leave out the vertical lines where adjencent
bars touch.
I have looked at the docs, but nothing jumped out at me as the right
keyword
for this. Is this possible? and if so, how?

Cheers
Tommy

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Perry Greenfield wrote:

···

On Sep 24, 2007, at 2:32 PM, Tommy Grav wrote:

I need to generate a set of histograms, but would like to plot only
the "skyline"
of the histogram, and leave out the vertical lines where adjencent
bars touch.
I have looked at the docs, but nothing jumped out at me as the right
keyword
for this. Is this possible? and if so, how?

I believe that you can do the same thing using the regular plot command with linestyles='steps' (but I think you need to fiddle with the x values so that the steps are aligned properly. But it would be nice if hist could do this too.

There is also an axes step() method in svn.

Eric