擅长:python、mysql、java
<p>我很难理解你的答案,因为使用了lambda,我发现有点难以理解。我让我的朋友解释一下,我大脑的秘诀是知道我们正在做的是将ORM中的三列转换成一个数组(Python中的LIST)。我认为这对初学者(像我一样)来说是一个更简单的答案。在</p>
<pre><code>class Animals(models.Model):
cats = models.PositiveSmallIntegerField
dogs = models.PositiveSmallIntegerField
created = created = models.DateTimeField(auto_now_add=True)
import matplotlib.pyplot as plt
datatograph = Animals.objects.all()
for a in datatograph
catslist = catslist + [a.cats]
dogslist = dogslist + [a.cats]
dates = dates + [a.created]
plt.plot(dates, catslist)
plt.plot(dates, dogslist)
plt.show() # Pops up a dialog with the graph, se plt.savefig(filename.ext) to save in .ext format like .png
plt.close()
</code></pre>