Skip to content

Commit ec0c2ea

Browse files
committed
fix plot off-by-one problem
The last data point of the plot was missing, because it was plotted beyond the xlim(). And drawstyle="steps-post" only draws a short vertical line for the last point; add a final point to fix this. And center the bars on the x-axis on integer samples.
1 parent 86bc243 commit ec0c2ea

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Chapter2_MorePyMC/separation_plot.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,17 @@ def separation_plot( p, y, **kwargs ):
3636
ax = fig.add_subplot(M, 1, i+1)
3737
ix = np.argsort( p[:,i] )
3838
#plot the different bars
39-
bars = ax.bar( np.arange(n), np.ones(n), width=1.,
39+
bars = ax.bar( np.arange(n), np.ones(n), width=1.,
40+
align = 'center',
4041
color = colors_bmh[ y[ix].astype(int) ],
4142
edgecolor = 'none')
42-
ax.plot( np.arange(n), p[ix,i], "k",
43-
linewidth = 1.,drawstyle="steps-post" )
43+
ax.plot( np.arange(n+1)-0.5, np.append(p[ix,i], p[ix,i][-1]), "k",
44+
linewidth = 1.,drawstyle="steps-post" )
4445
#create expected value bar.
4546
ax.vlines( [(1-p[ix,i]).sum()], [0], [1] )
4647
#ax.grid(False)
4748
#ax.axis('off')
48-
plt.xlim( 0, n-1)
49+
plt.xlim( -0.5, n-1+0.5)
4950

5051
plt.tight_layout()
5152

0 commit comments

Comments
 (0)