homework.py
def viz_subgraph_author(author_id: int, max_hop_dist: int, reduced: bool = False):
    '''
    Visualize the subgraph induced by nodes that have hop distance at most
    equal to max_hop_dist with author_id
    Args:
        author_id: The integer id of an author
        max_hop_dist: the maximum hop distance to create the subgraph
        reduced: If reduced equals true it will use the reduced data
            to create the graph, otherwise it will use the full data
    '''
    graph = Graph(reduced)
    subgraph, node_list = graph.get_subgraph_author(author_id, max_hop_dist)
    author_component = nx.node_connected_component(graph.graph, author_id)
    per = round((len(subgraph.nodes())/len(author_component))*100, 2)
    print("Percentage of component = {}".format(str(per)))
    pos = nx.fruchterman_reingold_layout(subgraph)
    legend_handles = []
    plt.figure(figsize=(16, 12))
    cmap = plt.cm.get_cmap('hsv', len(node_list)+1)
    for index, value in enumerate(node_list):
        color = cmap(index)
        if index == 0:
            label = "Root"
        else:
            label = 'Distance {}'.format(str(index))
        patch = mpatches.Patch(color=color, label=label)
        legend_handles.append(patch)
        nx.draw_networkx(subgraph, pos=pos, nodelist=value, node_color=color,
                         with_labels=False, node_size=100)
    plt.legend(handles=legend_handles)
    plt.show()

    Visualize the subgraph induced by nodes that have hop distance at most
    equal to max_hop_dist with author_id
    Args:
        author_id: The integer id of an author
        max_hop_dist: the maximum hop distance to create the subgraph
        reduced: If reduced equals true it will use the reduced data
            to create the graph, otherwise it will use the full data
    
Visualize the subgraph induced by nodes that have hop distance at most
equal to max_hop_dist with author_id
Visualize the subgraph induced by nodes that have hop distance at most equal to max_hop_dist with author_id
def viz_subgraph_author(author_id: int, max_hop_dist: int, reduced: bool = False):
    graph = Graph(reduced)
    subgraph, node_list = graph.get_subgraph_author(author_id, max_hop_dist)
    author_component = nx.node_connected_component(graph.graph, author_id)
    per = round((len(subgraph.nodes())/len(author_component))*100, 2)
    print("Percentage of component = {}".format(str(per)))
    pos = nx.fruchterman_reingold_layout(subgraph)
    legend_handles = []
    plt.figure(figsize=(16, 12))
    cmap = plt.cm.get_cmap('hsv', len(node_list)+1)
    for index, value in enumerate(node_list):
        color = cmap(index)
        if index == 0:
            label = "Root"
        else:
            label = 'Distance {}'.format(str(index))
        patch = mpatches.Patch(color=color, label=label)
        legend_handles.append(patch)
        nx.draw_networkx(subgraph, pos=pos, nodelist=value, node_color=color,
                         with_labels=False, node_size=100)
    plt.legend(handles=legend_handles)
    plt.show()
def viz_subgraph_author ( author_id : int , max_hop_dist : int , reduced : bool = False ) : graph = Graph ( reduced ) subgraph , node_list = graph . get_subgraph_author ( author_id , max_hop_dist ) author_component = nx . node_connected_component ( graph . graph , author_id ) per = round ( ( len ( subgraph . nodes ( ) ) / len ( author_component ) ) * 100 , 2 ) print ( "Percentage of component = {}" . format ( str ( per ) ) ) pos = nx . fruchterman_reingold_layout ( subgraph ) legend_handles = [ ] plt . figure ( figsize = ( 16 , 12 ) ) cmap = plt . cm . get_cmap ( 'hsv' , len ( node_list ) + 1 ) for index , value in enumerate ( node_list ) : color = cmap ( index ) if index == 0 : label = "Root" else : label = 'Distance {}' . format ( str ( index ) ) patch = mpatches . Patch ( color = color , label = label ) legend_handles . append ( patch ) nx . draw_networkx ( subgraph , pos = pos , nodelist = value , node_color = color , with_labels = False , node_size = 100 ) plt . legend ( handles = legend_handles ) plt . show ( )
Visualize the subgraph induced by nodes that have hop distance at most
equal to max_hop_dist with author_id
Visualize the subgraph induced by nodes that have hop distance at most equal to max_hop_dist with author_id
'''
    Visualize the subgraph induced by nodes that have hop distance at most
    equal to max_hop_dist with author_id
    Args:
        author_id: The integer id of an author
        max_hop_dist: the maximum hop distance to create the subgraph
        reduced: If reduced equals true it will use the reduced data
            to create the graph, otherwise it will use the full data
    '''
author_id
int
The integer id of an author
The integer id of an author
max_hop_dist
int
the maximum hop distance to create the subgraph
the maximum hop distance to create the subgraph
reduced
bool
If reduced equals true it will use the reduced data
to create the graph, otherwise it will use the full data
If reduced equals true it will use the reduced data to create the graph otherwise it will use the full data