Skip to content

Commit 13a3338

Browse files
committed
Fix Bernoulli CDF to show initial jump from 0
Issue: CDF plot started at 0.7 without showing that it should be 0 before x=0 Fix: - Added point at x=-0.5 with CDF=0 to show initial value - Now properly shows: 0 → jump to 0.7 at x=0 → jump to 1.0 at x=1 - Applied to both Bernoulli CDF visualizations - Added xlim to show the full step function The plot now correctly mirrors the description: starts at 0, jumps to 0.7 at x=0 (including outcome 0), then jumps to 1.0 at x=1 (including both outcomes).
1 parent 619c897 commit 13a3338

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)