Plot Z1 and Z2 in function of IBS2* ratio.

    :param x: the x axis of the plot (``IBS2 ratio``).
    :param y: the y axis of the plot (either ``z1`` or ``z2``).
    :param code: the code of the relatedness of each sample pair.
    :param ylabel: the label of the y axis (either ``z1`` or ``z2``).
    :param fileName: the name of the output file.
    :param options: the options.

    :type x: numpy.array of floats
    :type y: numpy.array of floats
    :type code: numpy.array
    :type ylabel: str
    :type fileName: str
    :type options: argparse.Namespace

    There are four different relation codes (represented by 4 different color
    in the plots:

    ==== =============================================== ===========
    Code                    Relation                        Color
    ==== =============================================== ===========
    1    Full-sbis                                       ``#CC0000``
    2    Half-sibs or Grand-parent-Child or Uncle-Nephew ``#0099CC``
    3    Parent-Child                                    ``#FF8800``
    4    Twins or Duplicated samples                     ``#9933CC``
    ==== =============================================== ===========

    Sample pairs with unknown relation are plotted using ``#669900`` as color.

def plot_related_data(x, y, code, ylabel, fileName, options):
    """Plot Z1 and Z2 in function of IBS2* ratio.

    :param x: the x axis of the plot (``IBS2 ratio``).
    :param y: the y axis of the plot (either ``z1`` or ``z2``).
    :param code: the code of the relatedness of each sample pair.
    :param ylabel: the label of the y axis (either ``z1`` or ``z2``).
    :param fileName: the name of the output file.
    :param options: the options.

    :type x: numpy.array of floats
    :type y: numpy.array of floats
    :type code: numpy.array
    :type ylabel: str
    :type fileName: str
    :type options: argparse.Namespace

    There are four different relation codes (represented by 4 different color
    in the plots:

    ==== =============================================== ===========
    Code                    Relation                        Color
    ==== =============================================== ===========
    1    Full-sbis                                       ``#CC0000``
    2    Half-sibs or Grand-parent-Child or Uncle-Nephew ``#0099CC``
    3    Parent-Child                                    ``#FF8800``
    4    Twins or Duplicated samples                     ``#9933CC``
    ==== =============================================== ===========

    Sample pairs with unknown relation are plotted using ``#669900`` as color.

    """
    import matplotlib as mpl
    if mpl.get_backend() != "agg":
        mpl.use("Agg")
    import matplotlib.pyplot as plt
    plt.ioff()

    fig = plt.figure()
    ax = fig.add_subplot(111)

    # Setting the title, the X and Y label
    ax.set_title((r"%d pairs with $IBS2^\ast_{ratio} >$ "
                  r"%f" % (len(code), options.ibs2_ratio)))
    ax.set_xlabel(r"$IBS2^\ast_{ratio}$")
    ax.set_ylabel(ylabel)

    # Plotting the data (there are 5 error codes)
    c5, = ax.plot(x[code == "5"], y[code == "5"], "o", ms=3, mec="#669900",
                  mfc="#669900")
    c1, = ax.plot(x[code == "1"], y[code == "1"], "o", ms=3, mec="#CC0000",
                  mfc="#CC0000")
    c2, = ax.plot(x[code == "2"], y[code == "2"], "o", ms=3, mec="#0099CC",
                  mfc="#0099CC")
    c3, = ax.plot(x[code == "3"], y[code == "3"], "o", ms=3, mec="#FF8800",
                  mfc="#FF8800")
    c4, = ax.plot(x[code == "4"], y[code == "4"], "o", ms=3, mec="#9933CC",
                  mfc="#9933CC")

    # The legend
    prop = mpl.font_manager.FontProperties(size=8)
    leg = ax.legend([c1, c2, c3, c4, c5],
                    ["Full sibs (n={})".format(np.sum(code == "1")),
                     ("Half sibs, grand-parent-child or uncle-nephew "
                      "(n={})".format(np.sum(code == "2"))),
                     "Parent-child (n={})".format(np.sum(code == "3")),
                     ("Twins or duplicated samples "
                      "(n={})".format(np.sum(code == "4"))),
                     "Unknown (n={})".format(np.sum(code == "5"))],
                    loc="best", numpoints=1, fancybox=True, prop=prop)
    leg.get_frame().set_alpha(0.5)

    # Setting the limits
    ax.set_xlim((options.ibs2_ratio - 0.01, 1.01))
    ax.set_ylim((-0.01, 1.01))

    # Modifying the spines
    ax.xaxis.set_ticks_position("bottom")
    ax.yaxis.set_ticks_position("left")
    ax.spines["top"].set_visible(False)
    ax.spines["right"].set_visible(False)

    # Saving the figure
    plt.savefig(fileName)