小编And*_*ndy的帖子

如何使用 Sympy 绘制点图?

我需要计算并绘制一个函数及其前两个导数。然后,我需要在图上绘制原始函数的最小值和最大值点。我已经计算了这些,但不知道如何绘制数据图表。最小/最大点的 x 值为 criticalPoints[]

y 值为

criticalPointsY[]

这是出现错误的代码段。

equation=CreateFunction();
    firstDeriv=equation.diff(x);
    secondDeriv=firstDeriv.diff(x);
    print(equation);
criticalPoints=solveset(firstDeriv,x);
criticalPointsY=[];
for a in criticalPoints:
    criticalPointsY.append(equation.subs(x,a));

p=plot(equation,firstDeriv,secondDeriv,(x,-10,10));
# Need to add the critical points to the graph. We have them, and the
# y values, but need to put them on the graphs.
print(criticalPoints)
print(criticalPointsY);
for a in range(0, len(criticalPoints)):
    xval=criticalPoints[a];
    yval=criticalPointsY[a];
    plt.plot(xval, yval, 'ro')
p.show();
plt.show();
Run Code Online (Sandbox Code Playgroud)

当我运行该程序时,我收到此错误。`

Traceback (most recent call last):
  File "--------", line 58, in <module>
    xval=criticalPoints[a];
TypeError: 'FiniteSet' object does not support indexing …
Run Code Online (Sandbox Code Playgroud)

python graphing matplotlib sympy

4
推荐指数
2
解决办法
1万
查看次数

标签 统计

graphing ×1

matplotlib ×1

python ×1

sympy ×1