[英]Matplotlib: plots two extra lines on my graph?
我有一个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)`
返回给我两个图,其中一个很好(它是第一组数据),但是另一个绘制了两条额外的线,我不知道它们来自何处。 第二个图有两条额外的线,顶部的两条是多余的。
粗略地看一下,第二个图形(最上面的两行)似乎与第一行中的相同。 我不是最好的matplotlib,但我确实看到
plt.figure
没有指定需要重新制作一个。 您应该使用plt.figure(1)
和plt.figure(2)
来指定它们是不同的图形
plt.clf()
可以创建新图,而无需追加到现有图上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.