gpt4 book ai didi

python - 在 Python 中绘制多项式

转载 作者:太空狗 更新时间:2023-10-29 22:30:57 32 4
gpt4 key购买 nike

除了 matplotlib.pyplot 的一些基本知识外,我是 Python 绘图的新手。我的问题是如何绘制一些更高次的多项式?我看到的一种方法是用 x 表示 y,然后绘制值。但是我有两个困难:

  1. y 和 x 不能分开。
  2. 我期待一条闭合曲线(实际上是一条复杂的曲线)

我要绘制的多项式是:

c0 + c1*x + c2*y +c3*x*x + c4*x*y + c5*y*y + c6*x**3 + c7*x**2*y + ..... c26*x*y**5 + c27*y**6

所有系数 c0c27 都是已知的。如何绘制这条曲线?

另外,您能否向我推荐可以在 Python 中学习绘图和可视化的资源?

澄清:抱歉大家说的不够清楚。它不是曲面方程(涉及 3 个变量:x、y 和 z)。我应该在末尾放一个零:c0 + c1*x + c2*y +c3*x*x + c4*x*y + c5*y*y + c6*x**3 + c7*x** 2*y + ..... c26*x*y**5 + c27*y**6 =0

最佳答案

我不确定我是否完全理解您的问题,但我认为您想要一个 surface plot

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

x = np.arange(-5, 5, 0.25)
y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(x, y)
F = 3 + 2*X + 4*X*Y + 5*X*X

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X, Y, F)
plt.show()

资源:official documentationpyvideos

关于python - 在 Python 中绘制多项式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18088261/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com