Пример #1
0
def plot_discoveries_treemap(experiment_definition, repetition_id=0, experiment_statistics=None, data_filters=None, config=None, **kwargs):
    
    default_config = dict(
            random_seed = 0,
            
            squarify = dict(
                        x = 0.0,
                        y = 0.0,
                        width = 100.0,
                        height = 100.0,
                    
                    ),

            # global style config
            global_layout = dict(
                    height=700, 
                    width=700,
                    margin = dict(
                            l = 0,
                            r = 0,
                            b = 0,
                            t = 0
                            ),
                    xaxis=dict(
                        autorange=True,
                        showgrid=False,
                        zeroline=False,
                        showline=False,
                        ticks='',
                        showticklabels=False
                    ),
                    yaxis=dict(
                        autorange=True,
                        showgrid=False,
                        zeroline=False,
                        showline=False,
                        ticks='',
                        showticklabels=False
                    ),
                    title = dict(
                            text = '',
                            font = dict(
                                  color = "black",
                                  size = 22,
                                  family='Times New Roman'
                                )
                            ),
                    hovermode='closest',
                    showlegend =  True,
                ),
            
            # Shapes style config
            shapes = dict(
                    line = dict(
                            width = 2
                            ),
                    layer = "below"
                    ),
            shapes_background_colors = ['rgb(0,0,0)', 'rgb(204,121,167)', 'rgb(0,114,178)'],
            shapes_lines_colors = [ 'rgb(0,0,0)','rgb(154,71,117)', 'rgb(0,64,128)'],
            
            # Images style config
            margin_x = 1,
            margin_y = 1, 
            images = dict (
                        xref= "x",
                        yref= "y",
                        sizex= 10,
                        sizey= 10,
                        opacity = 1,
                        xanchor= "center",
                        yanchor= "middle",
                        layer = "above"
                    ),
            images_transform = True,
            images_transform_colormaps = [
                            create_colormap(np.array([[255,255,255], [119,255,255],[23,223,252],[0,190,250],[0,158,249],[0,142,249],[81,125,248],[150,109,248],[192,77,247],[232,47,247],[255,9,247],[200,0,84]])/255*8), #WBPR
                			create_colormap(np.array([[0,0,4],[0,0,8],[0,4,8],[0,8,8],[4,8,4],[8,8,0],[8,4,0],[8,0,0],[4,0,0]])), #BCYR
                			create_colormap(np.array([[0,2,0],[0,4,0],[4,6,0],[8,8,0],[8,4,4],[8,0,8],[4,0,8],[0,0,8],[0,0,4]])), #GYPB
                			create_colormap(np.array([[4,0,2],[8,0,4],[8,0,6],[8,0,8],[4,4,4],[0,8,0],[0,6,0],[0,4,0],[0,2,0]])), #PPGG
                			create_colormap(np.array([[4,4,6],[2,2,4],[2,4,2],[4,6,4],[6,6,4],[4,2,2]])), #BGYR
                			create_colormap(np.array([[4,6,4],[2,4,2],[4,4,2],[6,6,4],[6,4,6],[2,2,4]])), #GYPB
                			create_colormap(np.array([[6,6,4],[4,4,2],[4,2,4],[6,4,6],[4,6,6],[2,4,2]])), #YPCG
                			create_colormap(np.array([[8,8,8],[7,7,7],[5,5,5],[3,3,3],[0,0,0]]), is_marker_w=False), #W/B
                			create_colormap(np.array([[0,0,0],[3,3,3],[5,5,5],[7,7,7],[8,8,8]]))], #B/W
            
            # Annotations style config
            annotations = dict(
                    font = dict(
                      color = "#140054",
                      size = 18,
                      family='Times New Roman'
                    ),
                    showarrow = False,
                    opacity=1.0,
                    bgcolor='rgb(255,255,255)'
                    )
            
            
            )
    
    config = ad.config.set_default_config(kwargs, config, default_config)
    
    random.seed(config.random_seed)
    
    # experiment_ids=[exp_def['id'] for exp_def in experiment_definitions]
    # for experiment_id in experiment_ids:
    #     experiment_idx = experiment_ids.index(experiment_id)
    #     for repetition_idx in repetition_ids:
    #         experiment_statistics[experiment_id][repetition_idx] = ad.gui.jupyter.misc.load_statistics(os.path.join(experiment_definitions[experiment_idx]['directory'], 'repetition_{:06d}'.format(repetition_idx)))

    experiment_id = experiment_definition['id']
    #exp_idx = experiment_ids.index(experiment_id)
    if repetition_id is None:
        path = experiment_definition['directory']
    else:
        path = os.path.join(
            experiment_definition['directory'],
            'repetition_{:06d}'.format(int(repetition_id))
        )
    
    path = os.path.join(path, 'statistics')
    final_observation_path = os.path.join(path, 'final_observation')

    # Recover images (from png or zip)
    all_images = []
    if os.path.isdir(final_observation_path):
        dir_content = os.listdir(final_observation_path)
        for image_file_name in dir_content:
            file_path = os.path.join(path, image_file_name)
            if os.path.isfile(file_path) and '.png' in image_file_name:
                item_id = image_file_name.split('.')[0]
                item_id = int(item_id)
                file = open(file_path, "rb")
                image_PIL = Image.open(file)
                if config.images_transform:
                    image_PIL = transform_image_from_colormap(image_PIL, config.images_transform_colormaps[0])
                all_images.append(image_PIL)
    
    elif zipfile.is_zipfile(final_observation_path + '.zip'):
        zf = zipfile.ZipFile(final_observation_path + '.zip', 'r')
        dir_content = zf.namelist()
        for image_file_name in dir_content:
            item_id = image_file_name.split('.')[0]
            item_id = int(item_id)
            with zf.open(image_file_name) as file:
                image_PIL = Image.open(file)
                if config.images_transform:
                    image_PIL = transform_image_from_colormap(image_PIL, config.images_transform_colormaps[0])
                all_images.append(image_PIL)

    else:
        warnings.warn('No Images found under {!r}'.format(final_observation_path))
        
    # Recover labels
    filters_ids = list(data_filters.keys())
    database_filtered_ids = dict()
    for curr_filter_k, curr_filter_val in data_filters.items():
        # filter
        if curr_filter_val is None or not curr_filter_val:
            img_ids = range(len(all_images))
        else:
            run_ids = ad.gui.jupyter.misc.filter_single_experiment_data(experiment_statistics[experiment_id], curr_filter_val, int(repetition_id))
            img_ids = np.where(run_ids)[0]
            database_filtered_ids[curr_filter_k] = list(img_ids)  

    values = []
    for filter_id in filters_ids:
        values.append(len(database_filtered_ids[filter_id])/len(all_images)*100)
    sorted_indexes = np.argsort(-np.array(values))
    
    values = np.array(values)[sorted_indexes]
    filters_ids = np.array(filters_ids)[sorted_indexes]
    config.shapes_background_colors = np.array(config.shapes_background_colors)[sorted_indexes]
    config.shapes_lines_colors = np.array(config.shapes_lines_colors)[sorted_indexes]
    
    normed = ad.gui.jupyter.squarify.normalize_sizes(values, config.squarify.width, config.squarify.height)
    rects = ad.gui.jupyter.squarify.squarify(normed, config.squarify.x, config.squarify.y, config.squarify.width, config.squarify.height)
    
    annotations = []
    shapes = []
    images = []
    counter = 0
    
    for r in rects:
        # annotations layout
        annotation_config = ad.config.set_default_config(
                    dict(
                        x = r['x']+(r['dx']/2),
                        y = r['y']+(r['dy']/2),
                        text = "<b>{}:<br>{:.1f}%<b>".format(filters_ids[counter],values[counter]),
                        ),
                    config.annotations
                    )
        annotations.append(annotation_config)
        
        # shapes layout
        shape_config = ad.config.set_default_config(
                    dict(
                        type = 'rect', 
                        x0 = r['x'], 
                        y0 = r['y'], 
                        x1 = r['x']+r['dx'], 
                        y1 = r['y']+r['dy'],
                        fillcolor = config.shapes_background_colors[counter],
                        line = dict(color = config.shapes_lines_colors[counter])
                        ),
                    config.shapes  
                    )
        shapes.append(shape_config)
        
        # images layout
        x0 = r['x']
        y0 = r['y']
        w = r['dx']
        h = r['dy']
        
        n_cols = int((w - 2 * config.margin_x) // config.images.sizex)
        space_x = (w - 2 * config.margin_x) / n_cols
        centers_x = []
        for j in range(n_cols):
            centers_x.append(j * space_x + space_x / 2.0)
        
        n_rows = int((h - 2 * config.margin_y) // config.images.sizey)
        space_y = (h - 2 * config.margin_y) / n_rows
        centers_y = []
        for i in range(n_rows):
            centers_y.append(i * space_y + space_y / 2.0)
        
        list_of_random_items = random.sample(database_filtered_ids[filters_ids[counter]], n_rows*n_cols)
        
        for i in range(n_rows):
            for j in range(n_cols):
                image_config = ad.config.set_default_config(
                        dict(
                            source = all_images[list_of_random_items[np.ravel_multi_index((i, j), dims=(n_rows,n_cols), order='F')]],
                            x = x0 + config.margin_x + centers_x[j],
                            y = y0 + config.margin_y + centers_y[i],
                        ),
                        config.images)
                images.append(image_config)
        
        counter = counter + 1
        if counter >= len(config.shapes_background_colors):
            counter = 0
    

    # append to global layout
    global_layout = ad.config.set_default_config(
                dict(
                    annotations = annotations,
                    shapes=shapes,
                    images=images
                    ),
                config.global_layout
                )
                        
    
    figure = dict(data=[go.Scatter()],layout=global_layout)
    
    
    plotly.offline.iplot(figure)
    
    return figure
Пример #2
0
    def get_default_gui_config():
        default_config = ad.Config()

        # general box layout config
        default_config.box_layout = ad.Config()
        default_config.box_layout.flex_flow = 'column'
        default_config.box_layout.display = 'flex'
        default_config.box_layout.align_items = 'stretch'

        # Row 0: 2D visualisation type selector
        default_config.visualisation_type_selector = ad.Config()
        default_config.visualisation_type_selector.description = 'visualisation type'
        default_config.visualisation_type_selector.options = [
            'T-SNE', 'PCA', 'UMAP', '0-1', '0-2', '0-3', '0-4', '0-5', '0-6',
            '0-7'
        ]
        default_config.visualisation_type_selector.value = 'UMAP'
        default_config.visualisation_type_selector.disabled = False

        # Row 1: Canvas graph
        default_config.canvas = ad.Config()

        ## default print properties for layout
        multiplier = 2
        pixel_cm_ration = 35
        width_full = int(13.95 * pixel_cm_ration) * multiplier
        width_half = int(13.95 / 2 * pixel_cm_ration) * multiplier
        height_default = int(3.5 * pixel_cm_ration) * multiplier
        top_margin = 0 * multiplier
        left_margin = 0 * multiplier
        right_margin = 0 * multiplier
        bottom_margin = 0 * multiplier
        font_family = 'Times New Roman'
        font_size = 10 * multiplier
        default_config.canvas.layout = dict(
            font=dict(
                family=font_family,
                size=font_size,
            ),
            updatemenus=[],
            width=width_half,  # in cm
            height=height_default,  # in cm
            margin=dict(
                l=left_margin,  #left margin in pixel
                r=right_margin,  #right margin in pixel
                b=bottom_margin,  #bottom margin in pixel
                t=top_margin,  #top margin in pixel
            ),
            legend=dict(
                font=dict(
                    family=font_family,
                    size=font_size,
                ),
                xanchor='right',
                yanchor='bottom',
                y=0.,
                x=1.0,
            ),
            showlegend=False)

        ## scatter default config
        default_config.canvas_data = ad.Config()
        default_config.canvas_data.mode = 'markers'
        default_config.canvas_data.marker = dict(size=4.0, opacity=1.0)

        ## colors and symbols for markers
        default_config.marker_colorlist = dict()
        default_config.marker_colorlist['dead'] = 'rgb(0,0,0)'
        default_config.marker_colorlist['animal'] = 'rgb(230,159,0)'
        default_config.marker_colorlist['non-animal'] = 'rgb(0,158,115)'

        default_config.marker_symbollist = dict()
        default_config.marker_symbollist['dead'] = 'circle'
        default_config.marker_symbollist['animal'] = 'diamond'
        default_config.marker_symbollist['non-animal'] = 'square'

        # Row 2: Image list widget for selected points
        default_config.image_list_widget = ad.gui.jupyter.ImageListWidget.get_default_gui_config(
        )
        default_config.image_list_widget.image_items.layout.border = '1px solid gray'  # add gray countour around images displayed

        ## colormap for images (BW --> colormap)
        default_config.transform_images = True
        default_config.transform_images_colormaps = [
            create_colormap(
                np.array([[255, 255, 255], [119, 255, 255], [23, 223, 252],
                          [0, 190, 250], [0, 158, 249], [0, 142, 249],
                          [81, 125, 248], [150, 109, 248], [192, 77, 247],
                          [232, 47, 247], [255, 9, 247], [200, 0, 84]]) / 255 *
                8),  #WBPR
            create_colormap(
                np.array([[0, 0, 4], [0, 0, 8], [0, 4, 8], [0, 8,
                                                            8], [4, 8, 4],
                          [8, 8, 0], [8, 4, 0], [8, 0, 0], [4, 0, 0]])),  #BCYR
            create_colormap(
                np.array([[0, 2, 0], [0, 4, 0], [4, 6, 0], [8, 8,
                                                            0], [8, 4, 4],
                          [8, 0, 8], [4, 0, 8], [0, 0, 8], [0, 0, 4]])),  #GYPB
            create_colormap(
                np.array([[4, 0, 2], [8, 0, 4], [8, 0, 6], [8, 0,
                                                            8], [4, 4, 4],
                          [0, 8, 0], [0, 6, 0], [0, 4, 0], [0, 2, 0]])),  #PPGG
            create_colormap(
                np.array([[4, 4, 6], [2, 2, 4], [2, 4, 2], [4, 6, 4],
                          [6, 6, 4], [4, 2, 2]])),  #BGYR
            create_colormap(
                np.array([[4, 6, 4], [2, 4, 2], [4, 4, 2], [6, 6, 4],
                          [6, 4, 6], [2, 2, 4]])),  #GYPB
            create_colormap(
                np.array([[6, 6, 4], [4, 4, 2], [4, 2, 4], [6, 4, 6],
                          [4, 6, 6], [2, 4, 2]])),  #YPCG
            create_colormap(np.array([[8, 8, 8], [7, 7, 7], [5, 5, 5],
                                      [3, 3, 3], [0, 0, 0]]),
                            is_marker_w=False),  #W/B
            create_colormap(
                np.array([[0, 0, 0], [3, 3, 3], [5, 5, 5], [7, 7, 7],
                          [8, 8, 8]]))
        ]  #B/W

        return default_config
# INPUT INFO
experiment_id = 171102
dataset_id = 7
n_max_images = 300

# OUTPUT INFO
output_image_folder = './images_colored/'
if not os.path.exists(output_image_folder):
    os.makedirs(output_image_folder)
img_filename_template = output_image_folder + 'pattern_{:06d}_{}'
img_suffix = '.png'
colored = True
colormap = create_colormap(
    np.array([[255, 255, 255], [119, 255, 255], [23, 223, 252], [0, 190, 250],
              [0, 158, 249], [0, 142, 249], [81, 125, 248], [150, 109, 248],
              [192, 77, 247], [232, 47, 247], [255, 9, 247], [200, 0, 84]]) /
    255 * 8)

# LOAD MODEL
model_path = '../../experiments/experiment_{:06d}/training/models/best_weight_model.pth'.format(
    experiment_id)
#model_path = '../../prior_data/pretrained_representation/representation_000118/best_weight_model.pth'
#model_path = '../../experiments/experiment_{:06d}/repetition_{:06d}/trained_representation/saved_models/stage_{:06d}_weight_model.pth'.format(experiment_id, repetition_id, stage_id)
print("Loading the trained model ... \n")
if os.path.exists(model_path):
    saved_model = torch.load(model_path, map_location='cpu')
    model_cls = getattr(ad.representations.static.pytorchnnrepresentation,
                        saved_model['type'])
    if 'self' in saved_model['init_params']:
        del saved_model['init_params']['self']
Пример #4
0
def plot_holmes_partitioning(experiment_definition,
                             repetition_id=0,
                             experiment_statistics=None,
                             data_filters=None,
                             config=None,
                             **kwargs):
    plotly_default_colors = plotly.colors.DEFAULT_PLOTLY_COLORS
    plotly_default_colors_darker = [
        lighten_color([
            float(cc) / 255.0
            for cc in c.replace("rgb(", "").replace(")", "").split(", ")
        ], 1.4) for c in plotly.colors.DEFAULT_PLOTLY_COLORS
    ]
    plotly_default_colors_darker = [
        "rgb({},{},{})".format(int(c[0] * 255), int(c[1] * 255),
                               int(c[2] * 255))
        for c in plotly_default_colors_darker
    ]
    default_config = dict(
        random_seed=0,

        # global style config
        global_layout=dict(
            height=700,
            width=700,
            margin=dict(l=0, r=0, b=0, t=0),
            xaxis=dict(autorange=True,
                       showgrid=False,
                       zeroline=False,
                       showline=False,
                       ticks='',
                       showticklabels=False),
            yaxis=dict(autorange=True,
                       showgrid=False,
                       zeroline=False,
                       showline=False,
                       ticks='',
                       showticklabels=False),
            title=dict(text='',
                       font=dict(color="black",
                                 size=22,
                                 family='Times New Roman')),
            hovermode='closest',
            showlegend=True,
        ),

        # Shapes style config
        shapes=dict(line=dict(width=2), layer="below"),
        shapes_background_colors=plotly_default_colors,
        shapes_lines_colors=plotly_default_colors_darker,

        # Images style config
        margin_x=1,
        margin_y=1,
        images=dict(xref="x",
                    yref="y",
                    sizex=10,
                    sizey=10,
                    opacity=1,
                    xanchor="center",
                    yanchor="middle",
                    layer="above"),
        images_transform=True,
        images_transform_colormaps=[
            create_colormap(
                np.array([[255, 255, 255], [119, 255, 255], [23, 223, 252],
                          [0, 190, 250], [0, 158, 249], [0, 142, 249],
                          [81, 125, 248], [150, 109, 248], [192, 77, 247],
                          [232, 47, 247], [255, 9, 247], [200, 0, 84]]) / 255 *
                8),
            # WBPR
            create_colormap(
                np.array([[0, 0, 4], [0, 0, 8], [0, 4, 8], [0, 8,
                                                            8], [4, 8, 4],
                          [8, 8, 0], [8, 4, 0], [8, 0, 0], [4, 0, 0]])),
            # BCYR
            create_colormap(
                np.array([[0, 2, 0], [0, 4, 0], [4, 6, 0], [8, 8,
                                                            0], [8, 4, 4],
                          [8, 0, 8], [4, 0, 8], [0, 0, 8], [0, 0, 4]])),
            # GYPB
            create_colormap(
                np.array([[4, 0, 2], [8, 0, 4], [8, 0, 6], [8, 0,
                                                            8], [4, 4, 4],
                          [0, 8, 0], [0, 6, 0], [0, 4, 0], [0, 2, 0]])),
            # PPGG
            create_colormap(
                np.array([[4, 4, 6], [2, 2, 4], [2, 4, 2], [4, 6, 4],
                          [6, 6, 4], [4, 2, 2]])),  # BGYR
            create_colormap(
                np.array([[4, 6, 4], [2, 4, 2], [4, 4, 2], [6, 6, 4],
                          [6, 4, 6], [2, 2, 4]])),  # GYPB
            create_colormap(
                np.array([[6, 6, 4], [4, 4, 2], [4, 2, 4], [6, 4, 6],
                          [4, 6, 6], [2, 4, 2]])),  # YPCG
            create_colormap(np.array([[8, 8, 8], [7, 7, 7], [5, 5, 5],
                                      [3, 3, 3], [0, 0, 0]]),
                            is_marker_w=False),
            # W/B
            create_colormap(
                np.array([[0, 0, 0], [3, 3, 3], [5, 5, 5], [7, 7, 7],
                          [8, 8, 8]]))
        ],  # B/W

        # Annotations style config
        annotations=dict(font=dict(color="#140054",
                                   size=18,
                                   family='Times New Roman'),
                         showarrow=False,
                         opacity=1.0,
                         bgcolor='rgb(255,255,255)'))

    config = ad.config.set_default_config(kwargs, config, default_config)

    random.seed(config.random_seed)
    np.random.seed(config.random_seed)

    if repetition_id is None:
        path = experiment_definition['directory']
    else:
        path = os.path.join(experiment_definition['directory'],
                            'repetition_{:06d}'.format(int(repetition_id)))

    path = os.path.join(path, 'statistics')
    final_observation_path = os.path.join(path, 'final_observation')

    # Recover images (from png or zip)
    all_images = []
    if os.path.isdir(final_observation_path):
        dir_content = os.listdir(final_observation_path)
        for image_file_name in dir_content:
            file_path = os.path.join(path, image_file_name)
            if os.path.isfile(file_path) and '.png' in image_file_name:
                item_id = image_file_name.split('.')[0]
                item_id = int(item_id)
                file = open(file_path, "rb")
                image_PIL = Image.open(file)
                if config.images_transform:
                    image_PIL = transform_image_from_colormap(
                        image_PIL, config.images_transform_colormaps[0])
                all_images.append(image_PIL)

    elif zipfile.is_zipfile(final_observation_path + '.zip'):
        zf = zipfile.ZipFile(final_observation_path + '.zip', 'r')
        dir_content = zf.namelist()
        for image_file_name in dir_content:
            item_id = image_file_name.split('.')[0]
            item_id = int(item_id)
            with zf.open(image_file_name) as file:
                image_PIL = Image.open(file)
                if config.images_transform:
                    image_PIL = transform_image_from_colormap(
                        image_PIL, config.images_transform_colormaps[0])
                all_images.append(image_PIL)

    else:
        warnings.warn(
            'No Images found under {!r}'.format(final_observation_path))

    # loads pathes taken in HOLMES
    ids_per_node_path = os.path.join(path, 'ids_per_node')
    ids_per_node = dict(np.load(ids_per_node_path + '.npz'))
    for gs_path, gs_val in ids_per_node.items():
        if len(gs_val.shape) == 0:
            ids_per_node[gs_path] = gs_val.dtype.type(gs_val)

    pathes = []
    max_depth = 0
    for k in ids_per_node.keys():
        cur_node_path = k[3:]
        pathes.append(cur_node_path)
        if (len(cur_node_path) - 1) > max_depth:
            max_depth = len(cur_node_path) - 1

    # load representations per node in HOLMES
    representations_per_node_path = os.path.join(path, 'representations')
    representations_per_node = dict(
        np.load(representations_per_node_path + '.npz'))
    for gs_path, gs_val in representations_per_node.items():
        representations_per_node[gs_path] = gs_val.dtype.type(gs_val)

    tot_width = config.global_layout.width
    row_height = config.global_layout.height

    figures = []
    counter = 0
    n_total = len(ids_per_node["gs_0"])

    for depth in range(max_depth + 1):
        cur_depth_pathes = []
        for path in pathes:
            if (len(path) - 1) == depth:
                cur_depth_pathes.append(path)
        cur_depth_pathes.sort()

        values = []
        for path in cur_depth_pathes:
            n_cur_node = len(ids_per_node["gs_{}".format(path)])
            values.append(n_cur_node / n_total * tot_width)

        for col_idx in range(len(values)):
            cur_path = cur_depth_pathes[col_idx]
            value = values[col_idx]

            x0 = 0
            y0 = 0
            # v1:
            w = value
            # v2:
            # w = tot_width
            h = row_height

            # images layout
            min_n_cols = 2
            space_between_images = 0.1
            n_cols = int((w - 2 * config.margin_x) // config.images.sizex)
            n_cols = max(n_cols, min_n_cols)
            space_x = config.images.sizex + space_between_images
            centers_x = []
            for j in range(n_cols):
                centers_x.append(j * space_x + space_x / 2.0)

            n_rows = int((h - 2 * config.margin_y) // config.images.sizey)
            space_y = config.images.sizey + space_between_images
            centers_y = []
            for i in range(n_rows):
                centers_y.append(i * space_y + space_y / 2.0)

            cur_path_x_ids = ids_per_node["gs_{}".format(cur_path)]
            indices_diverse = get_diversity_representants(
                representations_per_node["gs_{}".format(cur_path)],
                n_candidates=750,
                n_images=n_rows * n_cols)
            indices_diverse = cur_path_x_ids[indices_diverse]
            #list_of_random_items = np.random.choice(cur_path_x_ids, size=n_rows * n_cols, replace=True)

            images = []
            for i in range(n_rows):
                for j in range(n_cols):
                    image_config = ad.config.set_default_config(
                        dict(
                            source=all_images[indices_diverse[
                                np.ravel_multi_index((i, j),
                                                     dims=(n_rows, n_cols),
                                                     order='F')]],
                            x=x0 + config.margin_x + centers_x[j],
                            y=y0 + config.margin_y + centers_y[i],
                        ), config.images)
                    images.append(image_config)

            shape_w = n_cols * config.images.sizex + (
                n_cols - 1) * space_between_images + 2 * config.margin_x
            shape_h = n_rows * config.images.sizey + (
                n_rows - 1) * space_between_images + 2 * config.margin_y
            annotation_w = 170
            annotation_h = 20
            final_w = max(shape_w, annotation_w)
            final_h = shape_h + annotation_h + 0.2

            # annotations layout
            annotation_config = ad.config.set_default_config(
                dict(x=x0 + (final_w / 2),
                     y=y0 + shape_h + 0.2 + annotation_h,
                     width=annotation_w,
                     height=annotation_h,
                     text="<b>GS {}: {:.1f}%<b>".format(
                         cur_path, w / tot_width * 100),
                     font=dict(color=config.shapes_lines_colors[counter], )),
                config.annotations)

            # shapes layout
            shape_config = ad.config.set_default_config(
                dict(type='rect',
                     x0=x0,
                     y0=y0,
                     x1=x0 + shape_w,
                     y1=y0 + shape_h,
                     fillcolor=config.shapes_background_colors[counter],
                     line=dict(color=config.shapes_lines_colors[counter])),
                config.shapes)

            # figure
            cur_fig_layout = ad.config.set_default_config(
                dict(width=final_w,
                     height=final_h,
                     margin=dict(autoexpand=True),
                     annotations=[annotation_config],
                     shapes=[shape_config],
                     images=images), config.global_layout)

            figure = dict(data=[go.Scatter()], layout=cur_fig_layout)
            plotly.offline.iplot(figure)
            figures.append(figure)

            counter = counter + 1
            if counter >= len(config.shapes_background_colors):
                counter = 0

    return figures