Matplotlib:在我的图表上绘制两条额外的线条?

时间:2015-07-21 16:50:33

标签: python loops matplotlib

我有一个csv文件,它有两组数据。基本上:

    for row in reader:
    ###I have some other code but here's the stuff that applies to the question###

        disorder_long = sequence_analysis(looped_region.upper(), mode = 'long')
        disorder_short = sequence_analysis(looped_region.upper(), mode = 'short')

        length = len(list(disorder_short))
        #print length

        xmin = 1
        xmax_long = length
        ymin = 0
        ymax_long = max(disorder_long)
        ymax_short = max(disorder_short)

        y_limit = max([ymax_long, ymax_short])
        #print y_limit

        while True:
            try:
                newfig = str(raw_input('Name the graph to be created: '))
                break #break out of loop
            except ValueError:
                print("error")
                continue #return to start of loop

        plt.figure           

        #data
        x_series = np.array(range(1,length+1))
        # print "x series: "
        # print x_series
        # print len(x_series)
        y_series1 = np.array(disorder_long)
        y_series2 = np.array(disorder_short)
        # print y_series1, y_series2

        #plot data
        plt.plot(x_series, y_series1, label=uniprot_id+' long')
        plt.plot(x_series, y_series2, label=uniprot_id+' short')

        #add limits to the x and y axis
        plt.xlim(xmin, xmax_long)
        plt.ylim(ymin, 1)

        #create legend
        plt.legend(loc="upper left")

        #save figure to png
        plt.savefig(newfig)`

给我两张图,其中一张非常精细(它是第一组数据),但另一张有两条额外的线,我不知道它们来自哪里。第二个图表有两行,前两行是无关的。enter image description here enter image description here

2 个答案:

答案 0 :(得分:0)

只是粗略地看一眼,第二个图表,前两行,看起来与第一个中的线条相同。我不是matplotlib最好的,但我确实看到了这行

plt.figure

未指定需要制作新的。您应该使用plt.figure(1)plt.figure(2)来指定它们是不同的数字

答案 1 :(得分:0)

plt.clf()

用于创建新图而不附加到现有图。