def save_graph(graph_str, dest_file, fmt=None, image_ratio=None):
g = pydot.graph_from_dot_data(graph_str)<EOL>if fmt is None:<EOL><INDENT>fmt = os.path.splitext(dest_file)[<NUM_LIT:1>].lower().strip('<STR_LIT:.>') or "<STR_LIT>"<EOL><DEDENT>if hasattr(g, "<STR_LIT>" + fmt):<EOL><INDENT>write_fn = getattr(g, "<STR_LIT>" + fmt)<EOL><DEDENT>else:<EOL><INDENT>raise Exception("<STR_LIT>" % fmt)<EOL><DEDENT>if image_ratio:<EOL><INDENT>g.set_ratio(str(image_ratio))<EOL><DEDENT>write_fn(dest_file)<EOL>return fmt<EOL>
Render a graph to an image file.

    Args:
        graph_str (str): Dot-language graph string.
        dest_file (str): Filepath to save the graph to.
        fmt (str): Format, eg "png", "jpg".
        image_ratio (float): Image ratio.

    Returns:
        String representing format that was written, such as 'png'.