1
私は2つのリストのプロットを作成しようとしています。時間はtimeitで測定され、もう1つはループを通過しました。空のプロットしかないので、何かが間違っていると分かりました。誰かが多分、間違いがどこにあるのか教えてくれますか? 関数は本当に重要ではありませんが、私はコンテキストを提供するためにすべてを投稿します。ここで コードは次のとおりです。Pythonのリストをプロットする
import random
import timeit
import matplotlib.pyplot as plt
def generateSequences(n):
RandomSequences = []
dna = ["A","G","C","T"]
for i in range(int(n)):
randseq=''
for i in range(50):
randseq+=random.choice(dna)
RandomSequences.append(randseq)
return RandomSequences
def generatePrefixes(p, RandomSequences):
First20Chars = [x[:20] for x in RandomSequences]
RandomChoices = []
for i in range(p):
randomPrefix = random.choice(First20Chars)
RandomChoices.append(randomPrefix)
return First20Chars, RandomChoices
def searchReadsInList(RandomSequences, RandomChoices):
start_time = timeit.default_timer()
Matches_RS_RC = []
for i in RandomChoices:
for j in RandomSequences:
if i in j:
Matches_RS_RC.append(j)
elapsed_sRL = timeit.default_timer() - start_time
return Matches_RS_RC, elapsed_sRL
if __name__ == "__main__":
count = 10
while count < 1000:
RandomSequences = generateSequences(count)
First20Chars, RandomChoices = generatePrefixes(5, RandomSequences)
Matches_RS_RC, elapsed_sRL = searchReadsInList(RandomSequences, RandomChoices)
ListCounts = []
ListCounts.append(count)
ListTime = []
ListTime.append(elapsed_sRL)
count = count + 10
plt.plot(ListTime, count)
plt.xlabel('Time')
plt.ylabel('# of Reads')
plt.savefig("TimePlot.pdf")
plt.show()
あなたのリストには、唯一の2値保存:[990]と[0.0012807846069335938]。 plotのとき 'plt.plot(ListTime、ListCounts)'を使います。 – Serenity