# HG changeset patch
# User Ryan Grout <ayr035@gmail.com>
# Date 1282963408 18000
# Node ID 07e35b5674ed91c0c866cc53a7c944466f7547c2
# Parent 5227119ccb365a9c365611bbc8e41ba01f4701f4
#8838: make "arrow()" take 3d points
Modified arrow() to behave more like line(). Passing 2d points returns a 2d plot. Passing 3d points returns a 3d plot.
A 2d arrow is now arrow2d.
diff -r 5227119ccb36 -r 07e35b5674ed sage/plot/all.py
|
a
|
b
|
|
| 6 | 6 | show_default) |
| 7 | 7 | |
| 8 | 8 | from line import line, line2d |
| 9 | | from arrow import arrow |
| | 9 | from arrow import arrow, arrow2d |
| 10 | 10 | from bar_chart import bar_chart |
| 11 | 11 | from bezier_path import bezier_path |
| 12 | 12 | from scatter_plot import scatter_plot |
diff -r 5227119ccb36 -r 07e35b5674ed sage/plot/arrow.py
|
a
|
b
|
|
| 112 | 112 | EXAMPLES:: |
| 113 | 113 | |
| 114 | 114 | This function implicitly ends up rendering this arrow on a matplotlib subplot: |
| 115 | | sage: arrow(path=[[(0,1), (2,-1), (4,5)]]) |
| | 115 | sage: arrow2d(path=[[(0,1), (2,-1), (4,5)]]) |
| 116 | 116 | """ |
| 117 | 117 | options = self.options() |
| 118 | 118 | width = float(options['width']) |
| … |
… |
|
| 318 | 318 | subplot.add_patch(p) |
| 319 | 319 | return p |
| 320 | 320 | |
| | 321 | def arrow(start, end, **kwds): |
| | 322 | """ |
| | 323 | Returns either a 2-dimensional or 3-dimensional arrow depending |
| | 324 | on value of points. |
| | 325 | |
| | 326 | For information regarding additional arguments, see either arrow2d? |
| | 327 | or arrow3d?. |
| | 328 | |
| | 329 | EXAMPLES:: |
| | 330 | |
| | 331 | sage: arrow((0,0), (1,1)) |
| | 332 | sage: arrow((0,0,1), (1,1,1)) |
| | 333 | """ |
| | 334 | try: |
| | 335 | return arrow2d(start, end, **kwds) |
| | 336 | except ValueError: |
| | 337 | from sage.plot.plot3d.shapes import arrow3d |
| | 338 | return arrow3d(start, end, **kwds) |
| | 339 | |
| | 340 | |
| 321 | 341 | @rename_keyword(color='rgbcolor') |
| 322 | 342 | @options(width=2, rgbcolor=(0,0,1),zorder=2, head = 1, linestyle='solid') |
| 323 | | def arrow(tailpoint=None, headpoint=None, path=None, **options): |
| | 343 | def arrow2d(tailpoint=None, headpoint=None, path=None, **options): |
| 324 | 344 | """ |
| 325 | 345 | If tailpoint and headpoint are provided, returns an arrow from (xmin, ymin) |
| 326 | 346 | to (xmax, ymax). If tailpoint or headpoint is None and path is not None, |
| … |
… |
|
| 357 | 377 | |
| 358 | 378 | A straight, blue arrow:: |
| 359 | 379 | |
| 360 | | sage: arrow((1, 1), (3, 3)) |
| | 380 | sage: arrow2d((1, 1), (3, 3)) |
| 361 | 381 | |
| 362 | 382 | Make a red arrow:: |
| 363 | 383 | |
| 364 | | sage: arrow((-1, -1), (2, 3), color=(1,0,0)) |
| 365 | | sage: arrow((-1, -1), (2, 3), color='red') |
| | 384 | sage: arrow2d((-1, -1), (2, 3), color=(1,0,0)) |
| | 385 | sage: arrow2d((-1, -1), (2, 3), color='red') |
| 366 | 386 | |
| 367 | 387 | You can change the width of an arrow:: |
| 368 | 388 | |
| 369 | | sage: arrow((1, 1), (3, 3), width=5, arrowsize=15) |
| | 389 | sage: arrow2d((1, 1), (3, 3), width=5, arrowsize=15) |
| 370 | 390 | |
| 371 | 391 | A pretty circle of arrows:: |
| 372 | 392 | |
| 373 | | sage: sum([arrow((0,0), (cos(x),sin(x)), hue=x/(2*pi)) for x in [0..2*pi,step=0.1]]).show(aspect_ratio=1) |
| | 393 | sage: sum([arrow2d((0,0), (cos(x),sin(x)), hue=x/(2*pi)) for x in [0..2*pi,step=0.1]]).show(aspect_ratio=1) |
| 374 | 394 | |
| 375 | 395 | If we want to draw the arrow between objects, for example, the |
| 376 | 396 | boundaries of two lines, we can use the arrowshorten option |
| 377 | 397 | to make the arrow shorter by a certain number of points:: |
| 378 | 398 | |
| 379 | | sage: line([(0,0),(1,0)],thickness=10)+line([(0,1),(1,1)], thickness=10)+arrow((0.5,0),(0.5,1), arrowshorten=10,rgbcolor=(1,0,0)) |
| | 399 | sage: line([(0,0),(1,0)],thickness=10)+line([(0,1),(1,1)], thickness=10)+arrow2d((0.5,0),(0.5,1), arrowshorten=10,rgbcolor=(1,0,0)) |
| 380 | 400 | |
| 381 | 401 | Extra options will get passed on to show(), as long as they are valid:: |
| 382 | 402 | |
| 383 | | sage: arrow((-2, 2), (7,1), frame=True) |
| 384 | | sage: arrow((-2, 2), (7,1)).show(frame=True) |
| | 403 | sage: arrow2d((-2, 2), (7,1), frame=True) |
| | 404 | sage: arrow2d((-2, 2), (7,1)).show(frame=True) |
| 385 | 405 | """ |
| 386 | 406 | from sage.plot.plot import Graphics |
| 387 | 407 | g = Graphics() |