# Changeset 7889:3670aecb098e

Ignore:
Timestamp:
12/23/07 23:34:29 (5 years ago)
Branch:
default
Message:

Add 3d parametric plots (implemented currently in terms of line segments); lots of other misc touch up.

Location:
sage/plot
Files:
4 edited

Unmodified
Added
Removed
• ## sage/plot/plot.py

 r7888 plot(X, ...) where X is a SAGE object that either is callable and returns numbers that can be coerced to floats, or has a plot method that returns a GraphicPrimitive object. where X is a Sage object (or list of Sage objects) that either is callable and returns numbers that can be coerced to floats, or has a plot method that returns a GraphicPrimitive object. Type plot.options for a dictionary of the default sage: P.show()   # render We plot several functions together by passing a list of functions as input: sage: show(plot([sin(n*x) for n in [1..4]], 0, pi)) The function $\sin(1/x)$ wiggles wildtly near $0$, so the first plot below won't look perfect.  Sage adapts to this and plots extra points near the origin. sage: show(plot(sin(1/x), -1, 1)) The \code{plot_points} option, you can increase the number of sample points, to obtain a more accurate plot. sage: show(plot(sin(1/x), -1, 1, plot_points=1000)) The actual sample points are slightly randomized, so the above plots may look slightly different each time you draw them. Use \code{show(plot(sin, 0,10))} or \code{plot(sin,0,10).show()} to show the corresponding graphics object. We draw the graph of an elliptic curve as the union of graphs of 2 functions. #and will plotted as (f(x), g(x)) for all x in the given range if parametric: f,g = funcs if len(funcs) == 3: # 3d from plot3d.shapes import parametric_plot_3d return parametric_plot_3d(funcs, xmin, xmax, polar=polar, label=label, show=show, **kwds) elif len(funcs) == 2: # 2d f,g = funcs else: raise ValueError, "parametric plots only implemented in 2 and 3 dimensions." #or we have only a single function to be plotted: else: ########## misc functions ################### def parametric_plot((f,g), tmin, tmax, show=None, **kwargs): def parametric_plot(funcs, tmin, tmax, show=None, **kwargs): """ parametric_plot takes two functions as a list or a tuple and make INPUT: (f,g) -- tuple of functions funcs -- 2 or 3-tuple of functions tmin -- start value of t tmax -- end value of t EXAMPLE: We draw a 2d parametric plot: sage: t = var('t') sage: G = parametric_plot( (sin(t), sin(2*t)), 0, 2*pi, rgbcolor=hue(0.6) ) sage: G.show() We draw a 3d parametric plot: sage: show(parametric_plot( (5*cos(x), 5*sin(x), x), -12, 12, plot_points=150, color="red")) """ if show is None: show = SHOW_DEFAULT return plot((f,g), tmin, tmax, parametric=True, show=show, **kwargs) return plot(funcs, tmin, tmax, parametric=True, show=show, **kwargs) def polar_plot(funcs, xmin, xmax, show=None, **kwargs):
• ## sage/plot/plot3d/base.pyx

 r7866 import sage.misc.viewer viewer_app = sage.misc.viewer.browser() if DOCTEST_MODE or viewer=='java3d': f = open(filename+".obj", "w") if ext is None: raise ValueError, "Unknown 3d plot type: %s" % viewer if not DOCTEST_MODE and not EMBEDDED_MODE: if verbosity:
• ## sage/plot/plot3d/index_face_set.pyx

 r7866 """ def __new__(self, faces, point_list=None, enclosde=False, **kwds): def __new__(self, faces, point_list=None, enclosed=False, **kwds): self.vs = NULL self.face_indices = NULL
• ## sage/plot/plot3d/shapes.pyx

 r7865 from sage.modules.free_module_element import vector from base import Graphics3dGroup from sage.misc.all import srange from base import Graphics3dGroup, Graphics3d class Box(IndexFaceSet): """ EXAMPLES: A square black box: sage: show(Box([1,1,1])) A red rectangular box. sage: show(Box([2,3,4], color="red")) A stack of boxes: sage: show(sum([Box([2,3,1], color="red").translate((0,0,6*i)) for i in [0..3]])) A sinusoidal stack of multicolored boxes: sage: B = sum([Box([2,4,1/4], color=(i/4,i/5,1)).translate((sin(i),0,5-i)) for i in [0..20]]) sage: show(B, figsize=6) """ def __init__(self, *size, **kwds): def parametric_plot_3d(funcs, tmin, tmax, plot_points=50, show=None, thickness=0.2, polar=False, **kwargs): if polar: raise NotImplementedError, "3d parametric polar plots not implemented" f,g,h = funcs # normalize number of points to an integer plot_points = int(plot_points) if plot_points <= 1: plot_points = 1 v = srange(tmin, tmax, (tmax-tmin)/plot_points, include_endpoint=True) t0 = v[0] P =  (f(t0), g(t0), h(t0)) G = 0 for i in range(1, len(v)): t1 = v[i] Q = (f(t1), g(t1), h(t1)) G += LineSegment(P, Q, **kwargs) P = Q if show: G.show(**kwargs) return G
Note: See TracChangeset for help on using the changeset viewer.