//  [python]
def encoding_fig(fake_data=False, camera_ready=False):
    sb.set_style('darkgrid')
    sb.set_context("talk", rc={"figure.figsize": (7, 7)})

    fig, axes = plt.subplots(3, 2)

    ALGOS = ['Bolt', 'PQ', 'OPQ']
    algo2offset = {'Bolt': 100, 'PQ': 50, 'OPQ': 30, 'PairQ': 25}
    lengths = [64, 128, 256, 512, 1024]

    set_palette(ncolors=len(ALGOS))

    if fake_data:
        data = np.random.randn(1, len(lengths), len(algo2offset))
        for i, algo in enumerate(ALGOS):
            data[:, :, i] += algo2offset[algo]
        data /= np.arange(len(lengths)).reshape((1, -1, 1))

        ax = axes[0, 0]
        sb.lineplot(data=data.reshape(-1, data.shape[-1]), x=np.tile(lengths, data.shape[-1]), hue=np.repeat(ALGOS, len(lengths)), ax=ax)
        ax.set_title('Data Encoding Speed', y=1.02)

        data /= 2
        ax = axes[1, 0]
        sb.lineplot(data=data.reshape(-1, data.shape[-1]), x=np.tile(lengths, data.shape[-1]), hue=np.repeat(ALGOS, len(lengths)), ax=ax)

        data /= 2
        ax = axes[2, 0]
        sb.lineplot(data=data.reshape(-1, data.shape[-1]), x=np.tile(lengths, data.shape[-1]), hue=np.repeat(ALGOS, len(lengths)), ax=ax)

        data *= 8
        data += np.random.randn(*data.shape) * 5

        ax = axes[0, 1]
        sb.lineplot(data=data.reshape(-1, data.shape[-1]), x=np.tile(lengths, data.shape[-1]), hue=np.repeat(ALGOS, len(lengths)), ax=ax)
        ax.set_title('Query Encoding Speed', y=1.03, fontsize=16)

        data /= 2
        ax = axes[1, 1]
        sb.lineplot(data=data.reshape(-1, data.shape[-1]), x=np.tile(lengths, data.shape[-1]), hue=np.repeat(ALGOS, len(lengths)), ax=ax)

        data /= 2
        ax = axes[2, 1]
        sb.lineplot(data=data.reshape(-1, data.shape[-1]), x=np.tile(lengths, data.shape[-1]), hue=np.repeat(ALGOS, len(lengths)), ax=ax)

    else:
        NBYTES_LIST = [8, 16, 32]

        df = results.encode_results()
        df_x = df[df['task'] == 'encode_x']
        df_q = df[df['task'] == 'encode_q']
        dfs = [df_x, df_q]

        ax_cols = [axes[:, 0], axes[:, 1]]

        for df, ax_col in zip(dfs, ax_cols):
            for b, nbytes in enumerate(NBYTES_LIST):
                ax = ax_col[b]
                plot_df = df.loc[df['nbytes'] == nbytes]
                plot_df = plot_df.loc[plot_df['algo'].isin(ALGOS)]
                sb.lineplot(x='D', y='y', hue='algo', units='trial', data=plot_df, ax=ax, ci=95, n_boot=500)

    ax = axes.ravel()[-1]
    leg_lines, leg_labels = ax.get_legend_handles_labels()

    plt.figlegend(leg_lines, leg_labels, loc='lower center',
                  ncol=len(ALGOS), labelspacing=0)

    for ax in axes.ravel():
        ax.set_yscale("log")
        ax.legend_.remove()
        ax.set_ylim(5e3, 2e7)

    if camera_ready:
        axes[0, 0].set_title('Data Encoding Speed', x=.49, y=1.03, fontsize=18)
        axes[0, 1].set_title('Query Encoding Speed', x=.5, y=1.03, fontsize=18)
    else:
        axes[0, 0].set_title('Data Encoding Speed', y=1.03, fontsize=16)
        axes[0, 1].set_title('Query Encoding Speed', y=1.03, fontsize=16)

    for ax in axes[:-1, :].ravel():
        plt.setp(ax.get_xticklabels(), visible=False)
        ax.set_xlabel('', labelpad=-10)
    for ax in axes[-1, :].ravel():
        ax.set_xlabel('Vector Length', labelpad=7)
    for ax in axes[:, 0]:
        if camera_ready:
            ax.set_ylabel('Vectors Encoded / s', fontsize=13)
        else:
            ax.set_ylabel('Vectors Encoded / s')

    fmt_str = "{}B Encodings"
    for i, ax in enumerate(axes[:, 1].ravel()):
        ax.yaxis.set_label_position('right')
        ax.set_ylabel(fmt_str.format((2 ** i) * 8), labelpad=10, fontsize=15)

    plt.tight_layout()
    plt.subplots_adjust(bottom=.15)
    if camera_ready:
        save_fig_png('encoding_speed')
    else:
        save_fig('encoding_speed')