我怎么画更多的线?(python sympy)

时间:2017-08-07 03:18:58

标签: python sympy

当我输入时,

from sympy import *
from sympy.plotting import *
from sympy.plotting.plot import *


x, y = symbols('x y')
f = Function('f')
g = Function('g')

f = 1/((x+0.3)**2 + y**2) - 1/((x-0.3)**2 + y**2 )
g = (x+0.3)/sqrt((x+0.3)**2 + y**2) - (x-0.3)/sqrt((x-0.3)**2 + y**2)


p0 = Plot(ContourSeries(f,(x,-1.5,1.5),(y,-1.5,1.5)))
p1 = Plot(ContourSeries(g,(x,-1.5,1.5),(y,-1.5,1.5)))

p0.show()
p1.show()

enter image description here

enter image description here

p0显示与第一张照片相似。线数很少。

我想画更多像第二张图片一样的线条。

解决方案是什么?

1 个答案:

答案 0 :(得分:0)

ContourSeries类未提供执行此操作所需的正确信息,但很容易扩展。我将参数Ec2TagFilters直接传递给matplotlib。

levels

这至少应与sympy 1.2和1.3一起使用。 Sympy绘图为此序列使用了matplotlibs countour(https://github.com/sympy/sympy/blob/master/sympy/plotting/plot.py#L909

class MyContourSeries(ContourSeries):

    def __init__(self, expr, var_start_end_x, var_start_end_y, **kwargs):
        super(MyContourSeries, self).__init__(expr, var_start_end_x, var_start_end_y)
        self.nb_of_points_x = kwargs.get('nb_of_points_x', 50)
        self.nb_of_points_y = kwargs.get('nb_of_points_y', 50)
        self.levels = kwargs.get('levels', 5)

    def get_meshes(self):
        mesh_x, mesh_y, f = super().get_meshes()
        return (mesh_x, mesh_y, f, self.levels)

哪个签名是 elif s.is_contour: self.ax.contour(*s.get_meshes())

与matplotlib轮廓函数一样,您可以使用固定数量的水平

matplotlib.pyplot.contour([X, Y,] Z, [levels], **kwargs)

number of levels

或直接通过关卡

p0 = Plot(MyContourSeries(f, (x, -1.5, 1.5), (y, -1.5, 1.5),
                      nb_of_points_x=50, nb_of_points_y=50, levels=100))
p0.show()

passing a range