Beispiel #1
0
def ball():
    # x^2+y^2+z^2=a^2
    # plot3d(x**2+y**2+z**2,(x,-2,2),(y,-2,2),(z,-2,z))
    plot3d_parametric_surface(cos(u + v), sin(u - v), u - v, (u, -5, 5),
                              (v, -5, 5))
    plot3d_parametric_line((cos(u), sin(u), u, (u, -5, 5)),
                           (sin(u), u**2, u, (u, -5, 5)))
    # 圆
    plot_parametric((cos(u), sin(u), (u, -5, 5)), (cos(u), u, (u, -5, 5)))
Beispiel #2
0
def plotgrid_and_save(name):
    tmp_file = TmpFileManager.tmp_file

    x = Symbol('x')
    y = Symbol('y')

    p1 = plot(x)
    p2 = plot_parametric((sin(x), cos(x)), (x, sin(x)), show=False)
    p3 = plot_parametric(cos(x), sin(x), adaptive=False, nb_of_points=500, show=False)
    p4 = plot3d_parametric_line(sin(x), cos(x), x, show=False)
    # symmetric grid
    p = PlotGrid(2, 2, p1, p2, p3, p4)
    p.save(tmp_file('%s_grid1' % name))
    p._backend.close()

    # grid size greater than the number of subplots
    p = PlotGrid(3, 4, p1, p2, p3, p4)
    p.save(tmp_file('%s_grid2' % name))
    p._backend.close()

    p5 = plot(cos(x),(x, -pi, pi), show=False)
    p5[0].line_color = lambda a: a
    p6 = plot(Piecewise((1, x > 0), (0, True)), (x, -1, 1), show=False)
    p7 = plot_contour((x**2 + y**2, (x, -5, 5), (y, -5, 5)), (x**3 + y**3, (x, -3, 3), (y, -3, 3)), show=False)
    # unsymmetric grid (subplots in one line)
    p = PlotGrid(1, 3, p5, p6, p7)
    p.save(tmp_file('%s_grid3' % name))
    p._backend.close()
Beispiel #3
0
def plotgrid_and_save(name):
    tmp_file = TmpFileManager.tmp_file

    x = Symbol('x')
    y = Symbol('y')
    z = Symbol('z')
    p1 = plot(x)
    p2 = plot_parametric((sin(x), cos(x)), (x, sin(x)), show=False)
    p3 = plot_parametric(cos(x), sin(x), adaptive=False, nb_of_points=500, show=False)
    p4 = plot3d_parametric_line(sin(x), cos(x), x, show=False)
    # symmetric grid
    p = PlotGrid(2, 2, p1, p2, p3, p4)
    p.save(tmp_file('%s_grid1' % name))
    p._backend.close()

    # grid size greater than the number of subplots
    p = PlotGrid(3, 4, p1, p2, p3, p4)
    p.save(tmp_file('%s_grid2' % name))
    p._backend.close()

    p5 = plot(cos(x),(x, -pi, pi), show=False)
    p5[0].line_color = lambda a: a
    p6 = plot(Piecewise((1, x > 0), (0, True)), (x, -1, 1), show=False)
    p7 = plot_contour((x**2 + y**2, (x, -5, 5), (y, -5, 5)), (x**3 + y**3, (x, -3, 3), (y, -3, 3)), show=False)
    # unsymmetric grid (subplots in one line)
    p = PlotGrid(1, 3, p5, p6, p7)
    p.save(tmp_file('%s_grid3' % name))
    p._backend.close()
Beispiel #4
0
def func_gui():
	x=funx.get()
	y=funy.get()
	z=funz.get()
	p1=plot3d_parametric_line(x,y,z,(t, l_t.get(), u_t.get()), show=false,title=tit.get())#,xlabel=x_lab.get(),ylabel=y_lab.get())
	p1[0].line_color=result[1]
	p1.show()
Beispiel #5
0
 def __init__(self):
     self.plotters = {
         "plot":
         lambda args, params: plot(*args, **params),
         "plot_parametric":
         lambda args, params: plot_parametric(*args, **params),
         "plot3d":
         lambda args, params: plot3d(*args, **params),
         "plot3d_parametric_line":
         lambda args, params: plot3d_parametric_line(*args, **params),
         "plot3d_parametric_surface":
         lambda args, params: plot3d_parametric_surface(*args, **params),
     }
Beispiel #6
0
def plot_and_save_2(name):
    tmp_file = TmpFileManager.tmp_file

    x = Symbol('x')
    y = Symbol('y')
    z = Symbol('z')

    #parametric 2d plots.
    #Single plot with default range.
    plot_parametric(sin(x), cos(x)).save(tmp_file())

    #Single plot with range.
    p = plot_parametric(sin(x), cos(x), (x, -5, 5))
    p.save(tmp_file('%s_parametric_range' % name))
    p._backend.close()

    #Multiple plots with same range.
    p = plot_parametric((sin(x), cos(x)), (x, sin(x)))
    p.save(tmp_file('%s_parametric_multiple' % name))
    p._backend.close()

    #Multiple plots with different ranges.
    p = plot_parametric((sin(x), cos(x), (x, -3, 3)), (x, sin(x), (x, -5, 5)))
    p.save(tmp_file('%s_parametric_multiple_ranges' % name))
    p._backend.close()

    #depth of recursion specified.
    p = plot_parametric(x, sin(x), depth=13)
    p.save(tmp_file('%s_recursion_depth' % name))
    p._backend.close()

    #No adaptive sampling.
    p = plot_parametric(cos(x), sin(x), adaptive=False, nb_of_points=500)
    p.save(tmp_file('%s_adaptive' % name))
    p._backend.close()

    #3d parametric plots
    p = plot3d_parametric_line(sin(x), cos(x), x)
    p.save(tmp_file('%s_3d_line' % name))
    p._backend.close()

    p = plot3d_parametric_line((sin(x), cos(x), x, (x, -5, 5)),
                               (cos(x), sin(x), x, (x, -3, 3)))
    p.save(tmp_file('%s_3d_line_multiple' % name))
    p._backend.close()

    p = plot3d_parametric_line(sin(x), cos(x), x, nb_of_points=30)
    p.save(tmp_file('%s_3d_line_points' % name))
    p._backend.close()

    # 3d surface single plot.
    p = plot3d(x * y)
    p.save(tmp_file('%s_surface' % name))
    p._backend.close()

    # Multiple 3D plots with same range.
    p = plot3d(-x * y, x * y, (x, -5, 5))
    p.save(tmp_file('%s_surface_multiple' % name))
    p._backend.close()

    # Multiple 3D plots with different ranges.
    p = plot3d((x * y, (x, -3, 3), (y, -3, 3)),
               (-x * y, (x, -3, 3), (y, -3, 3)))
    p.save(tmp_file('%s_surface_multiple_ranges' % name))
    p._backend.close()

    # Single Parametric 3D plot
    p = plot3d_parametric_surface(sin(x + y), cos(x - y), x - y)
    p.save(tmp_file('%s_parametric_surface' % name))
    p._backend.close()

    # Multiple Parametric 3D plots.
    p = plot3d_parametric_surface(
        (x * sin(z), x * cos(z), z, (x, -5, 5), (z, -5, 5)),
        (sin(x + y), cos(x - y), x - y, (x, -5, 5), (y, -5, 5)))
    p.save(tmp_file('%s_parametric_surface' % name))
    p._backend.close()

    # Single Contour plot.
    p = plot_contour(sin(x) * sin(y), (x, -5, 5), (y, -5, 5))
    p.save(tmp_file('%s_contour_plot' % name))
    p._backend.close()

    # Multiple Contour plots with same range.
    p = plot_contour(x**2 + y**2, x**3 + y**3, (x, -5, 5), (y, -5, 5))
    p.save(tmp_file('%s_contour_plot' % name))
    p._backend.close()

    # Multiple Contour plots with different range.
    p = plot_contour((x**2 + y**2, (x, -5, 5), (y, -5, 5)),
                     (x**3 + y**3, (x, -3, 3), (y, -3, 3)))
    p.save(tmp_file('%s_contour_plot' % name))
    p._backend.close()
Beispiel #7
0
def plot3d_parametric_line(*args, **kwargs):
    kwargs.pop("show", None)
    return plotter.plot3d_parametric_line(*plotArgs(args),
                                          show=False,
                                          **kwargs)
Beispiel #8
0
from sympy.plotting import (plot, plot_parametric, plot3d_parametric_surface,
                            plot3d_parametric_line, plot3d)

lx = range(5)
ly = [i**2 for i in lx]

x = Symbol('x')
y = Symbol('y')
u = Symbol('u')
v = Symbol('v')
expr = x**2 - 1

b = plot(expr, (x, 2, 4), show=False)  # cartesian plot
e = plot(exp(-x), (x, 0, 4),
         show=False)  # cartesian plot (and coloring, see below)
f = plot3d_parametric_line(sin(x), cos(x), x, (x, 0, 10),
                           show=False)  # 3d parametric line plot
g = plot3d(sin(x) * cos(y), (x, -5, 5), (y, -10, 10),
           show=False)  # 3d surface cartesian plot
