在Python中绘制多项式 [英] Plotting a polynomial in Python
问题描述
除了matplotlib.pyplot
的一些基本知识之外,我还是Python的新手.我的问题是如何绘制一些高阶多项式?我看到的一种方法是用x表示y,然后绘制值.但是我有两个困难:
I am new to Python plotting apart from some basic knowledge of matplotlib.pyplot
. My question is how to plot some higher degree polynomials? One method I saw was expressing y in terms of x and then plotting the values. But I have 2 difficulties:
- y和x不能分开.
- 我期待一条闭合曲线(实际上是一条复杂的曲线)
我要绘制的多项式是:
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
所有系数c0
至c27
都是已知的.
如何绘制此曲线?
All coefficients c0
to c27
are known.
How do I plot this curve?
您还可以从我可以在Python中学习绘图和可视化的资源中向我推荐一些资源吗?
Also could you please suggest me resources from where I can learn plotting and visualization in 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
Clarification: Sorry everyone for not making it clear enough. It is not an equation of a surface (which involves 3 variables: x, y and z). I should have put a zero at the end: 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
推荐答案
I'm not sure I fully understood your question, but I think you want a 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()