Changeset 7889:3670aecb098e
- Timestamp:
- 12/23/07 23:34:29 (5 years ago)
- Branch:
- default
- Location:
- sage/plot
- Files:
-
- 4 edited
-
plot.py (modified) (6 diffs)
-
plot3d/base.pyx (modified) (2 diffs)
-
plot3d/index_face_set.pyx (modified) (1 diff)
-
plot3d/shapes.pyx (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/plot/plot.py
r7888 r7889 2283 2283 plot(X, ...) 2284 2284 2285 where X is a S AGE object that either is callable and returns2286 numbers that can be coerced to floats, or has a plot method2287 that returns a GraphicPrimitive object.2285 where X is a Sage object (or list of Sage objects) that either is 2286 callable and returns numbers that can be coerced to floats, or has 2287 a plot method that returns a GraphicPrimitive object. 2288 2288 2289 2289 Type plot.options for a dictionary of the default … … 2352 2352 sage: P.show() # render 2353 2353 2354 We plot several functions together by passing a list 2355 of functions as input: 2356 sage: show(plot([sin(n*x) for n in [1..4]], 0, pi)) 2357 2358 2359 The function $\sin(1/x)$ wiggles wildtly near $0$, so the 2360 first plot below won't look perfect. Sage adapts to this 2361 and plots extra points near the origin. 2362 sage: show(plot(sin(1/x), -1, 1)) 2363 2364 The \code{plot_points} option, you can increase the number 2365 of sample points, to obtain a more accurate plot. 2366 sage: show(plot(sin(1/x), -1, 1, plot_points=1000)) 2367 2368 The actual sample points are slightly randomized, so the above 2369 plots may look slightly different each time you draw them. 2370 2354 2371 Use \code{show(plot(sin, 0,10))} or \code{plot(sin,0,10).show()} 2355 2372 to show the corresponding graphics object. 2356 2373 2357 2374 We draw the graph of an elliptic curve as the union 2358 2375 of graphs of 2 functions. … … 2419 2436 #and will plotted as (f(x), g(x)) for all x in the given range 2420 2437 if parametric: 2421 f,g = funcs 2438 if len(funcs) == 3: 2439 # 3d 2440 from plot3d.shapes import parametric_plot_3d 2441 return parametric_plot_3d(funcs, xmin, xmax, polar=polar, label=label, show=show, **kwds) 2442 elif len(funcs) == 2: 2443 # 2d 2444 f,g = funcs 2445 else: 2446 raise ValueError, "parametric plots only implemented in 2 and 3 dimensions." 2447 2422 2448 #or we have only a single function to be plotted: 2423 2449 else: … … 2542 2568 ########## misc functions ################### 2543 2569 2544 def parametric_plot( (f,g), tmin, tmax, show=None, **kwargs):2570 def parametric_plot(funcs, tmin, tmax, show=None, **kwargs): 2545 2571 """ 2546 2572 parametric_plot takes two functions as a list or a tuple and make … … 2549 2575 2550 2576 INPUT: 2551 (f,g) --tuple of functions2577 funcs -- 2 or 3-tuple of functions 2552 2578 tmin -- start value of t 2553 2579 tmax -- end value of t … … 2558 2584 2559 2585 EXAMPLE: 2586 We draw a 2d parametric plot: 2560 2587 sage: t = var('t') 2561 2588 sage: G = parametric_plot( (sin(t), sin(2*t)), 0, 2*pi, rgbcolor=hue(0.6) ) 2562 2589 sage: G.show() 2590 2591 We draw a 3d parametric plot: 2592 sage: show(parametric_plot( (5*cos(x), 5*sin(x), x), -12, 12, plot_points=150, color="red")) 2563 2593 """ 2564 2594 if show is None: 2565 2595 show = SHOW_DEFAULT 2566 return plot( (f,g), tmin, tmax, parametric=True, show=show, **kwargs)2596 return plot(funcs, tmin, tmax, parametric=True, show=show, **kwargs) 2567 2597 2568 2598 def polar_plot(funcs, xmin, xmax, show=None, **kwargs): -
sage/plot/plot3d/base.pyx
r7866 r7889 243 243 import sage.misc.viewer 244 244 viewer_app = sage.misc.viewer.browser() 245 245 246 if DOCTEST_MODE or viewer=='java3d': 246 247 f = open(filename+".obj", "w") … … 264 265 if ext is None: 265 266 raise ValueError, "Unknown 3d plot type: %s" % viewer 267 266 268 if not DOCTEST_MODE and not EMBEDDED_MODE: 267 269 if verbosity: -
sage/plot/plot3d/index_face_set.pyx
r7866 r7889 178 178 """ 179 179 180 def __new__(self, faces, point_list=None, enclos de=False, **kwds):180 def __new__(self, faces, point_list=None, enclosed=False, **kwds): 181 181 self.vs = <point_c *>NULL 182 182 self.face_indices = <int *>NULL -
sage/plot/plot3d/shapes.pyx
r7865 r7889 50 50 from sage.modules.free_module_element import vector 51 51 52 from base import Graphics3dGroup 52 from sage.misc.all import srange 53 54 from base import Graphics3dGroup, Graphics3d 53 55 54 56 55 57 class Box(IndexFaceSet): 58 """ 59 60 EXAMPLES: 61 A square black box: 62 sage: show(Box([1,1,1])) 63 64 A red rectangular box. 65 sage: show(Box([2,3,4], color="red")) 66 67 A stack of boxes: 68 sage: show(sum([Box([2,3,1], color="red").translate((0,0,6*i)) for i in [0..3]])) 69 70 A sinusoidal stack of multicolored boxes: 71 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]]) 72 sage: show(B, figsize=6) 73 """ 56 74 57 75 def __init__(self, *size, **kwds): … … 334 352 335 353 354 def parametric_plot_3d(funcs, tmin, tmax, plot_points=50, show=None, thickness=0.2, polar=False, **kwargs): 355 356 if polar: 357 raise NotImplementedError, "3d parametric polar plots not implemented" 358 359 f,g,h = funcs 360 361 # normalize number of points to an integer 362 plot_points = int(plot_points) 363 if plot_points <= 1: 364 plot_points = 1 365 366 367 v = srange(tmin, tmax, (tmax-tmin)/plot_points, include_endpoint=True) 368 t0 = v[0] 369 P = (f(t0), g(t0), h(t0)) 370 G = 0 371 for i in range(1, len(v)): 372 t1 = v[i] 373 Q = (f(t1), g(t1), h(t1)) 374 G += LineSegment(P, Q, **kwargs) 375 P = Q 376 377 if show: 378 G.show(**kwargs) 379 380 return G 381
Note: See TracChangeset
for help on using the changeset viewer.