h = plot3d_parametric_surface(cos(u) * v,
                              sin(u) * v,
                              u, (u, 0, 10), (v, -2, 2),
                              show=False)  # 3d parametric surface plot

# Some aesthetics
e[0].line_color = lambda x: x / 4
f[0].line_color = lambda x, y, z: z / 10
g[0].surface_color = lambda x, y: sin(x)

# Some more stuff on aesthetics - coloring wrt coordinates or parameters
param_line_2d = plot_parametric(
    (x * cos(x), x * sin(x), (x, 0, 15)),
Beispiel #9
0
def plot_and_save(name):
    tmp_file = TmpFileManager.tmp_file

    x = Symbol('x')
    y = Symbol('y')
    z = Symbol('z')

    ###
    # Examples from the 'introduction' notebook
    ###

    p = plot(x)
    p = plot(x*sin(x), x*cos(x))
    p.extend(p)
    p[0].line_color = lambda a: a
    p[1].line_color = 'b'
    p.title = 'Big title'
    p.xlabel = 'the x axis'
    p[1].label = 'straight line'
    p.legend = True
    p.aspect_ratio = (1, 1)
    p.xlim = (-15, 20)
    p.save(tmp_file('%s_basic_options_and_colors' % name))
    p._backend.close()

    p.extend(plot(x + 1))
    p.append(plot(x + 3, x**2)[1])
    p.save(tmp_file('%s_plot_extend_append' % name))

    p[2] = plot(x**2, (x, -2, 3))
    p.save(tmp_file('%s_plot_setitem' % name))
    p._backend.close()

    p = plot(sin(x), (x, -2*pi, 4*pi))
    p.save(tmp_file('%s_line_explicit' % name))
    p._backend.close()

    p = plot(sin(x))
    p.save(tmp_file('%s_line_default_range' % name))
    p._backend.close()

    p = plot((x**2, (x, -5, 5)), (x**3, (x, -3, 3)))
    p.save(tmp_file('%s_line_multiple_range' % name))
    p._backend.close()

    raises(ValueError, lambda: plot(x, y))

    p = plot(Piecewise((1, x > 0), (0, True)),(x,-1,1))
    p.save(tmp_file('%s_plot_piecewise' % name))
    p._backend.close()

    #parametric 2d plots.
    #Single plot with default range.
    plot_parametric(sin(x), cos(x)).save(tmp_file())

    #Single plot with range.
    p = plot_parametric(sin(x), cos(x), (x, -5, 5))
    p.save(tmp_file('%s_parametric_range' % name))
    p._backend.close()

    #Multiple plots with same range.
    p = plot_parametric((sin(x), cos(x)), (x, sin(x)))
    p.save(tmp_file('%s_parametric_multiple' % name))
    p._backend.close()

    #Multiple plots with different ranges.
    p = plot_parametric((sin(x), cos(x), (x, -3, 3)), (x, sin(x), (x, -5, 5)))
    p.save(tmp_file('%s_parametric_multiple_ranges' % name))
    p._backend.close()

    #depth of recursion specified.
    p = plot_parametric(x, sin(x), depth=13)
    p.save(tmp_file('%s_recursion_depth' % name))
    p._backend.close()

    #No adaptive sampling.
    p = plot_parametric(cos(x), sin(x), adaptive=False, nb_of_points=500)
    p.save(tmp_file('%s_adaptive' % name))
    p._backend.close()

    #3d parametric plots
    p = plot3d_parametric_line(sin(x), cos(x), x)
    p.save(tmp_file('%s_3d_line' % name))
    p._backend.close()

    p = plot3d_parametric_line(
        (sin(x), cos(x), x, (x, -5, 5)), (cos(x), sin(x), x, (x, -3, 3)))
    p.save(tmp_file('%s_3d_line_multiple' % name))
    p._backend.close()

    p = plot3d_parametric_line(sin(x), cos(x), x, nb_of_points=30)
    p.save(tmp_file('%s_3d_line_points' % name))
    p._backend.close()

    # 3d surface single plot.
    p = plot3d(x * y)
    p.save(tmp_file('%s_surface' % name))
    p._backend.close()

    # Multiple 3D plots with same range.
    p = plot3d(-x * y, x * y, (x, -5, 5))
    p.save(tmp_file('%s_surface_multiple' % name))
    p._backend.close()

    # Multiple 3D plots with different ranges.
    p = plot3d(
        (x * y, (x, -3, 3), (y, -3, 3)), (-x * y, (x, -3, 3), (y, -3, 3)))
    p.save(tmp_file('%s_surface_multiple_ranges' % name))
    p._backend.close()

    # Single Parametric 3D plot
    p = plot3d_parametric_surface(sin(x + y), cos(x - y), x - y)
    p.save(tmp_file('%s_parametric_surface' % name))
    p._backend.close()

    # Multiple Parametric 3D plots.
    p = plot3d_parametric_surface(
        (x*sin(z), x*cos(z), z, (x, -5, 5), (z, -5, 5)),
        (sin(x + y), cos(x - y), x - y, (x, -5, 5), (y, -5, 5)))
    p.save(tmp_file('%s_parametric_surface' % name))
    p._backend.close()

    ###
    # Examples from the 'colors' notebook
    ###

    p = plot(sin(x))
    p[0].line_color = lambda a: a
    p.save(tmp_file('%s_colors_line_arity1' % name))

    p[0].line_color = lambda a, b: b
    p.save(tmp_file('%s_colors_line_arity2' % name))
    p._backend.close()

    p = plot(x*sin(x), x*cos(x), (x, 0, 10))
    p[0].line_color = lambda a: a
    p.save(tmp_file('%s_colors_param_line_arity1' % name))

    p[0].line_color = lambda a, b: a
    p.save(tmp_file('%s_colors_param_line_arity2a' % name))

    p[0].line_color = lambda a, b: b
    p.save(tmp_file('%s_colors_param_line_arity2b' % name))
    p._backend.close()

    p = plot3d_parametric_line(sin(x) + 0.1*sin(x)*cos(7*x),
             cos(x) + 0.1*cos(x)*cos(7*x),
        0.1*sin(7*x),
        (x, 0, 2*pi))
    p[0].line_color = lambda a: sin(4*a)
    p.save(tmp_file('%s_colors_3d_line_arity1' % name))
    p[0].line_color = lambda a, b: b
    p.save(tmp_file('%s_colors_3d_line_arity2' % name))
    p[0].line_color = lambda a, b, c: c
    p.save(tmp_file('%s_colors_3d_line_arity3' % name))
    p._backend.close()

    p = plot3d(sin(x)*y, (x, 0, 6*pi), (y, -5, 5))
    p[0].surface_color = lambda a: a
    p.save(tmp_file('%s_colors_surface_arity1' % name))
    p[0].surface_color = lambda a, b: b
    p.save(tmp_file('%s_colors_surface_arity2' % name))
    p[0].surface_color = lambda a, b, c: c
    p.save(tmp_file('%s_colors_surface_arity3a' % name))
    p[0].surface_color = lambda a, b, c: sqrt((a - 3*pi)**2 + b**2)
    p.save(tmp_file('%s_colors_surface_arity3b' % name))
    p._backend.close()

    p = plot3d_parametric_surface(x * cos(4 * y), x * sin(4 * y), y,
             (x, -1, 1), (y, -1, 1))
    p[0].surface_color = lambda a: a
    p.save(tmp_file('%s_colors_param_surf_arity1' % name))
    p[0].surface_color = lambda a, b: a*b
    p.save(tmp_file('%s_colors_param_surf_arity2' % name))
    p[0].surface_color = lambda a, b, c: sqrt(a**2 + b**2 + c**2)
    p.save(tmp_file('%s_colors_param_surf_arity3' % name))
    p._backend.close()

    ###
    # Examples from the 'advanced' notebook
    ###

    i = Integral(log((sin(x)**2 + 1)*sqrt(x**2 + 1)), (x, 0, y))
    p = plot(i, (y, 1, 5))
    p.save(tmp_file('%s_advanced_integral' % name))
    p._backend.close()

    s = Sum(1/x**y, (x, 1, oo))
    p = plot(s, (y, 2, 10))
    p.save(tmp_file('%s_advanced_inf_sum' % name))
    p._backend.close()

    p = plot(Sum(1/x, (x, 1, y)), (y, 2, 10), show=False)
    p[0].only_integers = True
    p[0].steps = True
    p.save(tmp_file('%s_advanced_fin_sum' % name))
    p._backend.close()

    ###
    # Test expressions that can not be translated to np and generate complex
    # results.
    ###
    plot(sin(x) + I*cos(x)).save(tmp_file())
    plot(sqrt(sqrt(-x))).save(tmp_file())
    plot(LambertW(x)).save(tmp_file())
    plot(sqrt(LambertW(x))).save(tmp_file())

    #Characteristic function of a StudentT distribution with nu=10
    plot((meijerg(((1 / 2,), ()), ((5, 0, 1 / 2), ()), 5 * x**2 * exp_polar(-I*pi)/2)
            + meijerg(((1/2,), ()), ((5, 0, 1/2), ()),
                5*x**2 * exp_polar(I*pi)/2)) / (48 * pi), (x, 1e-6, 1e-2)).save(tmp_file())
Beispiel #10
0
def plot_and_save_3(name):
    tmp_file = TmpFileManager.tmp_file

    x = Symbol('x')
    y = Symbol('y')
    z = Symbol('z')

    ###
    # Examples from the 'colors' notebook
    ###

    p = plot(sin(x))
    p[0].line_color = lambda a: a
    p.save(tmp_file('%s_colors_line_arity1' % name))

    p[0].line_color = lambda a, b: b
    p.save(tmp_file('%s_colors_line_arity2' % name))
    p._backend.close()

    p = plot(x*sin(x), x*cos(x), (x, 0, 10))
    p[0].line_color = lambda a: a
    p.save(tmp_file('%s_colors_param_line_arity1' % name))

    p[0].line_color = lambda a, b: a
    p.save(tmp_file('%s_colors_param_line_arity2a' % name))

    p[0].line_color = lambda a, b: b
    p.save(tmp_file('%s_colors_param_line_arity2b' % name))
    p._backend.close()

    p = plot3d_parametric_line(sin(x) + 0.1*sin(x)*cos(7*x),
             cos(x) + 0.1*cos(x)*cos(7*x),
        0.1*sin(7*x),
        (x, 0, 2*pi))
    p[0].line_color = lambdify_(x, sin(4*x))
    p.save(tmp_file('%s_colors_3d_line_arity1' % name))
    p[0].line_color = lambda a, b: b
    p.save(tmp_file('%s_colors_3d_line_arity2' % name))
    p[0].line_color = lambda a, b, c: c
    p.save(tmp_file('%s_colors_3d_line_arity3' % name))
    p._backend.close()

    p = plot3d(sin(x)*y, (x, 0, 6*pi), (y, -5, 5))
    p[0].surface_color = lambda a: a
    p.save(tmp_file('%s_colors_surface_arity1' % name))
    p[0].surface_color = lambda a, b: b
    p.save(tmp_file('%s_colors_surface_arity2' % name))
    p[0].surface_color = lambda a, b, c: c
    p.save(tmp_file('%s_colors_surface_arity3a' % name))
    p[0].surface_color = lambdify_((x, y, z), sqrt((x - 3*pi)**2 + y**2))
    p.save(tmp_file('%s_colors_surface_arity3b' % name))
    p._backend.close()

    p = plot3d_parametric_surface(x * cos(4 * y), x * sin(4 * y), y,
             (x, -1, 1), (y, -1, 1))
    p[0].surface_color = lambda a: a
    p.save(tmp_file('%s_colors_param_surf_arity1' % name))
    p[0].surface_color = lambda a, b: a*b
    p.save(tmp_file('%s_colors_param_surf_arity2' % name))
    p[0].surface_color = lambdify_((x, y, z), sqrt(x**2 + y**2 + z**2))
    p.save(tmp_file('%s_colors_param_surf_arity3' % name))
    p._backend.close()
Beispiel #11
0
# alpha(t) function alpha(t)=([[alpha1(t), alpha2(t), alpha3(t)]])
alpha = sp.Matrix([[sp.cos(t), sp.sin(t), sp.exp(t)]])

# Tangent vector (d/dt)alpha(t)
da = sp.simplify(sp.diff(alpha, t))
print("alpha(s)'s Tangent vector T(t)=(d/dt)alpha(t): T(t)=%s \n" % (da))

# Speed ||(d/dt)alpha(t)||
print("Speed of alpha(t): ||(d/dt)alpha(t)||=%s\n" %
      (sp.simplify(sp.sqrt(da.dot(da)))))

# Acceleration ((d2)/d(t2))alpha(t)
dda = sp.simplify(da.diff(t))
print("Acceleration of alpha(t) ((d2)/(dt2))alpha(t): a(t)=%s" % (dda))

# Plotting
"""
Plots alpha(t) uncomment the option according to alpha(t)
The code inside $'s signs is LaTeX code
"""

x = alpha[0]
y = alpha[1]
z = alpha[2]

# 2d
#spp.plot_parametric(x, y, (t, -2, 2), title=r"Plot of $\alpha(t)$")

# 3d
spp.plot3d_parametric_line(x, y, z, (t, -2, 2), title=r"Plot of $\alpha(t)$")
Beispiel #12
0
# A parametric plot - a Lissajous curve.
# %%
t=Symbol('t')
plot_parametric(sin(2*t),cos(3*t),(t,0,2*pi),
                title='Lissajous',xlabel='x',ylabel='y')
# %% markdown
# An implicit plot - a circle.
# %%
plot_implicit(x**2+y**2-1,(x,-1,1),(y,-1,1))
# %% markdown
# A surface. If it is not inline but in a separaye window, you can rotate it with your mouse.
# %%
plot3d(x*y,(x,-2,2),(y,-2,2))
# %% markdown
# Several surfaces.
# %%
plot3d(x**2+y**2,x*y,(x,-2,2),(y,-2,2))
# %% markdown
# A parametric space curve - a spiral.
# %%
a=0.1
plot3d_parametric_line(cos(t),sin(t),a*t,(t,0,4*pi))
# %% markdown
# A parametric surface - a torus.
# %%
u,v=symbols('u v')
a=0.3
plot3d_parametric_surface((1+a*cos(u))*cos(v),
                          (1+a*cos(u))*sin(v),a*sin(u),
                          (u,0,2*pi),(v,0,2*pi))
Beispiel #13
0
v = Symbol('v')
theta = Symbol('theta')
epsilon = 2
epsilon_z = 1.5
mu = 0.2
mu_z = 1.9
omega = 40 * pi
# -sqrt(epsilon*epsilon_z*mu/(-epsilon*cos(theta)**2 + epsilon + epsilon_z*cos(theta)**2))*Abs(omega)
expr = -sqrt(
    epsilon * epsilon_z * mu /
    (-epsilon * cos(theta)**2 + epsilon + epsilon_z * cos(theta)**2)) * omega

#param_line_3d = plot3d_parametric_line((x*cos(x), x*sin(x), x, (x, 0, 15)),(1.5*x*cos(x), 1.5*x*sin(x), x, (x, 0, 15)),(2*x*cos(x), 2*x*sin(x), x, (x, 0, 15)), show=False)
param_line_3d = plot3d_parametric_line((epsilon_z*cos(expr)*cos(theta)*cos(omega*theta)/sin(theta)/epsilon -omega*mu_z*cos(expr)*cos(omega*theta)/sin(theta)/expr,\
           -epsilon_z*cos(expr)*cos(theta)*sin(omega*theta)/sin(theta)/epsilon*expr + omega*epsilon_z*cos(expr)*sin(omega*theta)/sin(theta)/expr,\
            exp(theta), (theta, 0.1, 3)),\
#				       (-omega*mu_z*exp(expr)*cos(omega*theta)/sin(theta)/expr,\
#				       omega*epsilon_z*exp(expr)*sin(omega*theta)/sin(theta)/expr,\
#				        exp(expr), (theta, 0.1, 3)),\
#				        (-omega*mu_z*cos(theta)/sin(theta)**2 /expr,\
#				        omega*epsilon_z*cos(theta)/sin(theta)**2 *cos(omega*theta+pi/2)**2 * expr,\
#				        theta, (theta, 0.1, 20)),\
            show=False)
param_line_3d[0].line_color = lambda u: u  # parametric
#param_line_3d[1].line_color = lambda u, v: u*v  # first and second coordinates
#param_line_3d[2].line_color = lambda u, v, w: u*v*w  # all coordinates

if __name__ == '__main__':
    for p in [param_line_3d]:
        p.show()
Beispiel #14
0
from sympy import *
from sympy.plotting import plot3d_parametric_line

u = symbols('u')
x=raw_input("input x in terms of 1 parameter : ")
y=raw_input("input y in terms of 1 parameter : ")
z=raw_input("input z in terms of 1 parameter : ")
lu=input("lower limit of u :")
uu=input("upper limit of u :")
p1=plot3d_parametric_line(x,y,z,(u,lu,uu))
Beispiel #15
0
def plot_and_save(name):
    tmp_file = TmpFileManager.tmp_file

    x = Symbol('x')
    y = Symbol('y')
    z = Symbol('z')

    ###
    # Examples from the 'introduction' notebook
    ###

    p = plot(x)
    p = plot(x * sin(x), x * cos(x))
    p.extend(p)
    p[0].line_color = lambda a: a
    p[1].line_color = 'b'
    p.title = 'Big title'
    p.xlabel = 'the x axis'
    p[1].label = 'straight line'
    p.legend = True
    p.aspect_ratio = (1, 1)
    p.xlim = (-15, 20)
    p.save(tmp_file('%s_basic_options_and_colors' % name))
    p._backend.close()

    p.extend(plot(x + 1))
    p.append(plot(x + 3, x**2)[1])
    p.save(tmp_file('%s_plot_extend_append' % name))

    p[2] = plot(x**2, (x, -2, 3))
    p.save(tmp_file('%s_plot_setitem' % name))
    p._backend.close()

    p = plot(sin(x), (x, -2 * pi, 4 * pi))
    p.save(tmp_file('%s_line_explicit' % name))
    p._backend.close()

    p = plot(sin(x))
    p.save(tmp_file('%s_line_default_range' % name))
    p._backend.close()

    p = plot((x**2, (x, -5, 5)), (x**3, (x, -3, 3)))
    p.save(tmp_file('%s_line_multiple_range' % name))
    p._backend.close()

    raises(ValueError, lambda: plot(x, y))

    p = plot(Piecewise((1, x > 0), (0, True)), (x, -1, 1))
    p.save(tmp_file('%s_plot_piecewise' % name))
    p._backend.close()

    #parametric 2d plots.
    #Single plot with default range.
    plot_parametric(sin(x), cos(x)).save(tmp_file())

    #Single plot with range.
    p = plot_parametric(sin(x), cos(x), (x, -5, 5))
    p.save(tmp_file('%s_parametric_range' % name))
    p._backend.close()

    #Multiple plots with same range.
    p = plot_parametric((sin(x), cos(x)), (x, sin(x)))
    p.save(tmp_file('%s_parametric_multiple' % name))
    p._backend.close()

    #Multiple plots with different ranges.
    p = plot_parametric((sin(x), cos(x), (x, -3, 3)), (x, sin(x), (x, -5, 5)))
    p.save(tmp_file('%s_parametric_multiple_ranges' % name))
    p._backend.close()

    #depth of recursion specified.
    p = plot_parametric(x, sin(x), depth=13)
    p.save(tmp_file('%s_recursion_depth' % name))
    p._backend.close()

    #No adaptive sampling.
    p = plot_parametric(cos(x), sin(x), adaptive=False, nb_of_points=500)
    p.save(tmp_file('%s_adaptive' % name))
    p._backend.close()

    #3d parametric plots
    p = plot3d_parametric_line(sin(x), cos(x), x)
    p.save(tmp_file('%s_3d_line' % name))
    p._backend.close()

    p = plot3d_parametric_line((sin(x), cos(x), x, (x, -5, 5)),
                               (cos(x), sin(x), x, (x, -3, 3)))
    p.save(tmp_file('%s_3d_line_multiple' % name))
    p._backend.close()

    p = plot3d_parametric_line(sin(x), cos(x), x, nb_of_points=30)
    p.save(tmp_file('%s_3d_line_points' % name))
    p._backend.close()

    # 3d surface single plot.
    p = plot3d(x * y)
    p.save(tmp_file('%s_surface' % name))
    p._backend.close()

    # Multiple 3D plots with same range.
    p = plot3d(-x * y, x * y, (x, -5, 5))
    p.save(tmp_file('%s_surface_multiple' % name))
    p._backend.close()

    # Multiple 3D plots with different ranges.
    p = plot3d((x * y, (x, -3, 3), (y, -3, 3)),
               (-x * y, (x, -3, 3), (y, -3, 3)))
    p.save(tmp_file('%s_surface_multiple_ranges' % name))
    p._backend.close()

    # Single Parametric 3D plot
    p = plot3d_parametric_surface(sin(x + y), cos(x - y), x - y)
    p.save(tmp_file('%s_parametric_surface' % name))
    p._backend.close()

    # Multiple Parametric 3D plots.
    p = plot3d_parametric_surface(
        (x * sin(z), x * cos(z), z, (x, -5, 5), (z, -5, 5)),
        (sin(x + y), cos(x - y), x - y, (x, -5, 5), (y, -5, 5)))
    p.save(tmp_file('%s_parametric_surface' % name))
    p._backend.close()

    ###
    # Examples from the 'colors' notebook
    ###

    p = plot(sin(x))
    p[0].line_color = lambda a: a
    p.save(tmp_file('%s_colors_line_arity1' % name))

    p[0].line_color = lambda a, b: b
    p.save(tmp_file('%s_colors_line_arity2' % name))
    p._backend.close()

    p = plot(x * sin(x), x * cos(x), (x, 0, 10))
    p[0].line_color = lambda a: a
    p.save(tmp_file('%s_colors_param_line_arity1' % name))

    p[0].line_color = lambda a, b: a
    p.save(tmp_file('%s_colors_param_line_arity2a' % name))

    p[0].line_color = lambda a, b: b
    p.save(tmp_file('%s_colors_param_line_arity2b' % name))
    p._backend.close()

    p = plot3d_parametric_line(
        sin(x) + 0.1 * sin(x) * cos(7 * x),
        cos(x) + 0.1 * cos(x) * cos(7 * x), 0.1 * sin(7 * x), (x, 0, 2 * pi))
    p[0].line_color = lambda a: sin(4 * a)
    p.save(tmp_file('%s_colors_3d_line_arity1' % name))
    p[0].line_color = lambda a, b: b
    p.save(tmp_file('%s_colors_3d_line_arity2' % name))
    p[0].line_color = lambda a, b, c: c
    p.save(tmp_file('%s_colors_3d_line_arity3' % name))
    p._backend.close()

    p = plot3d(sin(x) * y, (x, 0, 6 * pi), (y, -5, 5))
    p[0].surface_color = lambda a: a
    p.save(tmp_file('%s_colors_surface_arity1' % name))
    p[0].surface_color = lambda a, b: b
    p.save(tmp_file('%s_colors_surface_arity2' % name))
    p[0].surface_color = lambda a, b, c: c
    p.save(tmp_file('%s_colors_surface_arity3a' % name))
    p[0].surface_color = lambda a, b, c: sqrt((a - 3 * pi)**2 + b**2)
    p.save(tmp_file('%s_colors_surface_arity3b' % name))
    p._backend.close()

    p = plot3d_parametric_surface(x * cos(4 * y), x * sin(4 * y), y,
                                  (x, -1, 1), (y, -1, 1))
    p[0].surface_color = lambda a: a
    p.save(tmp_file('%s_colors_param_surf_arity1' % name))
    p[0].surface_color = lambda a, b: a * b
    p.save(tmp_file('%s_colors_param_surf_arity2' % name))
    p[0].surface_color = lambda a, b, c: sqrt(a**2 + b**2 + c**2)
    p.save(tmp_file('%s_colors_param_surf_arity3' % name))
    p._backend.close()

    ###
    # Examples from the 'advanced' notebook
    ###

    i = Integral(log((sin(x)**2 + 1) * sqrt(x**2 + 1)), (x, 0, y))
    p = plot(i, (y, 1, 5))
    p.save(tmp_file('%s_advanced_integral' % name))
    p._backend.close()

    s = Sum(1 / x**y, (x, 1, oo))
    p = plot(s, (y, 2, 10))
    p.save(tmp_file('%s_advanced_inf_sum' % name))
    p._backend.close()

    p = plot(Sum(1 / x, (x, 1, y)), (y, 2, 10), show=False)
    p[0].only_integers = True
    p[0].steps = True
    p.save(tmp_file('%s_advanced_fin_sum' % name))
    p._backend.close()

    ###
    # Test expressions that can not be translated to np and generate complex
    # results.
    ###
    plot(sin(x) + I * cos(x)).save(tmp_file())
    plot(sqrt(sqrt(-x))).save(tmp_file())
    plot(LambertW(x)).save(tmp_file())
    plot(sqrt(LambertW(x))).save(tmp_file())

    #Characteristic function of a StudentT distribution with nu=10
    plot((meijerg(
        ((1 / 2, ), ()),
        ((5, 0, 1 / 2), ()), 5 * x**2 * exp_polar(-I * pi) / 2) + meijerg(
            ((1 / 2, ), ()),
            ((5, 0, 1 / 2),
             ()), 5 * x**2 * exp_polar(I * pi) / 2)) / (48 * pi),
         (x, 1e-6, 1e-2)).save(tmp_file())
Beispiel #16
0
def plot_and_save_3(name):
    tmp_file = TmpFileManager.tmp_file

    x = Symbol('x')
    y = Symbol('y')
    z = Symbol('z')

    ###
    # Examples from the 'colors' notebook
    ###

    p = plot(sin(x))
    p[0].line_color = lambda a: a
    p.save(tmp_file('%s_colors_line_arity1' % name))

    p[0].line_color = lambda a, b: b
    p.save(tmp_file('%s_colors_line_arity2' % name))
    p._backend.close()

    p = plot(x * sin(x), x * cos(x), (x, 0, 10))
    p[0].line_color = lambda a: a
    p.save(tmp_file('%s_colors_param_line_arity1' % name))

    p[0].line_color = lambda a, b: a
    p.save(tmp_file('%s_colors_param_line_arity2a' % name))

    p[0].line_color = lambda a, b: b
    p.save(tmp_file('%s_colors_param_line_arity2b' % name))
    p._backend.close()

    p = plot3d_parametric_line(
        sin(x) + 0.1 * sin(x) * cos(7 * x),
        cos(x) + 0.1 * cos(x) * cos(7 * x), 0.1 * sin(7 * x), (x, 0, 2 * pi))
    p[0].line_color = lambdify_(x, sin(4 * x))
    p.save(tmp_file('%s_colors_3d_line_arity1' % name))
    p[0].line_color = lambda a, b: b
    p.save(tmp_file('%s_colors_3d_line_arity2' % name))
    p[0].line_color = lambda a, b, c: c
    p.save(tmp_file('%s_colors_3d_line_arity3' % name))
    p._backend.close()

    p = plot3d(sin(x) * y, (x, 0, 6 * pi), (y, -5, 5))
    p[0].surface_color = lambda a: a
    p.save(tmp_file('%s_colors_surface_arity1' % name))
    p[0].surface_color = lambda a, b: b
    p.save(tmp_file('%s_colors_surface_arity2' % name))
    p[0].surface_color = lambda a, b, c: c
    p.save(tmp_file('%s_colors_surface_arity3a' % name))
    p[0].surface_color = lambdify_((x, y, z), sqrt((x - 3 * pi)**2 + y**2))
    p.save(tmp_file('%s_colors_surface_arity3b' % name))
    p._backend.close()

    p = plot3d_parametric_surface(x * cos(4 * y), x * sin(4 * y), y,
                                  (x, -1, 1), (y, -1, 1))
    p[0].surface_color = lambda a: a
    p.save(tmp_file('%s_colors_param_surf_arity1' % name))
    p[0].surface_color = lambda a, b: a * b
    p.save(tmp_file('%s_colors_param_surf_arity2' % name))
    p[0].surface_color = lambdify_((x, y, z), sqrt(x**2 + y**2 + z**2))
    p.save(tmp_file('%s_colors_param_surf_arity3' % name))
    p._backend.close()
Beispiel #17
0
from sympy.plotting import (plot, plot_parametric,
                            plot3d_parametric_surface, plot3d_parametric_line,
                            plot3d)

lx = range(5)
ly = [i**2 for i in lx]

x = Symbol('x')
y = Symbol('y')
u = Symbol('u')
v = Symbol('v')
expr = x**2 - 1

b = plot(expr, (x, 2, 4), show=False)  # cartesian plot
e = plot(exp(-x), (x, 0, 4), show=False)  # cartesian plot (and coloring, see below)
f = plot3d_parametric_line(sin(x), cos(x), x, (x, 0, 10), show=False)  # 3d parametric line plot
g = plot3d(sin(x)*cos(y), (x, -5, 5), (y, -10, 10), show=False)  # 3d surface cartesian plot
h = plot3d_parametric_surface(cos(u)*v, sin(u)*v, u, (u, 0, 10), (v, -2, 2), show=False)  # 3d parametric surface plot

# Some aesthetics
e[0].line_color = lambda x: x / 4
f[0].line_color = lambda x, y, z: z / 10
g[0].surface_color = lambda x, y: sin(x)

# Some more stuff on aesthetics - coloring wrt coordinates or parameters
param_line_2d = plot_parametric((x*cos(x), x*sin(x), (x, 0, 15)), (1.1*x*cos(x), 1.1*x*sin(x), (x, 0, 15)), show=False)
param_line_2d[0].line_color = lambda u: sin(u)  # parametric
param_line_2d[1].line_color = lambda u, v: u**2 + v**2  # coordinates
param_line_2d.title = 'The inner one is colored by parameter and the outher one by coordinates'

param_line_3d = plot3d_parametric_line((x*cos(x), x*sin(x), x, (x, 0, 15)),
Beispiel #18
0
def plot_and_save(name):
    x = Symbol('x')
    y = Symbol('y')
    z = Symbol('z')

    ###
    # Examples from the 'introduction' notebook
    ###

    p = plot(x)
    p = plot(x*sin(x),x*cos(x))
    p.extend(p)
    p[0].line_color = lambda a : a
    p[1].line_color='b'
    p.title = 'Big title'
    p.xlabel = 'the x axis'
    p[1].label = 'straight line'
    p.legend = True
    p.aspect_ratio = (1,1)
    p.xlim = (-15,20)
    p.save(tmp_file('%s_basic_options_and_colors.png' % name))

    p.extend(plot(x+1))
    p.append(plot(x+3,x**2)[1])
    p.save(tmp_file('%s_plot_extend_append.png' % name))

    p[2] = plot(x**2, (x, -2, 3))
    p.save(tmp_file('%s_plot_setitem.png' % name))

    p = plot(sin(x),(x,-2*pi,4*pi))
    p.save(tmp_file('%s_line_explicit.png' % name))

    p = plot(sin(x))
    p.save(tmp_file('%s_line_default_range.png' % name))

    p = plot((x**2, (x, -5, 5)), (x**3, (x, -3, 3)))
    p.save(tmp_file('%s_line_multiple_range.png' % name))


    #parametric 2d plots.
    #Single plot with default range.
    plot_parametric(sin(x), cos(x)).save(tmp_file())

    #Single plot with range.
    p = plot_parametric(sin(x), cos(x), (x, -5, 5))
    p.save(tmp_file('%s_parametric_range.png' % name))

    #Multiple plots with same range.
    p = plot_parametric((sin(x), cos(x)), (x, sin(x)))
    p.save(tmp_file('%s_parametric_multiple.png' % name))

    #Multiple plots with different ranges.
    p = plot_parametric((sin(x), cos(x), (x, -3, 3)), (x, sin(x), (x, -5, 5)))
    p.save(tmp_file('%s_parametric_multiple_ranges.png' % name))

    #depth of recursion specified.
    p = plot_parametric(x, sin(x), depth=13)
    p.save(tmp_file('%s_recursion_depth' % name))

    #No adaptive sampling.
    p = plot_parametric(cos(x), sin(x), adaptive=False, nb_of_points=500)
    p.save(tmp_file('%s_adaptive' % name))

    #3d parametric plots
    p = plot3d_parametric_line(sin(x),cos(x),x)
    p.save(tmp_file('%s_3d_line.png' % name))

    p = plot3d_parametric_line((sin(x), cos(x), x, (x, -5, 5)), (cos(x), sin(x), x, (x, -3, 3)))
    p.save(tmp_file('%s_3d_line_multiple' % name))

    p = plot3d_parametric_line(sin(x), cos(x), x, nb_of_points=30)
    p.save(tmp_file('%s_3d_line_points' % name))

    # 3d surface single plot.
    p = plot3d(x * y)
    p.save(tmp_file('%s_surface.png' % name))

    # Multiple 3D plots with same range.
    p = plot3d(-x * y, x * y, (x, -5, 5))
    p.save(tmp_file('%s_surface_multiple' % name))

    # Multiple 3D plots with different ranges.
    p = plot3d((x * y, (x, -3, 3), (y, -3, 3)), (-x * y, (x, -3, 3), (y, -3, 3)))
    p.save(tmp_file('%s_surface_multiple_ranges' % name))

    # Single Parametric 3D plot
    p = plot3d_parametric_surface(sin(x + y), cos(x - y), x - y)
    p.save(tmp_file('%s_parametric_surface' % name))

    # Multiple Parametric 3D plots.
    p = plot3d_parametric_surface((x*sin(z),x*cos(z),z, (x, -5, 5), (z, -5, 5)),
                (sin(x + y), cos(x - y), x - y, (x, -5, 5), (y, -5, 5)))
    p.save(tmp_file('%s_parametric_surface.png' % name))

    ###
    # Examples from the 'colors' notebook
    ###

    p = plot(sin(x))
    p[0].line_color = lambda a : a
    p.save(tmp_file('%s_colors_line_arity1.png' % name))

    p[0].line_color = lambda a, b : b
    p.save(tmp_file('%s_colors_line_arity2.png' % name))

    p = plot(x*sin(x), x*cos(x), (x, 0, 10))
    p[0].line_color = lambda a : a
    p.save(tmp_file('%s_colors_param_line_arity1.png' % name))

    p[0].line_color = lambda a, b : a
    p.save(tmp_file('%s_colors_param_line_arity2a.png' % name))

    p[0].line_color = lambda a, b : b
    p.save(tmp_file('%s_colors_param_line_arity2b.png' % name))

    p = plot3d_parametric_line(sin(x)+0.1*sin(x)*cos(7*x),
             cos(x)+0.1*cos(x)*cos(7*x),
             0.1*sin(7*x),
             (x, 0 , 2*pi))
    p[0].line_color = lambda a : sin(4*a)
    p.save(tmp_file('%s_colors_3d_line_arity1.png' % name))
    p[0].line_color = lambda a, b : b
    p.save(tmp_file('%s_colors_3d_line_arity2.png' % name))
    p[0].line_color = lambda a, b, c : c
    p.save(tmp_file('%s_colors_3d_line_arity3.png' % name))

    p = plot3d(sin(x)*y, (x, 0, 6*pi), (y, -5, 5))
    p[0].surface_color = lambda a : a
    p.save(tmp_file('%s_colors_surface_arity1.png' % name))
    p[0].surface_color = lambda a, b : b
    p.save(tmp_file('%s_colors_surface_arity2.png' % name))
    p[0].surface_color = lambda a, b, c : c
    p.save(tmp_file('%s_colors_surface_arity3a.png' % name))
    p[0].surface_color = lambda a, b, c : sqrt((a-3*pi)**2+b**2)
    p.save(tmp_file('%s_colors_surface_arity3b.png' % name))

    p = plot3d_parametric_surface(x * cos(4 * y), x * sin(4 * y), y,
             (x, -1, 1), (y, -1, 1))
    p[0].surface_color = lambda a : a
    p.save(tmp_file('%s_colors_param_surf_arity1.png' % name))
    p[0].surface_color = lambda a, b : a*b
    p.save(tmp_file('%s_colors_param_surf_arity2.png' % name))
    p[0].surface_color = lambda a, b, c : sqrt(a**2+b**2+c**2)
    p.save(tmp_file('%s_colors_param_surf_arity3.png' % name))

    ###
    # Examples from the 'advanced' notebook
    ###

    i = Integral(log((sin(x)**2+1)*sqrt(x**2+1)),(x,0,y))
    p = plot(i,(y, 1, 5))
    p.save(tmp_file('%s_advanced_integral.png' % name))

    s = summation(1/x**y,(x, 1, oo))
    p = plot(s, (y, 2, 10))
    p.save(tmp_file('%s_advanced_inf_sum.png' % name))

    p = plot(summation(1/x,(x,1,y)), (y, 2,10), show=False)
    p[0].only_integers = True
    p[0].steps = True
    p.save(tmp_file('%s_advanced_fin_sum.png' % name))


    ###
    # Test expressions that can not be translated to np and generate complex
    # results.
    ###


    plot(sin(x)+I*cos(x)).save(tmp_file())
    plot(sqrt(sqrt(-x))).save(tmp_file())
    plot(LambertW(x)).save(tmp_file())
    plot(sqrt(LambertW(x))).save(tmp_file())
Beispiel #19
0
def plot_and_save_2(name):
    tmp_file = TmpFileManager.tmp_file

    x = Symbol('x')
    y = Symbol('y')
    z = Symbol('z')

    #parametric 2d plots.
    #Single plot with default range.
    plot_parametric(sin(x), cos(x)).save(tmp_file())

    #Single plot with range.
    p = plot_parametric(sin(x), cos(x), (x, -5, 5))
    p.save(tmp_file('%s_parametric_range' % name))
    p._backend.close()

    #Multiple plots with same range.
    p = plot_parametric((sin(x), cos(x)), (x, sin(x)))
    p.save(tmp_file('%s_parametric_multiple' % name))
    p._backend.close()

    #Multiple plots with different ranges.
    p = plot_parametric((sin(x), cos(x), (x, -3, 3)), (x, sin(x), (x, -5, 5)))
    p.save(tmp_file('%s_parametric_multiple_ranges' % name))
    p._backend.close()

    #depth of recursion specified.
    p = plot_parametric(x, sin(x), depth=13)
    p.save(tmp_file('%s_recursion_depth' % name))
    p._backend.close()

    #No adaptive sampling.
    p = plot_parametric(cos(x), sin(x), adaptive=False, nb_of_points=500)
    p.save(tmp_file('%s_adaptive' % name))
    p._backend.close()

    #3d parametric plots
    p = plot3d_parametric_line(sin(x), cos(x), x)
    p.save(tmp_file('%s_3d_line' % name))
    p._backend.close()

    p = plot3d_parametric_line(
        (sin(x), cos(x), x, (x, -5, 5)), (cos(x), sin(x), x, (x, -3, 3)))
    p.save(tmp_file('%s_3d_line_multiple' % name))
    p._backend.close()

    p = plot3d_parametric_line(sin(x), cos(x), x, nb_of_points=30)
    p.save(tmp_file('%s_3d_line_points' % name))
    p._backend.close()

    # 3d surface single plot.
    p = plot3d(x * y)
    p.save(tmp_file('%s_surface' % name))
    p._backend.close()

    # Multiple 3D plots with same range.
    p = plot3d(-x * y, x * y, (x, -5, 5))
    p.save(tmp_file('%s_surface_multiple' % name))
    p._backend.close()

    # Multiple 3D plots with different ranges.
    p = plot3d(
        (x * y, (x, -3, 3), (y, -3, 3)), (-x * y, (x, -3, 3), (y, -3, 3)))
    p.save(tmp_file('%s_surface_multiple_ranges' % name))
    p._backend.close()

    # Single Parametric 3D plot
    p = plot3d_parametric_surface(sin(x + y), cos(x - y), x - y)
    p.save(tmp_file('%s_parametric_surface' % name))
    p._backend.close()

    # Multiple Parametric 3D plots.
    p = plot3d_parametric_surface(
        (x*sin(z), x*cos(z), z, (x, -5, 5), (z, -5, 5)),
        (sin(x + y), cos(x - y), x - y, (x, -5, 5), (y, -5, 5)))
    p.save(tmp_file('%s_parametric_surface' % name))
    p._backend.close()

    # Single Contour plot.
    p = plot_contour(sin(x)*sin(y), (x, -5, 5), (y, -5, 5))
    p.save(tmp_file('%s_contour_plot' % name))
    p._backend.close()

    # Multiple Contour plots with same range.
    p = plot_contour(x**2 + y**2, x**3 + y**3, (x, -5, 5), (y, -5, 5))
    p.save(tmp_file('%s_contour_plot' % name))
    p._backend.close()

    # Multiple Contour plots with different range.
    p = plot_contour((x**2 + y**2, (x, -5, 5), (y, -5, 5)), (x**3 + y**3, (x, -3, 3), (y, -3, 3)))
    p.save(tmp_file('%s_contour_plot' % name))
    p._backend.close()
Beispiel #20
0
v = Symbol('v')
theta = Symbol('theta')
epsilon = 2
epsilon_z = 1.5
mu = 0.2
mu_z = 1.9
omega = 40*pi 
# -sqrt(epsilon*epsilon_z*mu/(-epsilon*cos(theta)**2 + epsilon + epsilon_z*cos(theta)**2))*Abs(omega)
expr = -sqrt(epsilon*epsilon_z*mu/(-epsilon*cos(theta)**2 + epsilon + epsilon_z*cos(theta)**2))*omega

#param_line_3d = plot3d_parametric_line((x*cos(x), x*sin(x), x, (x, 0, 15)),(1.5*x*cos(x), 1.5*x*sin(x), x, (x, 0, 15)),(2*x*cos(x), 2*x*sin(x), x, (x, 0, 15)), show=False)
param_line_3d = plot3d_parametric_line((epsilon_z*cos(expr)*cos(theta)*cos(omega*theta)/sin(theta)/epsilon -omega*mu_z*cos(expr)*cos(omega*theta)/sin(theta)/expr,\
				       -epsilon_z*cos(expr)*cos(theta)*sin(omega*theta)/sin(theta)/epsilon*expr + omega*epsilon_z*cos(expr)*sin(omega*theta)/sin(theta)/expr,\
				        exp(theta), (theta, 0.1, 3)),\
#				       (-omega*mu_z*exp(expr)*cos(omega*theta)/sin(theta)/expr,\
#				       omega*epsilon_z*exp(expr)*sin(omega*theta)/sin(theta)/expr,\
#				        exp(expr), (theta, 0.1, 3)),\
#				        (-omega*mu_z*cos(theta)/sin(theta)**2 /expr,\
#				        omega*epsilon_z*cos(theta)/sin(theta)**2 *cos(omega*theta+pi/2)**2 * expr,\
#				        theta, (theta, 0.1, 20)),\
				        show=False)
param_line_3d[0].line_color = lambda u: u  # parametric
#param_line_3d[1].line_color = lambda u, v: u*v  # first and second coordinates
#param_line_3d[2].line_color = lambda u, v, w: u*v*w  # all coordinates


if __name__ == '__main__':
    for p in [param_line_3d]:
        p.show()


Beispiel #21
0
def plot_and_save(name):
    tmp_file = TmpFileManager.tmp_file

    x = Symbol('x')
    y = Symbol('y')
    z = Symbol('z')

    ###
    # Examples from the 'introduction' notebook
    ###

    p = plot(x)
    p = plot(x*sin(x), x*cos(x))
    p.extend(p)
    p[0].line_color = lambda a: a
    p[1].line_color = 'b'
    p.title = 'Big title'
    p.xlabel = 'the x axis'
    p[1].label = 'straight line'
    p.legend = True
    p.aspect_ratio = (1, 1)
    p.xlim = (-15, 20)
    p.save(tmp_file('%s_basic_options_and_colors' % name))
    p._backend.close()

    p.extend(plot(x + 1))
    p.append(plot(x + 3, x**2)[1])
    p.save(tmp_file('%s_plot_extend_append' % name))

    p[2] = plot(x**2, (x, -2, 3))
    p.save(tmp_file('%s_plot_setitem' % name))
    p._backend.close()

    p = plot(sin(x), (x, -2*pi, 4*pi))
    p.save(tmp_file('%s_line_explicit' % name))
    p._backend.close()

    p = plot(sin(x))
    p.save(tmp_file('%s_line_default_range' % name))
    p._backend.close()

    p = plot((x**2, (x, -5, 5)), (x**3, (x, -3, 3)))
    p.save(tmp_file('%s_line_multiple_range' % name))
    p._backend.close()

    raises(ValueError, lambda: plot(x, y))

    #Piecewise plots
    p = plot(Piecewise((1, x > 0), (0, True)), (x, -1, 1))
    p.save(tmp_file('%s_plot_piecewise' % name))
    p._backend.close()

    p = plot(Piecewise((x, x < 1), (x**2, True)), (x, -3, 3))
    p.save(tmp_file('%s_plot_piecewise_2' % name))
    p._backend.close()

    # test issue 7471
    p1 = plot(x)
    p2 = plot(3)
    p1.extend(p2)
    p.save(tmp_file('%s_horizontal_line' % name))
    p._backend.close()

    # test issue 10925
    f = Piecewise((-1, x < -1), (x, And(-1 <= x, x < 0)), \
        (x**2, And(0 <= x, x < 1)), (x**3, x >= 1))
    p = plot(f, (x, -3, 3))
    p.save(tmp_file('%s_plot_piecewise_3' % name))
    p._backend.close()

    #parametric 2d plots.
    #Single plot with default range.
    plot_parametric(sin(x), cos(x)).save(tmp_file())

    #Single plot with range.
    p = plot_parametric(sin(x), cos(x), (x, -5, 5))
    p.save(tmp_file('%s_parametric_range' % name))
    p._backend.close()

    #Multiple plots with same range.
    p = plot_parametric((sin(x), cos(x)), (x, sin(x)))
    p.save(tmp_file('%s_parametric_multiple' % name))
    p._backend.close()

    #Multiple plots with different ranges.
    p = plot_parametric((sin(x), cos(x), (x, -3, 3)), (x, sin(x), (x, -5, 5)))
    p.save(tmp_file('%s_parametric_multiple_ranges' % name))
    p._backend.close()

    #depth of recursion specified.
    p = plot_parametric(x, sin(x), depth=13)
    p.save(tmp_file('%s_recursion_depth' % name))
    p._backend.close()

    #No adaptive sampling.
    p = plot_parametric(cos(x), sin(x), adaptive=False, nb_of_points=500)
    p.save(tmp_file('%s_adaptive' % name))
    p._backend.close()

    #3d parametric plots
    p = plot3d_parametric_line(sin(x), cos(x), x)
    p.save(tmp_file('%s_3d_line' % name))
    p._backend.close()

    p = plot3d_parametric_line(
        (sin(x), cos(x), x, (x, -5, 5)), (cos(x), sin(x), x, (x, -3, 3)))
    p.save(tmp_file('%s_3d_line_multiple' % name))
    p._backend.close()

    p = plot3d_parametric_line(sin(x), cos(x), x, nb_of_points=30)
    p.save(tmp_file('%s_3d_line_points' % name))
    p._backend.close()

    # 3d surface single plot.
    p = plot3d(x * y)
    p.save(tmp_file('%s_surface' % name))
    p._backend.close()

    # Multiple 3D plots with same range.
    p = plot3d(-x * y, x * y, (x, -5, 5))
    p.save(tmp_file('%s_surface_multiple' % name))
    p._backend.close()

    # Multiple 3D plots with different ranges.
    p = plot3d(
        (x * y, (x, -3, 3), (y, -3, 3)), (-x * y, (x, -3, 3), (y, -3, 3)))
    p.save(tmp_file('%s_surface_multiple_ranges' % name))
    p._backend.close()

    # Single Parametric 3D plot
    p = plot3d_parametric_surface(sin(x + y), cos(x - y), x - y)
    p.save(tmp_file('%s_parametric_surface' % name))
    p._backend.close()

    # Multiple Parametric 3D plots.
    p = plot3d_parametric_surface(
        (x*sin(z), x*cos(z), z, (x, -5, 5), (z, -5, 5)),
        (sin(x + y), cos(x - y), x - y, (x, -5, 5), (y, -5, 5)))
    p.save(tmp_file('%s_parametric_surface' % name))
    p._backend.close()

    ###
    # Examples from the 'colors' notebook
    ###

    p = plot(sin(x))
    p[0].line_color = lambda a: a
    p.save(tmp_file('%s_colors_line_arity1' % name))

    p[0].line_color = lambda a, b: b
    p.save(tmp_file('%s_colors_line_arity2' % name))
    p._backend.close()

    p = plot(x*sin(x), x*cos(x), (x, 0, 10))
    p[0].line_color = lambda a: a
    p.save(tmp_file('%s_colors_param_line_arity1' % name))

    p[0].line_color = lambda a, b: a
    p.save(tmp_file('%s_colors_param_line_arity2a' % name))

    p[0].line_color = lambda a, b: b
    p.save(tmp_file('%s_colors_param_line_arity2b' % name))
    p._backend.close()

    p = plot3d_parametric_line(sin(x) + 0.1*sin(x)*cos(7*x),
             cos(x) + 0.1*cos(x)*cos(7*x),
        0.1*sin(7*x),
        (x, 0, 2*pi))
    p[0].line_color = lambdify_(x, sin(4*x))
    p.save(tmp_file('%s_colors_3d_line_arity1' % name))
    p[0].line_color = lambda a, b: b
    p.save(tmp_file('%s_colors_3d_line_arity2' % name))
    p[0].line_color = lambda a, b, c: c
    p.save(tmp_file('%s_colors_3d_line_arity3' % name))
    p._backend.close()

    p = plot3d(sin(x)*y, (x, 0, 6*pi), (y, -5, 5))
    p[0].surface_color = lambda a: a
    p.save(tmp_file('%s_colors_surface_arity1' % name))
    p[0].surface_color = lambda a, b: b
    p.save(tmp_file('%s_colors_surface_arity2' % name))
    p[0].surface_color = lambda a, b, c: c
    p.save(tmp_file('%s_colors_surface_arity3a' % name))
    p[0].surface_color = lambdify_((x, y, z), sqrt((x - 3*pi)**2 + y**2))
    p.save(tmp_file('%s_colors_surface_arity3b' % name))
    p._backend.close()

    p = plot3d_parametric_surface(x * cos(4 * y), x * sin(4 * y), y,
             (x, -1, 1), (y, -1, 1))
    p[0].surface_color = lambda a: a
    p.save(tmp_file('%s_colors_param_surf_arity1' % name))
    p[0].surface_color = lambda a, b: a*b
    p.save(tmp_file('%s_colors_param_surf_arity2' % name))
    p[0].surface_color = lambdify_((x, y, z), sqrt(x**2 + y**2 + z**2))
    p.save(tmp_file('%s_colors_param_surf_arity3' % name))
    p._backend.close()

    ###
    # Examples from the 'advanced' notebook
    ###

    # XXX: This raises the warning "The evaluation of the expression is
    # problematic. We are trying a failback method that may still work. Please
    # report this as a bug." It has to use the fallback because using evalf()
    # is the only way to evaluate the integral. We should perhaps just remove
    # that warning.

    with warnings.catch_warnings(record=True) as w:
        i = Integral(log((sin(x)**2 + 1)*sqrt(x**2 + 1)), (x, 0, y))
        p = plot(i, (y, 1, 5))
        p.save(tmp_file('%s_advanced_integral' % name))
        p._backend.close()
        # Make sure no other warnings were raised
        for i in w:
            assert issubclass(i.category, UserWarning)
            assert "The evaluation of the expression is problematic" in str(i.message)

    s = Sum(1/x**y, (x, 1, oo))
    p = plot(s, (y, 2, 10))
    p.save(tmp_file('%s_advanced_inf_sum' % name))
    p._backend.close()

    p = plot(Sum(1/x, (x, 1, y)), (y, 2, 10), show=False)
    p[0].only_integers = True
    p[0].steps = True
    p.save(tmp_file('%s_advanced_fin_sum' % name))
    p._backend.close()

    ###
    # Test expressions that can not be translated to np and generate complex
    # results.
    ###
    plot(sin(x) + I*cos(x)).save(tmp_file())
    plot(sqrt(sqrt(-x))).save(tmp_file())
    plot(LambertW(x)).save(tmp_file())
    plot(sqrt(LambertW(x))).save(tmp_file())

    #Characteristic function of a StudentT distribution with nu=10
    plot((meijerg(((1 / 2,), ()), ((5, 0, 1 / 2), ()), 5 * x**2 * exp_polar(-I*pi)/2)
            + meijerg(((1/2,), ()), ((5, 0, 1/2), ()),
                5*x**2 * exp_polar(I*pi)/2)) / (48 * pi), (x, 1e-6, 1e-2)).save(tmp_file())
Beispiel #22
0
def plot_and_save(name):
    tmp_file = TmpFileManager.tmp_file

    x = Symbol('x')
    y = Symbol('y')
    z = Symbol('z')

    ###
    # Examples from the 'introduction' notebook
    ###

    p = plot(x)
    p = plot(x * sin(x), x * cos(x))
    p.extend(p)
    p[0].line_color = lambda a: a
    p[1].line_color = 'b'
    p.title = 'Big title'
    p.xlabel = 'the x axis'
    p[1].label = 'straight line'
    p.legend = True
    p.aspect_ratio = (1, 1)
    p.xlim = (-15, 20)
    p.save(tmp_file('%s_basic_options_and_colors' % name))
    p._backend.close()

    p.extend(plot(x + 1))
    p.append(plot(x + 3, x**2)[1])
    p.save(tmp_file('%s_plot_extend_append' % name))

    p[2] = plot(x**2, (x, -2, 3))
    p.save(tmp_file('%s_plot_setitem' % name))
    p._backend.close()

    p = plot(sin(x), (x, -2 * pi, 4 * pi))
    p.save(tmp_file('%s_line_explicit' % name))
    p._backend.close()

    p = plot(sin(x))
    p.save(tmp_file('%s_line_default_range' % name))
    p._backend.close()

    p = plot((x**2, (x, -5, 5)), (x**3, (x, -3, 3)))
    p.save(tmp_file('%s_line_multiple_range' % name))
    p._backend.close()

    raises(ValueError, lambda: plot(x, y))

    #Piecewise plots
    p = plot(Piecewise((1, x > 0), (0, True)), (x, -1, 1))
    p.save(tmp_file('%s_plot_piecewise' % name))
    p._backend.close()

    p = plot(Piecewise((x, x < 1), (x**2, True)), (x, -3, 3))
    p.save(tmp_file('%s_plot_piecewise_2' % name))
    p._backend.close()

    # test issue 7471
    p1 = plot(x)
    p2 = plot(3)
    p1.extend(p2)
    p.save(tmp_file('%s_horizontal_line' % name))
    p._backend.close()

    # test issue 10925
    f = Piecewise((-1, x < -1), (x, And(-1 <= x, x < 0)), \
        (x**2, And(0 <= x, x < 1)), (x**3, x >= 1))
    p = plot(f, (x, -3, 3))
    p.save(tmp_file('%s_plot_piecewise_3' % name))
    p._backend.close()

    #parametric 2d plots.
    #Single plot with default range.
    plot_parametric(sin(x), cos(x)).save(tmp_file())

    #Single plot with range.
    p = plot_parametric(sin(x), cos(x), (x, -5, 5))
    p.save(tmp_file('%s_parametric_range' % name))
    p._backend.close()

    #Multiple plots with same range.
    p = plot_parametric((sin(x), cos(x)), (x, sin(x)))
    p.save(tmp_file('%s_parametric_multiple' % name))
    p._backend.close()

    #Multiple plots with different ranges.
    p = plot_parametric((sin(x), cos(x), (x, -3, 3)), (x, sin(x), (x, -5, 5)))
    p.save(tmp_file('%s_parametric_multiple_ranges' % name))
    p._backend.close()

    #depth of recursion specified.
    p = plot_parametric(x, sin(x), depth=13)
    p.save(tmp_file('%s_recursion_depth' % name))
    p._backend.close()

    #No adaptive sampling.
    p = plot_parametric(cos(x), sin(x), adaptive=False, nb_of_points=500)
    p.save(tmp_file('%s_adaptive' % name))
    p._backend.close()

    #3d parametric plots
    p = plot3d_parametric_line(sin(x), cos(x), x)
    p.save(tmp_file('%s_3d_line' % name))
    p._backend.close()

    p = plot3d_parametric_line((sin(x), cos(x), x, (x, -5, 5)),
                               (cos(x), sin(x), x, (x, -3, 3)))
    p.save(tmp_file('%s_3d_line_multiple' % name))
    p._backend.close()

    p = plot3d_parametric_line(sin(x), cos(x), x, nb_of_points=30)
    p.save(tmp_file('%s_3d_line_points' % name))
    p._backend.close()

    # 3d surface single plot.
    p = plot3d(x * y)
    p.save(tmp_file('%s_surface' % name))
    p._backend.close()

    # Multiple 3D plots with same range.
    p = plot3d(-x * y, x * y, (x, -5, 5))
    p.save(tmp_file('%s_surface_multiple' % name))
    p._backend.close()

    # Multiple 3D plots with different ranges.
    p = plot3d((x * y, (x, -3, 3), (y, -3, 3)),
               (-x * y, (x, -3, 3), (y, -3, 3)))
    p.save(tmp_file('%s_surface_multiple_ranges' % name))
    p._backend.close()

    # Single Parametric 3D plot
    p = plot3d_parametric_surface(sin(x + y), cos(x - y), x - y)
    p.save(tmp_file('%s_parametric_surface' % name))
    p._backend.close()

    # Multiple Parametric 3D plots.
    p = plot3d_parametric_surface(
        (x * sin(z), x * cos(z), z, (x, -5, 5), (z, -5, 5)),
        (sin(x + y), cos(x - y), x - y, (x, -5, 5), (y, -5, 5)))
    p.save(tmp_file('%s_parametric_surface' % name))
    p._backend.close()

    ###
    # Examples from the 'colors' notebook
    ###

    p = plot(sin(x))
    p[0].line_color = lambda a: a
    p.save(tmp_file('%s_colors_line_arity1' % name))

    p[0].line_color = lambda a, b: b
    p.save(tmp_file('%s_colors_line_arity2' % name))
    p._backend.close()

    p = plot(x * sin(x), x * cos(x), (x, 0, 10))
    p[0].line_color = lambda a: a
    p.save(tmp_file('%s_colors_param_line_arity1' % name))

    p[0].line_color = lambda a, b: a
    p.save(tmp_file('%s_colors_param_line_arity2a' % name))

    p[0].line_color = lambda a, b: b
    p.save(tmp_file('%s_colors_param_line_arity2b' % name))
    p._backend.close()

    p = plot3d_parametric_line(
        sin(x) + 0.1 * sin(x) * cos(7 * x),
        cos(x) + 0.1 * cos(x) * cos(7 * x), 0.1 * sin(7 * x), (x, 0, 2 * pi))
    p[0].line_color = lambdify_(x, sin(4 * x))
    p.save(tmp_file('%s_colors_3d_line_arity1' % name))
    p[0].line_color = lambda a, b: b
    p.save(tmp_file('%s_colors_3d_line_arity2' % name))
    p[0].line_color = lambda a, b, c: c
    p.save(tmp_file('%s_colors_3d_line_arity3' % name))
    p._backend.close()

    p = plot3d(sin(x) * y, (x, 0, 6 * pi), (y, -5, 5))
    p[0].surface_color = lambda a: a
    p.save(tmp_file('%s_colors_surface_arity1' % name))
    p[0].surface_color = lambda a, b: b
    p.save(tmp_file('%s_colors_surface_arity2' % name))
    p[0].surface_color = lambda a, b, c: c
    p.save(tmp_file('%s_colors_surface_arity3a' % name))
    p[0].surface_color = lambdify_((x, y, z), sqrt((x - 3 * pi)**2 + y**2))
    p.save(tmp_file('%s_colors_surface_arity3b' % name))
    p._backend.close()

    p = plot3d_parametric_surface(x * cos(4 * y), x * sin(4 * y), y,
                                  (x, -1, 1), (y, -1, 1))
    p[0].surface_color = lambda a: a
    p.save(tmp_file('%s_colors_param_surf_arity1' % name))
    p[0].surface_color = lambda a, b: a * b
    p.save(tmp_file('%s_colors_param_surf_arity2' % name))
    p[0].surface_color = lambdify_((x, y, z), sqrt(x**2 + y**2 + z**2))
    p.save(tmp_file('%s_colors_param_surf_arity3' % name))
    p._backend.close()

    ###
    # Examples from the 'advanced' notebook
    ###

    # XXX: This raises the warning "The evaluation of the expression is
    # problematic. We are trying a failback method that may still work. Please
    # report this as a bug." It has to use the fallback because using evalf()
    # is the only way to evaluate the integral. We should perhaps just remove
    # that warning.

    with warnings.catch_warnings(record=True) as w:
        i = Integral(log((sin(x)**2 + 1) * sqrt(x**2 + 1)), (x, 0, y))
        p = plot(i, (y, 1, 5))
        p.save(tmp_file('%s_advanced_integral' % name))
        p._backend.close()
        # Make sure no other warnings were raised
        for i in w:
            assert issubclass(i.category, UserWarning)
            assert "The evaluation of the expression is problematic" in str(
                i.message)

    s = Sum(1 / x**y, (x, 1, oo))
    p = plot(s, (y, 2, 10))
    p.save(tmp_file('%s_advanced_inf_sum' % name))
    p._backend.close()

    p = plot(Sum(1 / x, (x, 1, y)), (y, 2, 10), show=False)
    p[0].only_integers = True
    p[0].steps = True
    p.save(tmp_file('%s_advanced_fin_sum' % name))
    p._backend.close()

    ###
    # Test expressions that can not be translated to np and generate complex
    # results.
    ###
    plot(sin(x) + I * cos(x)).save(tmp_file())
    plot(sqrt(sqrt(-x))).save(tmp_file())
    plot(LambertW(x)).save(tmp_file())
    plot(sqrt(LambertW(x))).save(tmp_file())

    #Characteristic function of a StudentT distribution with nu=10
    plot((meijerg(
        ((1 / 2, ), ()),
        ((5, 0, 1 / 2), ()), 5 * x**2 * exp_polar(-I * pi) / 2) + meijerg(
            ((1 / 2, ), ()),
            ((5, 0, 1 / 2),
             ()), 5 * x**2 * exp_polar(I * pi) / 2)) / (48 * pi),
         (x, 1e-6, 1e-2)).save(tmp_file())