Skip to content

Commit 3e4cb82

Browse files
committed
Add average percentage line and legend to percentage of finds plot
1 parent 432bfd4 commit 3e4cb82

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,16 @@ def printPctFinds():
8080
findCounts[prisoner] = 0
8181
if found:
8282
findCounts[prisoner] += 1
83-
8483
pctFinds = {prisoner: (count / num_simulations) * 100 for prisoner, count in findCounts.items()}
84+
avgPctFinds = sum(pctFinds.values()) / len(pctFinds)
85+
8586
plt.bar(pctFinds.keys(), pctFinds.values())
87+
plt.axhline(y=avgPctFinds, color='r', linestyle='-', label=f'Overall Average: {avgPctFinds:.2f}%')
88+
plt.ylim(0, 100)
8689
plt.xlabel("Prisoner ID")
8790
plt.ylabel("Percentage of Finds (%)")
8891
plt.title("Percentage of Finds per Prisoner")
92+
plt.legend()
8993
plt.show()
9094

9195
def run():
@@ -100,7 +104,7 @@ def run():
100104
print("1. Show win percentage")
101105
print("2. Show average number of checked boxes per prisoner")
102106
print("3. Show percentage of finds per prisoner")
103-
print("4. Exit/Return to main menu")
107+
print("4. Return to main menu")
104108
choice = input("Enter your choice: ").strip()
105109
if choice == '1':
106110
plots_stats.printWinPercentage()

0 commit comments

Comments
 (0)