Skip to content

Instantly share code, notes, and snippets.

@BexTuychiev
Created December 15, 2020 15:28
Show Gist options
  • Save BexTuychiev/69058e443315ba6bbc829fde91696dda to your computer and use it in GitHub Desktop.
Save BexTuychiev/69058e443315ba6bbc829fde91696dda to your computer and use it in GitHub Desktop.
# 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