【发布时间】:2017-06-21 17:52:57
【问题描述】:
如果我想绘制类似y=x^2 的东西,那么我可以做类似的事情
x = np.linspace(-10, 10, 1000)
plt.plot(x, x**2)
但是,如果等式类似于x + y + sin(x) + sin(y) = 0,我该怎么办?我宁愿不必手动解决y。有没有处理这个的函数?
【问题讨论】:
标签: python matplotlib
如果我想绘制类似y=x^2 的东西,那么我可以做类似的事情
x = np.linspace(-10, 10, 1000)
plt.plot(x, x**2)
但是,如果等式类似于x + y + sin(x) + sin(y) = 0,我该怎么办?我宁愿不必手动解决y。有没有处理这个的函数?
【问题讨论】:
标签: python matplotlib
这样就可以了:
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()
【讨论】:
你可以试试等高线图:
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()
【讨论】: