Python 在matplotlib中不求解因变量而绘制曲线方程?

Python 在matplotlib中不求解因变量而绘制曲线方程?,python,matplotlib,Python,Matplotlib,如果我想绘制类似于y=x^2的图形,那么我可以这样做 x = np.linspace(-10, 10, 1000) plt.plot(x, x**2) 但是,如果这个方程是类似于x+y+sin(x)+sin(y)=0,我该怎么做呢?我宁愿不必手工求解y。是否有处理此问题的函数?您可以尝试等高线图: from matplotlib.pyplot import * def your_function(x, y): return 5 * np.sin(x) - 2 * np.cos(y)

如果我想绘制类似于
y=x^2
的图形,那么我可以这样做

x = np.linspace(-10, 10, 1000)
plt.plot(x, x**2)

但是,如果这个方程是类似于
x+y+sin(x)+sin(y)=0
,我该怎么做呢?我宁愿不必手工求解
y
。是否有处理此问题的函数?

您可以尝试等高线图:

from matplotlib.pyplot import *

def your_function(x, y):
    return 5 * np.sin(x) - 2 * np.cos(y)

x = np.linspace(-10, 10, 1000)
X, Y = np.meshgrid(x, x)
Z = your_function(X, Y)

CP = contour(X, Y, Z, [0])
grid()
show()

您可以尝试等高线图:

from matplotlib.pyplot import *

def your_function(x, y):
    return 5 * np.sin(x) - 2 * np.cos(y)

x = np.linspace(-10, 10, 1000)
X, Y = np.meshgrid(x, x)
Z = your_function(X, Y)

CP = contour(X, Y, Z, [0])
grid()
show()
这将完成以下工作:

import matplotlib.pyplot
import numpy as np
X, Y = np.meshgrid(np.arange(-10, 10, 0.05),np.arange(-10, 10, 0.05))
matplotlib.pyplot.contour(X, Y, X + Y + np.sin(X) + np.sin(Y), [0])
matplotlib.pyplot.show()
这将完成以下工作:

import matplotlib.pyplot
import numpy as np
X, Y = np.meshgrid(np.arange(-10, 10, 0.05),np.arange(-10, 10, 0.05))
matplotlib.pyplot.contour(X, Y, X + Y + np.sin(X) + np.sin(Y), [0])
matplotlib.pyplot.show()