Ticket #8838: trac_8838_arrow2d_3d.patch

File trac_8838_arrow2d_3d.patch, 3.8 KB (added by ryan, 3 years ago)

make arrow() behave more like line()

  • sage/plot/all.py

    # 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  
    66                  show_default) 
    77 
    88from line import line, line2d 
    9 from arrow import arrow 
     9from arrow import arrow, arrow2d 
    1010from bar_chart import bar_chart 
    1111from bezier_path import bezier_path 
    1212from scatter_plot import scatter_plot 
  • sage/plot/arrow.py

    diff -r 5227119ccb36 -r 07e35b5674ed sage/plot/arrow.py
    a b  
    112112        EXAMPLES:: 
    113113 
    114114        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)]]) 
    116116        """ 
    117117        options = self.options() 
    118118        width = float(options['width']) 
     
    318318        subplot.add_patch(p) 
    319319        return p 
    320320 
     321def 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 
    321341@rename_keyword(color='rgbcolor') 
    322342@options(width=2, rgbcolor=(0,0,1),zorder=2, head = 1, linestyle='solid') 
    323 def arrow(tailpoint=None, headpoint=None, path=None, **options): 
     343def arrow2d(tailpoint=None, headpoint=None, path=None, **options): 
    324344    """ 
    325345    If tailpoint and headpoint are provided, returns an arrow from (xmin, ymin)  
    326346    to (xmax, ymax).  If tailpoint or headpoint is None and path is not None, 
     
    357377 
    358378    A straight, blue arrow:: 
    359379 
    360        sage: arrow((1, 1), (3, 3)) 
     380       sage: arrow2d((1, 1), (3, 3)) 
    361381     
    362382    Make a red arrow:: 
    363383 
    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') 
    366386 
    367387    You can change the width of an arrow:: 
    368388 
    369         sage: arrow((1, 1), (3, 3), width=5, arrowsize=15) 
     389        sage: arrow2d((1, 1), (3, 3), width=5, arrowsize=15) 
    370390 
    371391    A pretty circle of arrows:: 
    372392 
    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) 
    374394 
    375395    If we want to draw the arrow between objects, for example, the 
    376396    boundaries of two lines, we can use the arrowshorten option 
    377397    to make the arrow shorter by a certain number of points:: 
    378398 
    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)) 
    380400 
    381401    Extra options will get passed on to show(), as long as they are valid:: 
    382402  
    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) 
    385405    """ 
    386406    from sage.plot.plot import Graphics 
    387407    g = Graphics()