Python 用参数绘制函数(matplotlib)
我定义了两个函数,第二个是工厂函数Python 用参数绘制函数(matplotlib),python,matplotlib,graph,Python,Matplotlib,Graph,我定义了两个函数,第二个是工厂函数 def bear(S,K): if S <= K: value = K elif K < S and S < 2*K: value = 2*K - S else: value = 0 return value def makeBear(K) def bear1(x): return bear(x,K) re
def bear(S,K):
if S <= K:
value = K
elif K < S and S < 2*K:
value = 2*K - S
else:
value = 0
return value
def makeBear(K)
def bear1(x):
return bear(x,K)
return bear1
等等
给出了图表上的点,但我需要一种更小、更干净的方法来完成此操作。- 你可以试试linspace命令
-5.0000-3.3333-1.6667 0 1.6667 3.3333 5.0000我不完全确定这里的问题是什么。如果你想要一个关于如何绘制x,y值的教程,这个问题太广泛了。你可以用谷歌搜索。如果问题是如何获得值,那么(例如10个值)
x=range(10);y=[makeBear10(val)表示x中的val]
?我基本上需要绘制一个x轴为0-30,y轴为makeBear10(x)的图形。然而你的答案已经帮了大忙了。我只需要知道如何设置自己的y轴限制,在我的例子中[-1,11]。我假设它与plt.axis[-1,11]很接近,但我会尝试找出那个
makeBear10 = makeBear(10)
makeBear10(0)
makeBear10(1)
makeBear10(2)