import pandas as pd
import numpy as np

import matplotlib.pyplot as plt
import seaborn as sns


def show_images(x: np.ndarray, y: np.ndarray = None, nrows: int = 1, ncols: int = 1, figsize: tuple = None):

    fig, axs = plt.subplots(nrows=nrows, ncols=ncols, figsize=figsize)
    axs = axs.flatten()

    for i in range(len(axs)):

        axs[i].imshow(x[i].squeeze())

        if y is not None:

            axs[i].set_title(f'{y[i]}')

        axs[i].grid(None)
        axs[i].axis('off')

    return fig, axs


def clusters_count(counts, title=None):

    benchmark = pd.DataFrame({'No. Clusters': counts})
    sns.set_theme(style='darkgrid')

    ax = sns.countplot(x='No. Clusters', data=benchmark)

    plt.xlabel('No. Clusters')
    plt.ylabel('No. Examples')

    if title is not None:

        plt.title(title)

    plt.tight_layout()

    return ax
