简体   繁体   English

使用具有2个以上参数的用户定义函数的matplotlib绘制3d曲面

[英]Plot 3d surface using matplotlib of user defined function with > 2 arguments

I have a function with 6 arguments, say fn. 我有一个带有6个参数的函数,例如fn。 I also have two arrays, one 'x' array and one 'y' array, filled with values that I would like to evaluate fn on (with the other 4 arguments being held constant the entire time). 我也有两个数组,一个'x'数组和一个'y'数组,其中填充了我想对fn求值的值(其他4个参数在整个时间内保持不变)。 I'd like to get a 3d plot of fn iterated over x,y. 我想在x,y上迭代fn的3d图。 Is there anyway to do this without redefining the function to be a function of 2 arguments with the other 4 held constant? 无论如何,是否要在不将函数重新定义为2个参数且其他4个参数保持不变的情况下执行此操作?

I have seen matplotlib's meshgrid and it seems like a direction to head in, but i'm not sure that calling my function on a meshgrid will work because of the additional four (constant) parameters. 我已经看过matplotlib的meshgrid,似乎是一个前进的方向,但是由于附加的四个(常量)参数,我不确定在meshgrid上调用函数是否可以正常工作。 Any ideas? 有任何想法吗? Will post detailed code if requested. 如果需要,将发布详细代码。

You are looking for something called currying ( http://en.wikipedia.org/wiki/Currying ) 您正在寻找一种称为currying的东西( http://en.wikipedia.org/wiki/Currying

def wrapper_function_factory(fun, c, d, e f):
    return lambda a, b: fun(a, b, c, d, e, f)

fixed_fun = wrapper_function_factor(fun, C, D, E, F)

Z = fixed_fun(x, y)  # assuming your function can do broadcasting

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM