【发布时间】:2018-10-11 19:26:12
【问题描述】:
我首先编写了一个函数,它接受 18 个参数并将它们变成 6 个不同的列表。代码如下:
def list_maker(val1,val2,val3,val4,val5,val6,val7,val8,val9,por1,por2,por3,hth1,hth2,hth3,sat1,sat2,sat3):
#Make the voip list
list1 = [val1,val2,val3]
list2 = [val4,val5,val6]
list3 = [val7,val8,val9]
#Make the variable list
list_por = [por1,por2,por3]
list_hth = [hth1,hth2,hth3]
list_sat = [sat1,sat2,sat3]
return list1,list2,list3,list_por,list_hth,list_sat
那部分工作得很好(一旦它真正工作,我会让它看起来更好)。 现在,我的想法是使用该函数作为下面另一个函数的输入来创建绘图:
def graph_maker(listx1,listx2,listx3,list1,list2,list3):
#plot the saturation graph
por_plot = plt.plot(listx1,list1)
por_plot.ylabel('VOIP')
por_plot.xlabel('Porosity')
por_plot.show()
#plot the heigth graph
hth_plot = plt.plot(listx2,list2)
hth_plot.ylabel('VOIP')
hth_plot.xlabel('Height')
hth_plot.show()
#plot the saturation graph
sat_plot = plt.plot(listx3,list3)
sat_plot.ylabel('VOIP')
sat_plot.xlabel('Saturation')
sat_plot.show()
所以我用以下两行运行代码:
list_maker(voip1,voip2,voip3,voip4,voip5,voip6,voip7,voip8,voip9,0.3,0.2,0.15,100,150,200,0.8,0.6,0.5)
graph_maker(list_maker)
我得到的错误是:
graph_maker() 缺少 5 个必需的位置参数:'listx2', “listx3”、“list1”、“list2”和“list3”
据我了解,似乎 list_maker() 实际上只返回一个列表,显然 graph_maker 函数需要 6 个参数。有什么想法吗?
感谢您的帮助!
【问题讨论】:
-
首先你需要传递列表而不是函数,其次你需要用星号'*'操作符解压列表。
graph_maker(*list_maker(voip1, voip2, ...))
标签: python python-3.x list function