def generate_graph()

in ADBench/plot_graphs.py [0:0]


def generate_graph(idx, data, static_out_dir, plotly_out_dir):
    '''Generates the graph from the given data.
    
    Args:
        idx: index of the figure.
        data (dictionary): plot data and information of the figure.
            figure_info:
                build: the type of the tool build.
                objective: the name of the objective, the graph is plotted.
                function_type: type of the current graph (e.g. "Jacobian",
                    "Objective" etc.)
                test_size: test size or empty string if the test can not have
                    a size.
            values:
                tool: name of the tool.
                time: array of time values.
                variable_count: array of variable count, respective to "time".
                violations: array of bool, determining whether the calculation
                    was correct or not for each test, respecive to "time".
        static_out_dir: output directory for the static graphs.
        plotly_out_dir: output directory for the plotly graphs.
    '''

    # Create figure
    figure = pyplot.figure(idx, figsize=figure_size, dpi=fig_dpi)

    handles, labels = [], []
    non_timeout_violation_x, non_timeout_violation_y = [], []
    additional = []

    # Plot results
    for (item, style, disp_name) in values_and_styles(data["values"]):
        (label, handle) = label_and_handle(item["tool"], item["variable_count"], item["time"], style, disp_name)
        (together, additionals) = together_and_additionals(item["variable_count"], item["time"], item["violations"])

        labels.append(label)
        handles += handle

        # adding coordinates of additional markers
        additional.append(([n_val for (n_val, _) in additionals],
                           [t_val for (_, t_val) in additionals],
                           style[0]))

        non_timeout_violation_x += [n_val for (n_val, t_val, _, _, violation)
                        in together if violation and t_val != float("inf")]
        non_timeout_violation_y += [t_val for (_, t_val, _, _, violation)
                        in together if violation and t_val != float("inf")]


    # if there was calculating violation add violation markers
    #
    # We must create the plot only if there was a violation because
    # plotly will add the violation marker to its legend even if
    # non_timeout_violation_x/y are empty.
    if len(non_timeout_violation_x) > 0:
        handles += pyplot.plot(
            non_timeout_violation_x,
            non_timeout_violation_y,
            marker="v",
            mec="k",
            mfc="r",
            ms=8,
            linestyle="None",
            label=VIOLATION_LABEL
        )

        labels.append(VIOLATION_LABEL)

    figure_info = data["figure_info"]
    (graph_name, graph_save_location) = graph_data(
        figure_info["build"],
        figure_info["objective"],
        figure_info["test_size"],
        figure_info["function_type"]
    )

    # Setup graph attributes
    xlabel = "No. independent variables"
    if "hand" == figure_info["objective"] or "hand" in figure_info["test_size"]:
        xlabel = "No. correspondences"
        
    pyplot.title(graph_name)
    pyplot.xlabel(xlabel)
    pyplot.ylabel(f"Running time (s) for [{figure_info['function_type'].capitalize()}]")
    pyplot.xscale("log")
    pyplot.yscale("log")

    draw_vertical_lines(data["values"])

    # Export to plotly (if selected)
    if do_plotly:
        plotly_fig = plotly.tools.mpl_to_plotly(copy.copy(figure))
        plotly_fig["layout"]["showlegend"] = True

        plotly_save_location_view = os.path.join(plotly_out_dir_rel, f"{graph_save_location}.html")
        plotly_save_location = os.path.join(plotly_out_dir, f"{graph_save_location}.html")

        print(f"    Saving plotly: {plotly_save_location_view}")
        utils._mkdir_if_none(plotly_save_location)
        plotly.offline.plot(plotly_fig, filename=plotly_save_location, auto_open=False)

    # Add legend (after plotly to avoid error)
    pyplot.legend(handles, labels, loc=4, bbox_to_anchor=(1, 0))

    # draw additional markers
    # Note: we do this later than plotly converting because plotly doesn't
    #       need additional markers
    for x, y, color in additional:
        pyplot.plot(
            x,
            y,
            linestyle="None",
            marker="_",
            ms=17,
            mew=2,
            color=color,
            zorder=0
        )

    # Save graph (if selected)
    if do_save:
        static_save_location_view = os.path.join(
            static_out_dir_rel,
            f"{graph_save_location}.png"
        )

        static_save_location = os.path.join(static_out_dir, f"{graph_save_location}.png")

        print(f"    Saving static: {static_save_location_view}")
        utils._mkdir_if_none(static_save_location)
        pyplot.savefig(static_save_location, dpi=save_dpi)

    if not do_show:
        pyplot.close(figure)