Skip to content

Commit 6e7b929

Browse files
authored
Merge pull request #73 from snowch/claude/binomial-distribution-calculator-QJG1z
Fix Bernoulli CDF to show initial jump from 0
2 parents 064ebc6 + 13a3338 commit 6e7b929

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

chapter_07.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,17 @@ The PMF shows two bars: P(X=0) = 0.7 for a negative test and P(X=1) = 0.3 for a
154154
:tags: [remove-input, remove-output]
155155
156156
# Plotting the CDF
157+
k_values_viz = [0, 1]
157158
cdf_values_viz = bernoulli_viz.cdf(k_values_viz)
158159
159160
plt.figure(figsize=(8, 4))
160-
plt.step(k_values_viz, cdf_values_viz, where='post', color='darkgreen', linewidth=2)
161+
# Add points to show the full step function including the start at 0
162+
plt.step([-0.5] + k_values_viz, [0] + list(cdf_values_viz), where='post', color='darkgreen', linewidth=2)
161163
plt.title(f"Bernoulli CDF (p={p_viz})")
162164
plt.xlabel("Outcome")
163165
plt.ylabel("Cumulative Probability P(X <= k)")
164166
plt.ylim(0, 1.1)
167+
plt.xlim(-0.5, 1.5)
165168
plt.xticks([0, 1])
166169
plt.grid(True, which='both', linestyle='--', linewidth=0.5, alpha=0.6)
167170
plt.savefig('ch07_bernoulli_cdf_generic.svg', format='svg', bbox_inches='tight')
@@ -256,11 +259,13 @@ The PMF shows the probability of each outcome. With p = 0.1, "Negative" has prob
256259
cdf_values = bernoulli_rv.cdf(k_values)
257260
258261
plt.figure(figsize=(8, 4))
259-
plt.step(k_values, cdf_values, where='post', color='darkgreen', linewidth=2)
262+
# Add points to show the full step function including the start at 0
263+
plt.step([-0.5] + k_values, [0] + list(cdf_values), where='post', color='darkgreen', linewidth=2)
260264
plt.title(f"Bernoulli CDF (p={p_positive})")
261265
plt.xlabel("Outcome")
262266
plt.ylabel("Cumulative Probability P(X <= k)")
263267
plt.ylim(0, 1.1)
268+
plt.xlim(-0.5, 1.5)
264269
plt.xticks([0, 1])
265270
plt.grid(True, which='both', linestyle='--', linewidth=0.5, alpha=0.6)
266271
plt.savefig('ch07_bernoulli_cdf.svg', format='svg', bbox_inches='tight')

0 commit comments

Comments
 (0)