def plot_heterozygosity(heterozygosity, options):
    """Plots the heterozygosity rate distribution.

    :param heterozygosity: the heterozygosity data.
    :param options: the options.

    :type heterozygosity: numpy.array
    :type options: argparse.Namespace

    Plots a histogram or a boxplot of the heterozygosity distribution.

    """
    # importing important stuff
    import matplotlib as mpl
    if options.format != "X11" and mpl.get_backend() != "agg":
        mpl.use("Agg")
    import matplotlib.pyplot as plt
    if options.format != "X11":
        plt.ioff()

    # Creating the figure and ax
    figsize = (13.5, 8)
    if options.boxplot:
        figsize = (13.5, 4)
    fig, ax = plt.subplots(1, 1, figsize=figsize)

    # Setting subplot properties
    ax.xaxis.set_ticks_position("bottom")
    ax.yaxis.set_ticks_position("left")
    ax.spines["top"].set_visible(False)
    ax.spines["right"].set_visible(False)
    ax.spines["bottom"].set_position(("outward", 9))
    ax.spines["left"].set_position(("outward", 9))

    # The title and labels
    ax.set_title(("Heterozygosity rate distribution "
                  "({:,} samples)".format(len(heterozygosity))), weight="bold")
    ax.set_xlabel("Heterozygosity rate")

    # Plotting the histogram
    if options.boxplot:
        # Specific settings for the boxplot
        ax.yaxis.set_ticks_position("none")
        ax.spines["left"].set_visible(False)
        ax.set_yticklabels([])
        fig.subplots_adjust(bottom=0.18)

        # The boxplot
        ax.boxplot(heterozygosity, notch=True, vert=False)
    else:
        # Specific settings for the histogram
        ax.set_ylabel("Proportion")

        # The histogram
        ax.hist(
            heterozygosity,
            bins=options.bins,
            color="#0099CC",
            histtype="stepfilled",
            weights=np.zeros_like(heterozygosity) + 1.0 / len(heterozygosity),
        )

        # Plotting the mean, the median and the variance
        the_mean = np.mean(heterozygosity)
        the_median = np.median(heterozygosity)
        the_variance = np.power(np.std(heterozygosity), 2)
        mean_line = ax.axvline(the_mean, color="#CC0000", ls="--", lw=2,
                               clip_on=False)
        median_line = ax.axvline(the_median, color="#FF8800", ls="--", lw=2,
                                 clip_on=False)
        variance_line = ax.axvline(the_variance, color="#FFFFFF", ls="--",
                                   lw=0, clip_on=False)
        ax.legend(
            [mean_line, median_line, variance_line],
            [
                "Mean ({:.4})".format(the_mean),
                "Median ({:.4})".format(the_median),
                "Variance ({:.4})".format(the_variance),
            ],
            loc="best",
            prop={"size": 11},
        )

        # The ylim
        if options.ymax is not None:
            ax.set_ylim(0.0, options.ymax)

    # The xlim
    if options.xlim is not None:
        ax.set_xlim(options.xlim)

    # Saving the figure
    if options.format == "X11":
        plt.show()
    else:
        file_name = "{}.{}".format(options.out, options.format)
        if options.boxplot:
            file_name = "{}_boxplot.{}".format(options.out, options.format)
        plt.savefig(file_name, dpi=300)