Created
December 15, 2020 15:28
-
-
Save BexTuychiev/69058e443315ba6bbc829fde91696dda to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find median | |
median_score = marks['math score'].median() | |
# Extract its prob | |
median_prob = math_pmf[median_score] | |
# Find 25th percentile | |
percentile_25th = marks['math score'].describe()['25%'] | |
# Extract its prob | |
percentile_prob = math_pmf[percentile_25th] | |
# Recreate the plot with annotations | |
fig, ax = plt.subplots(figsize=(12,6)) | |
# Plot the PMF | |
math_pmf.plot() | |
# Labelling | |
ax.set(xlabel='Math Score', | |
ylabel='Frequency', | |
title='The Probabilty of Each Score Occuring Among Students') | |
# Annotate the median score | |
ax.annotate(text=f'Median Score: {int(median_score)}', | |
xy=(median_score, median_prob), | |
xycoords='data', | |
fontsize=15, | |
xytext=(-350, 50), | |
textcoords='offset points', | |
arrowprops={'color': 'red'}) | |
# Annotate the 25th percentile | |
ax.annotate(text=f'25th percentile: {int(percentile_25th)}', | |
xy=(percentile_25th, percentile_prob), | |
xycoords='data', | |
fontsize=15, | |
xytext=(-300, -75), | |
textcoords='offset points', | |
arrowprops={'color': 'red'}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment