python pyplot在一个图中有多个图,但不知道确切的数字

时间:2015-05-07 11:18:50

标签: python matplotlib

我需要在同一个图上绘制多个图,我已经看到我必须使用此代码(每个xy是一个列表):

plot(x1,y2,'r',x2,y2,'r',x3,y3,'r'...xn,yn,'r')

此代码的问题在于,只有当我确切地知道' n'我即将绘制的函数。

EG了解eggs中的夫妻数量:

#eggs = [[[x1],[y1]],[[x2],[y2]],[[x3],[y3]]]
eggs = [[[1,2,3,4],[1,2,3,4]],[[1,2,3,4],[1,2,4,8]],[[1,2,3,4],[1,1,1,1]]]

#I know eggs has 3 couple so my plot is...
plot(eggs[0][0],eggs[0][1],'r',eggs[1][0],eggs[1][1],'r',eggs[2][0],eggs[2][1],'r')

如果我不知道在eggs中存储了多少对夫妇,我想在单个数字上自动化这些情节怎么办?

1 个答案:

答案 0 :(得分:1)

最简单的方法是首先创建您的数字,然后循环浏览数据以添加请求的地块。

eggs = [[[1,2,3,4],[1,2,3,4]],[[1,2,3,4],[1,2,4,8]],[[1,2,3,4],[1,1,1,1]]]

import matplotlib.pyplot as plt
fig,ax = plt.subplots()

for i in range(0,3):
    ax.plot(eggs[i][0],eggs[i][1])
plt.draw()

享受: - )

相关问题