def add_pos_node_attribute(graph, origin='bottomleft'):
    """
    Add node attribute 'pos' with X and Y coordinates to networkx graph so that we can the positions of each node to
    graphviz for plotting.  The origin for the X,Y plane is provided as some tools for grabbing coordinates from images
    use the topleft or the bottomleft.

    Args:
        graph (networkx graph): graph to "pos" node attribute to.  `graph` already should X, Y node attributes.
        origin (str): How to treat origin for X, Y.  One of: 'bottomleft', 'topleft', 'topright', 'bottomright'

    Returns:
        networkx graph with the node attributes added to graph
    """

    ori = {
        'bottomleft': {'X': 1, 'Y': 1},
        'topleft': {'X': 1, 'Y': -1},
        'topright': {'X': -1, 'Y': -1},
        'bottomright': {'X': -1, 'Y': 1}
    }[origin]

    for node_id in graph.nodes():
        try:
            # dividing by arbitrary number to make pos appear as required type: double
            graph.node[node_id]['pos'] = "{},{}!".format(ori['X']*graph.node[node_id]['X']/100,
                                                         ori['Y']*graph.node[node_id]['Y']/100)
        except KeyError as e:
            print(e)
            print('No X, Y coordinates found for node: {}'.format(node_id))
    return graph