Plot data without interpolation from former x value
<p>I am doing some particle tracking at the moment. Therefore I want to plot the distribution and the cumulative function of the passing particles. </p>

<p>When I plot the distribution, my plot always starts one time step to early.
Is there a way to just plot the event as a kind of peak, without any interpolation on the x axis? </p>

<p>Short example data is attached...</p>

<pre><code>time = [ 0.,1.,2.,3.,4.,5.,6.,7.,8.,9.]
counts = [0,0,1,0,2,0,0,0,1,0]
cum = [ 0.,0.,0.25,0.25,0.75,0.75,0.75,0.75,1.,1.]

ax1 = plt.subplot2grid((1,2), (0, 0), colspan=1)
ax1.plot(time, counts, "-", label="Density")
ax1.set_xlim([0,time[-1]])
ax1.legend(loc = "upper left", frameon = False)
ax1.grid()

ax2 = plt.subplot2grid((1,2), (0, 1), rowspan=1)
ax2.step(time, cum, "r",where='post', label="Sum")
ax2.legend(loc = "upper left", frameon = False)
ax2.set_ylim([-0.05,1.05])
ax2.set_xlim([0,time[-1]])
ax2.grid()

plt.suptitle("Particle distribution \n")
plt.show()
</code></pre>

<p><a href="http://i.stack.imgur.com/ZK7VY.png" rel="nofollow"><img src="http://i.stack.imgur.com/ZK7VY.png" alt="enter image description here"></a></p>

<p>Thanks for any help!</p>

<p>There is no interpolation; with <code>plot(.., '-')</code>, matplotlib simply <em>"connects the dots"</em> (data coordinates that you provide). Either don't draw the line and use markers, e.g.:</p>

<pre><code>ax1.plot(time, counts, "o", label="Density")
</code></pre>

<p>Or use e.g. <code>bar()</code> to draw "peaks":</p>

<pre><code>ax1.bar(time, counts, width=0.001)
</code></pre>

<p><em>edit</em>: Drawing <code>bar()</code>'s isn't ideal, as you are not drawing individual lines, but very small bars. It turns out that <code>matplotlib</code> actually has a function to draw the peaks: <code>stem()</code>:</p>

<pre><code>ax1.stem(time, counts, label="Density")
</code></pre>

<p>Which results in:</p>

<p><a href="http://i.stack.imgur.com/rBW9k.png" rel="nofollow"><img src="http://i.stack.imgur.com/rBW9k.png" alt="enter image description here"></a></p>

python matplotlib plot