python绘图非线性方程

时间:2018-08-10 22:57:36

标签: python plot nonlinear-functions

在python中绘制非线性方程的最简单方法是什么。

例如:

0 = sqrt((-6 - x) ** 2 + (4 - y) ** 2) - sqrt((1 - x) ** 2 + y ** 2) - 5

我想为x in [0, 10]绘制方程,看起来像一条连续的曲线。

谢谢!

1 个答案:

答案 0 :(得分:1)

这是使用numpy + matplotlib绘制隐式方程的简单方法:

import matplotlib.pyplot
from numpy import arange, meshgrid, sqrt

delta = 0.025
x, y = meshgrid(
    arange(0, 10, delta),
    arange(0, 10, delta)
)

matplotlib.pyplot.contour(
    x, y,
    sqrt((-6 - x) ** 2 + (4 - y) ** 2) - sqrt((1 - x) ** 2 + y ** 2) - 5,
    [0]
)
matplotlib.pyplot.show()

输出:

enter image description here

此方法非常实用,可以分析封闭的表格,例如,半径为3的圆看起来像:

matplotlib.pyplot.contour(
    x, y,
    x**2+y**2-9,
    [0]
)

enter image description here