def compareimputed(df1, df2, bins=50):
    """
    Compare the distributions of two DataFrames giving visualisations of:
     - individual and combined distributions
     - distribution of non-common values
     - distribution of non-common values vs. each side

    Useful for visualising effects of data imputation.

    Plot distribution as area (fill_between) + mean, median vertical bars.

    :param df1: `pandas.DataFrame`
    :param df2: `pandas.DataFrame`
    :param bins: `int` number of bins for histogram
    :return: Figure
    """

    fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(30, 10))

    xr = np.nanmin( [np.nanmin(df1), np.nanmin(df2)] ), np.nanmax( [np.nanmax(df1), np.nanmax(df2)] )

    ax1.set_title('Distributions of A and B')
    _areadist(ax1, df2.values, xr, c='r', bins=bins)
    _areadist(ax1, df1.values, xr, c='k', bins=bins, alpha=0.3)
    ax1.set_xlabel('Value')
    ax1.set_ylabel('Count')

    ax2.set_title('Distributions of A and values unique to B')
    # Calculate what is different isolate those values
    _areadist(ax2, df2.values[ df2.values != df1.values ], xr, c='r', bins=bins)
    _areadist(ax2, df1.values, xr, c='k', bins=bins, alpha=0.3)
    ax2.set_xlabel('Value')
    ax2.set_ylabel('Count')

    # Calculate (at the lowest column index level) the difference between
    # distribution of unique values, vs those in common
    # Get indices of difference
    dfc= df1.copy()
    dfc[:] = (df2.values != df1.values).astype(int)
    for i in dfc.columns.values:
        dfc[i[:-1]] = np.max(dfc[i[:-1]].values, axis=1)

    ax3.set_title('Distributions of associated values of A and substituted values in B')
    _areadist(ax3, df2.values[ df2.values != df1.values ], xr, c='r')
    _areadist(ax3, df1.values[ dfc.values == 1 ], xr, c='k', alpha=0.3)
    ax3.set_xlabel('Value')
    ax3.set_ylabel('Count')

    return fig
Compare the distributions of two DataFrames giving visualisations of:
     - individual and combined distributions
     - distribution of non-common values
     - distribution of non-common values vs. each side

    Useful for visualising effects of data imputation.

    Plot distribution as area (fill_between) + mean, median vertical bars.

    :param df1: `pandas.DataFrame`
    :param df2: `pandas.DataFrame`
    :param bins: `int` number of bins for histogram
    :return: Figure