Skip to content

Commit ceef736

Browse files
authored
Merge pull request #85 from snowch/claude/fix-bernoulli-rendering-mjFhe
Increase diagram font sizes and fix arrow overlaps in Binomial diagram
2 parents 1e0ae26 + 2ccf59e commit ceef736

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

chapter_07.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -435,14 +435,14 @@ import matplotlib.pyplot as plt
435435
import matplotlib.patches as mpatches
436436
from matplotlib.patches import FancyBboxPatch, FancyArrowPatch
437437
438-
fig, ax = plt.subplots(figsize=(12, 7))
438+
fig, ax = plt.subplots(figsize=(14, 8))
439439
ax.set_xlim(0, 10)
440440
ax.set_ylim(0, 10)
441441
ax.axis('off')
442442
443443
# Title
444444
ax.text(5, 9.5, r'Binomial Formula Breakdown: $n=3, k=2, p=0.6$',
445-
ha='center', va='top', fontsize=24, weight='bold')
445+
ha='center', va='top', fontsize=28, weight='bold')
446446
447447
# Draw the three sequences
448448
sequences = [
@@ -464,47 +464,47 @@ for seq_text, x, y in sequences:
464464
465465
# Sequence text
466466
ax.text(x, y, seq_text, ha='center', va='center',
467-
fontsize=22, weight='bold', family='monospace')
467+
fontsize=26, weight='bold', family='monospace')
468468
469469
# Probability calculation below
470470
ax.text(x, y-0.8, f'{p}×{p}×{1-p:.1f}', ha='center', va='top',
471-
fontsize=20, style='italic')
471+
fontsize=24, style='italic')
472472
ax.text(x, y-1.2, f'= {prob_each:.3f}', ha='center', va='top',
473-
fontsize=20, weight='bold')
473+
fontsize=24, weight='bold')
474474
475475
# Count annotation
476476
ax.text(5, 5.5, r'$\binom{3}{2} = 3$ sequences',
477-
ha='center', va='center', fontsize=20, weight='bold',
477+
ha='center', va='center', fontsize=24, weight='bold',
478478
bbox=dict(boxstyle='round', facecolor='lightyellow', edgecolor='orange', linewidth=2))
479479
480480
# Formula breakdown
481-
ax.text(5, 4.2, 'Formula:', ha='center', va='center', fontsize=20, weight='bold')
481+
ax.text(5, 4.2, 'Formula:', ha='center', va='center', fontsize=24, weight='bold')
482482
ax.text(5, 3.6, r'$P(X=2) = \binom{3}{2} \cdot p^2 \cdot (1-p)^1$',
483-
ha='center', va='center', fontsize=20)
483+
ha='center', va='center', fontsize=24)
484484
ax.text(5, 2.9, r'$= 3 \times 0.36 \times 0.4$',
485-
ha='center', va='center', fontsize=20)
485+
ha='center', va='center', fontsize=24)
486486
ax.text(5, 2.3, r'$= 0.432$',
487-
ha='center', va='center', fontsize=22, weight='bold',
487+
ha='center', va='center', fontsize=26, weight='bold',
488488
bbox=dict(boxstyle='round', facecolor='lightgreen', edgecolor='green', linewidth=2))
489489
490-
# Annotations with arrows - repositioned to avoid all overlaps
491-
ax.annotate('Count sequences', xy=(4.0, 5.5), xytext=(0.5, 4.8),
492-
arrowprops=dict(arrowstyle='->', color='orange', lw=2),
493-
fontsize=18, color='orange', weight='bold')
490+
# Annotations with arrows - repositioned to completely avoid overlaps
491+
ax.annotate('Count sequences', xy=(3.8, 5.5), xytext=(0.3, 5.0),
492+
arrowprops=dict(arrowstyle='->', color='orange', lw=2.5),
493+
fontsize=20, color='orange', weight='bold')
494494
495-
ax.annotate('Each sequence\nhas same\nprobability', xy=(8.1, 7), xytext=(8.5, 8.5),
496-
arrowprops=dict(arrowstyle='->', color='steelblue', lw=2),
497-
fontsize=18, color='steelblue', weight='bold', ha='left')
495+
ax.annotate('Each sequence\nhas same\nprobability', xy=(7.5, 7.5), xytext=(7.5, 9.0),
496+
arrowprops=dict(arrowstyle='->', color='steelblue', lw=2.5),
497+
fontsize=20, color='steelblue', weight='bold', ha='center')
498498
499-
ax.annotate('Multiply!', xy=(6.0, 2.5), xytext=(7.8, 1.8),
500-
arrowprops=dict(arrowstyle='->', color='green', lw=2),
501-
fontsize=18, color='green', weight='bold')
499+
ax.annotate('Multiply!', xy=(6.2, 2.3), xytext=(7.8, 1.5),
500+
arrowprops=dict(arrowstyle='->', color='green', lw=2.5),
501+
fontsize=20, color='green', weight='bold')
502502
503503
# Bottom explanation
504-
ax.text(5, 1.0, 'Why it works: Each sequence occurs with probability 0.432/3 = 0.144,',
505-
ha='center', va='center', fontsize=18, style='italic')
506-
ax.text(5, 0.5, 'and there are 3 ways to get exactly 2 successes, so total = 3 × 0.144 = 0.432',
507-
ha='center', va='center', fontsize=18, style='italic')
504+
ax.text(5, 0.8, 'Why it works: Each sequence occurs with probability 0.432/3 = 0.144,',
505+
ha='center', va='center', fontsize=20, style='italic')
506+
ax.text(5, 0.3, 'and there are 3 ways to get exactly 2 successes, so total = 3 × 0.144 = 0.432',
507+
ha='center', va='center', fontsize=20, style='italic')
508508
509509
plt.tight_layout()
510510
plt.savefig('ch07_binomial_formula_breakdown.svg', format='svg', bbox_inches='tight')

0 commit comments

Comments
 (0)