def best_ratio_fit(total_size: tuple[float, float], single_size: tuple[float, float], n: int) -> tuple[int, int]:
    """
    Find best ratio of rows and cols to show n axes of ax_size on Figure with total_size.
    :param total_size: total size available for n axes
    :param single_size: size of one axes
    :param n: number of axes to plot on total size
    :return: best ratio (rows and cols)
    """
    optimal_ratio = total_size[0] / total_size[1]

    single_plot_ratio = single_size[0] / single_size[1]
    optimal_ratio /= single_plot_ratio

    possible_ratios = []
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            if i * j >= n:
                possible_ratios.append((i, j))
                break

    # sort ratios by best fit to optimal ratio:
    possible_ratios[:] = sorted(possible_ratios, key=lambda ratio: abs(ratio[0] / ratio[1] - optimal_ratio))
    return possible_ratios[0]