import matplotlib.pyplot as plt
import numpy as np


def uloha1(matice_dat):
    fig, axs = plt.subplots(1, 2, sharey=True, tight_layout=True)
    axs[0].hist(matice_dat[:, 0],
                color='cyan',
                edgecolor='black',
                density=True,
                bins=range(1, 6))
    axs[1].hist(matice_dat[:, 1],
                color='magenta',
                edgecolor='black',
                density=True,
                label='Praktický',
                bins=range(1, 6))
    axs[0].set_title("Teoretický")
    axs[1].set_title("Praktický")
    axs[0].set_ylabel('Počet studentů')
    plt.show()


def uloha1a(matice_dat):
    plt.hist([matice_dat[:, 0], matice_dat[:, 1]],
             bins=range(1, 6),
             density=True,
             edgecolor='black',
             label=['Teoretický', 'Praktický'],
             stacked=True)
    plt.legend()
    plt.xticks(ticks=np.linspace(1.5, 5.5, 5), labels="12345")
    plt.title('Obtížnost DU')
    plt.show()


def uloha2(matice_dat):
    labels, sizes = np.unique(matice_dat[:, 2], return_counts=True)
    explode = np.zeros(len(labels))
    explode[np.argmax(sizes)] = 0.1
    fig1, ax1 = plt.subplots()
    ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
            shadow=True, startangle=90)
    ax1.axis('equal')
    plt.title("Pieplot vtipu o pieplot")
    plt.legend()
    plt.show()


def uloha3(matice_dat):
    plt.subplot(121)
    plt.boxplot(matice_dat[:, 3], showmeans=True,
                patch_artist=True,
                boxprops=dict(facecolor='royalblue'))
    plt.title('Výška')
    plt.ylabel('cm')
    plt.subplot(122)
    plt.title('Výška bez outlieru')
    plt.boxplot(matice_dat[:, 3][matice_dat[:, 3] != np.min(matice_dat[:, 3])],
                showmeans=True,
                patch_artist=True,
                boxprops=dict(facecolor='royalblue'))
    plt.show()


def uloha4(matice_dat):
    birth = dict(zip(*np.unique(matice_dat[:, 5], return_counts=True)))
    fav = dict(zip(*np.unique(matice_dat[:, 4], return_counts=True)))
    fav_counts = np.zeros(12)
    birth_counts = np.zeros(12)
    for i in range(0, 13):
        fav_counts[i] = fav[i] if i in fav else 0
        birth_counts[i] = birth[i] if i in birth else 0
    fig, ax = plt.subplots()
    ax.bar(range(1, 13), birth_counts, label="Narození")
    ax.bar(range(1, 13), fav_counts, bottom=birth_counts, label="Oblíbený")
    plt.legend()
    plt.ylabel("Počet hlasů")
    plt.title("Měsíce")
    plt.show()
