0

What I want is to generate different plots using one dictionary of lists (each key one list). I accumulate the values and at the moment to plot each list, they are going all to the same plot and the last plot looks like as in the figure.

Can you tell me some ideas about how to solve it?

    for k, v in dict_btw_longmers.items():
            print(k)
            out_fig = k + "cumulative.pdf"
            length = len(v)
            cu_list = [sum(v[0:x:1]) for x in range(0, length+1)]
            plt.plot(cu_list)[1:]
            plt.ylabel("Cumulative distances")
            plt.xlabel("Contig " + k)
            plt.savefig(out_fig)
            plt.close(out_fig)

enter image description here

F.Lira
  • 663
  • 2
  • 6
  • 19

1 Answers1

1

Consider adding plt.figure() before plotting. The code is as follows:

for k, v in dict_btw_longmers.items():
      print(k)
      out_fig = k + "cumulative.pdf"
      length = len(v)
      cu_list = [sum(v[0:x:1]) for x in range(0, length+1)]
      plt.figure()
      plt.plot(cu_list)[1:]
      plt.ylabel("Cumulative distances")
      plt.xlabel("Contig " + k)
      plt.savefig(out_fig)
      plt.close(out_fig)
sotmot
  • 1,256
  • 2
  • 9
  • 21