title: Saving nxpd generated graph plots
body: <p>The documentation on nxpd is very clear on how to print the graph internal to ipython, but how do you save the graph as a .png or .pdf? The method below reads in a dataframe (mc) containing the probability of state changes and an output path to save the plotted graph. It is unclear to me how to pass the nxpd draw to pyplot or use an internal save method.</p>
  
  <p>NXPD documentation is limited: <a href="https://github.com/chebee7i/nxpd" rel="nofollow noreferrer">https://github.com/chebee7i/nxpd</a></p>
  
  <pre><code>def DrawMarkov(mc, outputPath):
      import matplotlib.pyplot as plt
      from pandas import DataFrame
      import networkx as nx
      from nxpd import draw
      ## Draw as an internal to ipython
      # draw(G, show='ipynb')
      ## OR
      # from nxpd import nxpdParams
      # nxpdParams['show'] = 'ipynb' 
  
      def Add_Nodes(G, name):
          for node in range(0,len(mc) ):
      #         print(node); print(type(node)); print(color_map[node])
              G.add_node(node, style='filled', fillcolor=color_map[node], )
  
      def Add_Edges(G,mc):
          for start in range(0,len(mc[0])):
              # print(start,'\n')
              for finish in range(0,len(mc) ):
                  # print(mc[start][finish])
                  if mc[start][finish]!=0:
                      G.add_edge(start, finish, weight=mc[start][finish], label=str(mc[start][finish]) )
  
      color_map = {0: 'lightblue', 
                   1:'palegreen', 
                   2:'lightcoral'}
  
      ## Plot DiGraph
      G = nx.DiGraph()  
      Add_Nodes(G,mc)  
      Add_Edges(G,mc)  
      mapping={0:'State1', 1:'State2', 2:'State3'}
      G = nx.relabel_nodes(G,mapping)  
  
      ## Output  
      draw(G, layout='dot')  # , show='ipynb'  # unclear how to pass graph to plt
      # plt.savefig(os.path.join(outputPath, 'Graph.png') )  
  </code></pre>