Python Matplotlib: displaying histograms with overlapping borders

I draw a bar graph using Matplotlib in Python using a function matplotlib.bar(). This gives me graphs that look like this:

enter image description here

I am trying to create a histogram that only displays the caps of each bar and the sides that do not directly share the space with the border of another bar, something like this: (I edited this with gimp)

enter image description here

How can I achieve this using Python? Answers using are matplotlibpreferable, as this is what I have the most experience with, but I am open to everything that works using Python.

For what it's worth, here is the corresponding code:

import numpy as np
import matplotlib.pyplot as pp

bin_edges, bin_values = np.loadtxt("datafile.dat",unpack=True)
bin_edges = np.append(bin_edges,500.0)

bin_widths = []
for j in range(len(bin_values)):
    bin_widths.append(bin_edges[j+1] - bin_edges[j])

pp.bar(bin_edges[:-1],bin_values,width=bin_widths,color="none",edgecolor='black',lw=2)


pp.savefig("name.pdf")
+4
source share
1

, - :  http://matplotlib.org/examples/pylab_examples/step_demo.html

:

import numpy as np
import matplotlib.pyplot as pp

# Simulate data
bin_edges = np.arange(100)
bin_values = np.exp(-np.arange(100)/5.0)

# Prepare figure output
pp.figure(figsize=(7,7),edgecolor='k',facecolor='w')
pp.step(bin_edges,bin_values, where='post',color='k',lw=2)
pp.tight_layout(pad=0.25)
pp.show()

bin_edges , where = 'post'; , = 'pre'. , , , () , post (pre). / , .

2 - , - :

# Simulate data
data = np.random.rand(1000)

# Prepare histogram
nBins = 100
rng = [0,1]
n,bins = np.histogram(data,nBins,rng)
x = bins[:-1] + 0.5*np.diff(bins)

# Prepare figure output
pp.figure(figsize=(7,7),edgecolor='k',facecolor='w')
pp.step(x,n,where='mid',color='k',lw=2)
pp.show()
+4

All Articles