Many of the example of this section are taken from Sage Documentation : http://sagemath.org/doc
The following plotting functions are supported:
- plot() - plot of a function or other Sage object (e.g., elliptic curve).
- parametric_plot()
- implicit_plot()
- polar_plot()
- region_plot()
- list_plot()
- scatter_plot()
- bar_chart()
- contour_plot()
- density_plot()
- plot_vector_field()
- plot_slope_field()
- matrix_plot()
- complex_plot()
- graphics_array()
Dessiner une fonction $\mathbb{R}\mapsto \mathbb{R}$ : la commande plot:
sage: x,y = var('x y') sage: plot_vector_field((sin(x), cos(y)), (x,-3,3), (y,-3,3))
sage: f(x) = x^4 - 1 sage: complex_plot(f, (-2,2), (-2,2))
The following graphics primitives are supported:
- arrow() - an arrow from a min point to a max point.
- circle() - a circle with given radius
- ellipse() - an ellipse with given rad and angle
- arc() - an arc of a circle or an ellipse
- disk() - a filled disk (i.e. a sector or wedge of a circle)
- line() - a line determined by a sequence of points (this need not be straight!)
- point() - a point
- text() - some text
- polygon() - a filled polygon
sage: f = sin(1/x) sage: P = plot(f, -10, 10, color='red') sage: P
sage: Q = line([(3,0.9), (7,0.9), (7,1.1), (3,1.1), (3,0.9)], color='green') sage: Q
sage: R = text('$f(x) = \\sin(\\frac{1}{x})$', (5,1)) sage: R
sage: P + Q + R
For more examples on 2D ploting, visit: http://sagemath.org/doc/reference/plotting.html
Dessiner une fonction $\mathbb{R}^2\mapsto \mathbb{R}$ : la commande plot3d:
sage: def f(x, y): return x^2 + y^2 sage: plot3d(f, (-10,10), (-10,10), viewer='tachyon')
the same with Jmol:
sage: plot3d(f, (-10,10), (-10,10))
A hyperboloid:
sage: x, y, z = var('x, y, z') sage: implicit_plot3d(x^2 + y^2 - z^2 -0.3, (x, -2, 2), (y, -2, 2), (z, -1.8, 1.8))
A torus:
sage: implicit_plot3d((sqrt(x*x+y*y)-3)^2 + z*z - 1, (x, -4, 4), (y, -4, 4), (z, -1, 1))
Two spheres touching:
sage: sphere(center=(-1,0,0)) + sphere(center=(1,0,0), aspect_ratio=[1,1,1])
A transparent thick green line and a little blue line:
sage: A = line3d([(0,0,0), (1,1,1), (1,0,2)], opacity=0.5, radius=0.1, color='green') sage: B = line3d([(0,1,0), (1,0,2)]) sage: A + B
sage: from sage.plot.plot3d.shapes2 import ruler sage: R = ruler([1,2,3],vector([2,3,4]),ticks=6, sub_ticks=2, color='red'); R
For more examples on 3D ploting, visit: http://sagemath.org/doc/reference/plot3d.html
(The following is not in Sage currently but could be soon if there is an interest).
sage: load /Users/slabbe/Documents/Projets/laber/discrete_object.sage
sage: P = Plan([1,3,7]) sage: P Plan discret de vecteur normal v=(1, 3, 7), d'épaisseur omega=11 et d'intercept h=0. Bounding Box: ((0, 0, 0), (11, 11, 11))
sage: P.list() [(0, 0, 1), (0, 1, 0), (0, 1, 1), (0, 2, 0), (0, 3, 0), (1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1), (1, 2, 0), (1, 3, 0), (2, 0, 0), (2, 0, 1), (2, 1, 0), (2, 2, 0), (2, 3, 0), (3, 0, 0), (3, 0, 1), (3, 1, 0), (3, 2, 0), (4, 0, 0), (4, 0, 1), (4, 1, 0), (4, 2, 0), (5, 0, 0), (5, 1, 0), (5, 2, 0), (6, 0, 0), (6, 1, 0), (7, 0, 0), (7, 1, 0), (8, 0, 0), (8, 1, 0), (9, 0, 0), (10, 0, 0)]
sage: P.show3d()
sage: P = Plan([1,3,5], omega=7, h=20) sage: P.show3d()
Discrete 3d lines defined by cylinder offset:
sage: d = DroiteDiscrete3d_cylinder_offset((1,2,4), offset=1) sage: d.bounding_box(((0,0,0),(6,6,6))) sage: d Droite 3d defined by cylinder offset=1 and direction v=(1, 2, 4). Bounding Box: ((0, 0, 0), (6, 6, 6))
sage: d.show3d()
sage: d.tikz()
Reveillès Discrete 3d lines:
sage: d = DroiteDiscrete3d_reveilles((12,13,19)) sage: d Droite 3d de Reveilles v=(12, 13, 19). Bounding Box: [(0, 0, 0), (20, 20, 20)]
sage: (0,0,0) in d True
sage: d.show3d()
Let's now compare the Reveillès and Toutant 3D discrete lines:
sage: d = DroiteDiscrete3d_reveilles((10,20,29)) sage: t = DroiteDiscrete3d_toutant((10,20,29)) sage: d == t True
The following example shows that Reveillès and Toutant are different for the vector (1,2,4) and that Toutant points are nearer from the line:
sage: d = DroiteDiscrete3d_reveilles((1,2,4)) sage: t = DroiteDiscrete3d_toutant((1,2,4)) sage: d == t False sage: d.list() [(0, 0, 0), (0, 1, 1), (0, 1, 2), (1, 2, 3), (1, 2, 4)] sage: t.list() [(0, 0, 0), (0, 0, 1), (0, 1, 2), (1, 2, 3), (1, 2, 4)] sage: d.distance((0,1,1)) sqrt(2/7) sage: d.distance((0,0,1)) sqrt(5/21)
Intersection of two planes:
sage: p = Plan([1,-3,7],h=20) sage: q = Plan([3,3,-5],h=14) sage: i = p.intersection(q) sage: i Intersection des objets suivants : Plan discret de vecteur normal v=(1, 3, 7), d'épaisseur omega=11 et d'intercept h=20. Bounding Box: ((0, 0, 0), (31, 31, 31)) Plan discret de vecteur normal v=(3, 3, 5), d'épaisseur omega=11 et d'intercept h=14. Bounding Box: ((0, 0, 0), (25, 25, 25)) Bounding Box: ((0, 0, 0), (25, 25, 25))
sage: i.bounding_box(((-25,-25,-25),(25,25,25)))
sage: i.show3d()
(This is will be in version 4.7 of Sage.)
The Rauzy fractal:
sage: s = WordMorphism('1->12,2->13,3->1') sage: D = s.fixed_point('1') sage: v = s.pisot_eigenvector_right() sage: P = WordPaths('123',[(1,0,0),(0,1,0),(0,0,1)]) sage: w = P(D[:200]) sage: w.plot_projection(v) # optional long time (2 s)
The 3d-Rauzy fractal:
sage: s = WordMorphism('1->12,2->13,3->14,4->1') sage: D = s.fixed_point('1') sage: v = s.pisot_eigenvector_right() sage: P = WordPaths('1234',[(1,0,0,0), (0,1,0,0), (0,0,1,0), (0,0,0,1)]) sage: w = P(D[:200]) sage: w.plot_projection(v) # optional long time (1 s)
(This is in Sage since version 4.6.1.)
sage: from sage.combinat.e_one_star import E1Star, Patch, Face sage: sigma = WordMorphism({1:[1,2], 2:[1,3], 3:[1]}) sage: E = E1Star(sigma) sage: P = Patch([Face((0,0,0),t) for t in [1,2,3]]) sage: P.plot()
sage: image = E(P, iterations=12) sage: image.plot()
sage: image.plot3d()