image_output_1.png
from warnings import filterwarnings

import matplotlib.lines as lines

import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sns

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.lines as lines
import matplotlib.gridspec as gridspec
import seaborn as sns
from warnings import filterwarnings
filterwarnings('ignore')
plt.rcParams['font.family'] = 'monospace'

df = pd.read_csv('../input/predict-test-scores-of-students/test_scores.csv')

cmap0 = ['#68595b', '#7098af', '#6f636c', '#907c7b']
cmap1 = ['#484146', '#8da0b3', '#796d72', '#9fa9ba']
cmap2 = ['#545457', '#a79698', '#5284a2', '#bbbcc4']
bg_color = '#fbfbfb'
txt_color = '#5c5c5c'

# check for missing values
fig, ax = plt.subplots(tight_layout=True, figsize=(12,6))

fig.patch.set_facecolor(bg_color)
ax.set_facecolor(bg_color)

mv = df.isna()
ax = sns.heatmap(data=mv, cmap=sns.color_palette(cmap0), cbar=False, ax=ax, )

ax.set_ylabel('')
ax.set_yticks([])
ax.set_xticklabels(labels=mv.columns,rotation=45)
ax.tick_params(length=0)

fig.text(
    s=':Missing Values',
    x=0, y=1.1,
    fontsize=17, fontweight='bold',
    color=txt_color,
    va='top', ha='left'
)

fig.text(
    s='''
    we can't see any ...
    ''',
    x=0, y=1.075,
    fontsize=11, fontstyle='italic',
    color=txt_color,
    va='top', ha='left'
)

plt.show()

def despine_ax(ax, spines=['top', 'left', 'right', 'bottom']):
    for spine in spines:
        ax.spines[spine].set_visible(False)
def get_line(x=[0, 0], y=[0, 0], alpha=0.5, lw=1):
    return lines.Line2D(xdata=x, ydata=y, lw=lw, alpha=alpha, color='#aeaeae', transform=fig.transFigure, figure=fig)

fig, (ax0, ax1) = plt.subplots(2, 1, tight_layout=True, sharex=True, figsize=(12, 6))
fig.patch.set_facecolor(bg_color)
mean = df['posttest'].mean()
median = df['posttest'].median()
ax0.boxplot(data=df, x='posttest', vert=False, patch_artist=True, boxprops=dict(facecolor=cmap0[1], lw=0, alpha=0.75), whiskerprops=dict(color='gray', lw=1, ls='--'), capprops=dict(color='gray', lw=1, ls='--'), medianprops=dict(color='#fff', lw=0), flierprops=dict(markerfacecolor=cmap0[0], alpha=0.75), zorder=0)
ax1 = sns.kdeplot(data=df, x='posttest', shade=True, color=cmap0[0], edgecolor='#000', lw=1, zorder=0, alpha=0.8, ax=ax1)
ax0.axvline(x=mean, ymin=0.4, ymax=0.6, color=bg_color, ls=':', zorder=1, label='mean')
ax1.axvline(x=mean, ymin=0, ymax=0.9, color=bg_color, ls=':', zorder=1)
ax0.axvline(x=median, ymin=0.4, ymax=0.6, color=bg_color, ls='--', zorder=1)
ax1.axvline(x=median, ymin=0, ymax=0.9, color=bg_color, ls='--', zorder=1)
ax0.axis('off')
ax0.set_facecolor(bg_color)
ax1.set_ylabel('')
ax1.set_xlabel('')
ax1.set_yticks([])
ax1.tick_params(length=0)
ax1.set_facecolor(bg_color)
despine_ax(ax1, ['top', 'left', 'right'])
fig.text(s=':Posttest - Distribution', x=0, y=1.05, fontsize=17, fontweight='bold', color=txt_color, va='top', ha='left')
fig.text(s='\n    in the plot below we can see signs\n    of a binominal distribution, with \n    one peak at around 57-62 and the other \n    at approx. 72-79 points.\n    ', x=0, y=1.02, fontsize=11, fontstyle='italic', color=txt_color, va='top', ha='left')
fig.text(s=f'Mean: {np.round(mean, 1)}\nMedian: {np.round(median, 1)}', x=0.56, y=0.925, fontsize=9, fontstyle='italic', color=txt_color, va='top', ha='left')
l1 = get_line(x=[0.55, 0.55], y=[0.85, 0.95])
fig.lines.extend([l1])
plt.show()