//  [python]
def plot_importances(models_splits_lags, lag=0, keys=None, cutoff=6,
                     plot=True):
    #%%
    # keys = ['autocorr', '10_1_sst']
    if type(lag) is int:
        df_all = _get_importances(models_splits_lags, lag=lag)

        if plot:
            import matplotlib as mpl
            mpl.rcParams.update(mpl.rcParamsDefault)
            # fig, ax = plt.subplots(constrained_layout=True)
            lag_d = df_all.index[0][0]
            df_r = df_all.loc[lag_d]
            if keys is not None:
                # take show up to cutoff most important features
                df_r = df_r[keys]

            g = sns.boxplot(data=df_r, palette=sns.color_palette(["#e74c3c"]),
                            orient='h')

            ax = g
            # ax.set_facecolor('white')
            ax.grid(which='both')
            ax.set_title(f"{df_all.columns.name}")
            # ax.barh(np.arange(df_r.size), df_r.squeeze().values, tick_label=df_r.columns)
            # ax.text(0.98, 0.03, f'lead time: {lag_d} days',
            #         fontsize=12,
            #         bbox=dict(boxstyle='round', facecolor='wheat',
            #                   edgecolor='black', alpha=0.5),
            #     horizontalalignment='right',
            #     verticalalignment='top',
            #     transform=ax.transAxes)
            lim = df_r.apply(abs).max().max()
            lim = lim + .1*lim
            ax.set_xlim((-lim,lim))
            fig = plt.gcf()
    elif type(lag) is list or type(lag) is np.ndarray:

        dfs = []
        for i, l in enumerate(lag):
            df_ = _get_importances(models_splits_lags, lag=l)
            dfs.append(df_)
        all_vars = []
        all_vars.append([list(df.columns.values) for df in dfs])
        all_vars = np.unique(flatten(flatten(all_vars)))
        df_all = pd.DataFrame(columns=all_vars)
        for i, l in enumerate(lag):
            df_n = dfs[i]
            df_all = df_all.append(df_n, sort=False)
        sort_index = df_all.mean(0).sort_values(ascending=False).index
        df_all = df_all.reindex(sort_index, axis='columns')
        df_all = df_all.reindex(pd.MultiIndex.from_tuples(df_all.index))
        if plot:

            if keys is None:
                # take show up to cutoff most important features
                df_pl = df_all.reindex(df_all.mean(0).abs().sort_values(
                                                                ascending=False).index, axis=1)
                df_pl = df_pl.iloc[:,:cutoff]

            else:
                df_pl = df_all.loc[:,[k for k in sort_index if k in keys]]
            # plot vs lags
            fig, ax = plt.subplots(constrained_layout=True)
            styles_ = [['solid'], ['dashed']]
            styles = flatten([6*s for i, s in enumerate(styles_)])[:df_pl.size]
            linewidths = np.linspace(abs(cutoff)/4, 2, abs(cutoff))[::-1]
            lags_df = df_all.index.levels[0]
            for col, style, lw, cm in zip(df_pl.columns, styles, linewidths, colors_datasets):
                splits = df_all.loc[:,col].index.levels[1]
                df_var = df_all.loc[:,col]
                print(col)
                for s in splits:
                    ax.plot(lags_df.values, df_var.loc[:,s].values,
                             linestyle=style,
                             linewidth=1,
                             color=cm, alpha=.3,
                             label=None)
                ax.plot(lags_df.values,
                        df_var.mean(axis=0, level=0).values,
                        linestyle=style,
                        linewidth=lw,
                        color=cm,
                        label=col)
                    # df_var.loc[:,s].plot(figsize=(8,5),
                    #                       linestyle=style,
                    #                       linewidth=1,
                    #                       label=label,
                    #                       ax=ax)
                ax.set_xticks(lags_df)
            ax.hlines(y=0, xmin=lags_df[0], xmax=lags_df[-1])
            ax.legend()
            ax.set_title(f'{df_.columns.name} vs. lead time')
            ax.set_xlabel('lead time [days]')
    #%%
    return df_all, fig