【发布时间】:2017-02-03 01:00:57
【问题描述】:
我有一个嵌套列表:
nested=[[35,36,37],[34,35,36,37,38],[22,23,23,24]]
我需要创建一个图表,其中每个子列表都是同一图中的趋势线。例如,在 (x,y) 格式中:趋势线 1 有点 (1,35),(2,36),(3, 37)。趋势线 2 有点 (1,34),(2,35)...(5,38) 和第三条趋势线相同,我不知道该怎么做。我是python初学者,非常感谢您的建议!
我尝试过的编辑:
import matplotlib.pyplot as plt
for list in nested:
x=range(1, len(list)+1)
y=list
plt.plot(x,y)
plt.show()
这可行,但提供了许多情节。我需要把它全部放在一个情节中
【问题讨论】:
-
你试过
[plt.plot(x) for x in nested]; plt.show()吗? -
如果你想让x轴的值从1开始,那么你可以试试
[plt.plot(*m) for m in [list(zip(*[(ix+1,y) for ix,y in enumerate(x)])) for x in nested]]; plt.show()。
标签: python matplotlib plot graphing trendline