Line plots#

class sage.plot.line.Line(xdata, ydata, options)[source]#

Bases: GraphicPrimitive_xydata

Primitive class that initializes the line graphics type.

EXAMPLES:

sage: from sage.plot.line import Line
sage: Line([1,2,7], [1,5,-1], {})
Line defined by 3 points
>>> from sage.all import *
>>> from sage.plot.line import Line
>>> Line([Integer(1),Integer(2),Integer(7)], [Integer(1),Integer(5),-Integer(1)], {})
Line defined by 3 points
plot3d(z=0, **kwds)[source]#

Plots a 2D line in 3D, with default height zero.

EXAMPLES:

sage: E = EllipticCurve('37a').plot(thickness=5).plot3d()                   # needs sage.schemes
sage: F = EllipticCurve('37a').plot(thickness=5).plot3d(z=2)                # needs sage.schemes
sage: E + F                         # long time (5s on sage.math, 2012), needs sage.schemes
Graphics3d Object
>>> from sage.all import *
>>> E = EllipticCurve('37a').plot(thickness=Integer(5)).plot3d()                   # needs sage.schemes
>>> F = EllipticCurve('37a').plot(thickness=Integer(5)).plot3d(z=Integer(2))                # needs sage.schemes
>>> E + F                         # long time (5s on sage.math, 2012), needs sage.schemes
Graphics3d Object
../../_images/line-1.svg
sage.plot.line.line(points, **kwds)[source]#

Returns either a 2-dimensional or 3-dimensional line depending on value of points.

INPUT:

  • points – either a single point (as a tuple), a list of points, a single complex number, or a list of complex numbers.

For information regarding additional arguments, see either line2d? or line3d?.

EXAMPLES:

sage: line([(0,0), (1,1)])
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> line([(Integer(0),Integer(0)), (Integer(1),Integer(1))])
Graphics object consisting of 1 graphics primitive
../../_images/line-2.svg
sage: line([(0,0,1), (1,1,1)])
Graphics3d Object
>>> from sage.all import *
>>> line([(Integer(0),Integer(0),Integer(1)), (Integer(1),Integer(1),Integer(1))])
Graphics3d Object
../../_images/line-3.svg
sage.plot.line.line2d(points, alpha=1, rgbcolor=(0, 0, 1), thickness=1, legend_label=None, legend_color=None, aspect_ratio='automatic', **options)[source]#

Create the line through the given list of points.

INPUT:

  • points – either a single point (as a tuple), a list of points, a single complex number, or a list of complex numbers.

Type line2d.options for a dictionary of the default options for lines. You can change this to change the defaults for all future lines. Use line2d.reset() to reset to the default options.

INPUT:

  • alpha – How transparent the line is

  • thickness – How thick the line is

  • rgbcolor – The color as an RGB tuple

  • hue – The color given as a hue

  • legend_color – The color of the text in the legend

  • legend_label – the label for this item in the legend

Any MATPLOTLIB line option may also be passed in. E.g.,

  • linestyle – (default: “-”) The style of the line, which is one of
    • "-" or "solid"

    • "--" or "dashed"

    • "-." or "dash dot"

    • ":" or "dotted"

    • "None" or " " or "" (nothing)

    The linestyle can also be prefixed with a drawing style (e.g., "steps--")

    • "default" (connect the points with straight lines)

    • "steps" or "steps-pre" (step function; horizontal line is to the left of point)

    • "steps-mid" (step function; points are in the middle of horizontal lines)

    • "steps-post" (step function; horizontal line is to the right of point)

  • marker – The style of the markers, which is one of
    • "None" or " " or "" (nothing) – default

    • "," (pixel), "." (point)

    • "_" (horizontal line), "|" (vertical line)

    • "o" (circle), "p" (pentagon), "s" (square), "x" (x), "+" (plus), "*" (star)

    • "D" (diamond), "d" (thin diamond)

    • "H" (hexagon), "h" (alternative hexagon)

    • "<" (triangle left), ">" (triangle right), "^" (triangle up), "v" (triangle down)

    • "1" (tri down), "2" (tri up), "3" (tri left), "4" (tri right)

    • 0 (tick left), 1 (tick right), 2 (tick up), 3 (tick down)

    • 4 (caret left), 5 (caret right), 6 (caret up), 7 (caret down)

    • "$...$" (math TeX string)

  • markersize – the size of the marker in points

  • markeredgecolor – the color of the marker edge

  • markerfacecolor – the color of the marker face

  • markeredgewidth – the size of the marker edge in points

EXAMPLES:

A line with no points or one point:

sage: line([])      # returns an empty plot
Graphics object consisting of 0 graphics primitives
sage: import numpy; line(numpy.array([]))                                       # needs numpy
Graphics object consisting of 0 graphics primitives
sage: line([(1,1)])
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> line([])      # returns an empty plot
Graphics object consisting of 0 graphics primitives
>>> import numpy; line(numpy.array([]))                                       # needs numpy
Graphics object consisting of 0 graphics primitives
>>> line([(Integer(1),Integer(1))])
Graphics object consisting of 1 graphics primitive

A line with numpy arrays:

sage: line(numpy.array([[1,2], [3,4]]))                                         # needs numpy
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> line(numpy.array([[Integer(1),Integer(2)], [Integer(3),Integer(4)]]))                                         # needs numpy
Graphics object consisting of 1 graphics primitive

A line with a legend:

sage: line([(0,0),(1,1)], legend_label='line')
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> line([(Integer(0),Integer(0)),(Integer(1),Integer(1))], legend_label='line')
Graphics object consisting of 1 graphics primitive
../../_images/line-4.svg

Lines with different colors in the legend text:

sage: p1 = line([(0,0),(1,1)], legend_label='line')
sage: p2 = line([(1,1),(2,4)], legend_label='squared', legend_color='red')
sage: p1 + p2
Graphics object consisting of 2 graphics primitives
>>> from sage.all import *
>>> p1 = line([(Integer(0),Integer(0)),(Integer(1),Integer(1))], legend_label='line')
>>> p2 = line([(Integer(1),Integer(1)),(Integer(2),Integer(4))], legend_label='squared', legend_color='red')
>>> p1 + p2
Graphics object consisting of 2 graphics primitives
../../_images/line-5.svg

Extra options will get passed on to show(), as long as they are valid:

sage: line([(0,1), (3,4)], figsize=[10, 2])
Graphics object consisting of 1 graphics primitive
sage: line([(0,1), (3,4)]).show(figsize=[10, 2]) # These are equivalent
>>> from sage.all import *
>>> line([(Integer(0),Integer(1)), (Integer(3),Integer(4))], figsize=[Integer(10), Integer(2)])
Graphics object consisting of 1 graphics primitive
>>> line([(Integer(0),Integer(1)), (Integer(3),Integer(4))]).show(figsize=[Integer(10), Integer(2)]) # These are equivalent

We can also use a logarithmic scale if the data will support it:

sage: line([(1,2),(2,4),(3,4),(4,8),(4.5,32)],scale='loglog',base=2)
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> line([(Integer(1),Integer(2)),(Integer(2),Integer(4)),(Integer(3),Integer(4)),(Integer(4),Integer(8)),(RealNumber('4.5'),Integer(32))],scale='loglog',base=Integer(2))
Graphics object consisting of 1 graphics primitive
../../_images/line-6.svg

Many more examples below!

A blue conchoid of Nicomedes:

sage: from math import pi
sage: L = [[1 + 5*cos(pi/2+pi*i/100),
....:       tan(pi/2+pi*i/100) * (1+5*cos(pi/2+pi*i/100))] for i in range(1,100)]
sage: line(L, rgbcolor=(1/4,1/8,3/4))
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> from math import pi
>>> L = [[Integer(1) + Integer(5)*cos(pi/Integer(2)+pi*i/Integer(100)),
...       tan(pi/Integer(2)+pi*i/Integer(100)) * (Integer(1)+Integer(5)*cos(pi/Integer(2)+pi*i/Integer(100)))] for i in range(Integer(1),Integer(100))]
>>> line(L, rgbcolor=(Integer(1)/Integer(4),Integer(1)/Integer(8),Integer(3)/Integer(4)))
Graphics object consisting of 1 graphics primitive
../../_images/line-7.svg

A line with 2 complex points:

sage: i = CC(0,1)
sage: line([1 + i, 2 + 3*i])
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> i = CC(Integer(0),Integer(1))
>>> line([Integer(1) + i, Integer(2) + Integer(3)*i])
Graphics object consisting of 1 graphics primitive
../../_images/line-8.svg

A blue hypotrochoid (3 leaves):

sage: n = 4; h = 3; b = 2
sage: L = [[n*cos(pi*i/100) + h*cos((n/b)*pi*i/100),
....:       n*sin(pi*i/100) - h*sin((n/b)*pi*i/100)] for i in range(200)]
sage: line(L, rgbcolor=(1/4,1/4,3/4))
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> n = Integer(4); h = Integer(3); b = Integer(2)
>>> L = [[n*cos(pi*i/Integer(100)) + h*cos((n/b)*pi*i/Integer(100)),
...       n*sin(pi*i/Integer(100)) - h*sin((n/b)*pi*i/Integer(100))] for i in range(Integer(200))]
>>> line(L, rgbcolor=(Integer(1)/Integer(4),Integer(1)/Integer(4),Integer(3)/Integer(4)))
Graphics object consisting of 1 graphics primitive
../../_images/line-9.svg

A blue hypotrochoid (4 leaves):

sage: n = 6; h = 5; b = 2
sage: L = [[n*cos(pi*i/100) + h*cos((n/b)*pi*i/100),
....:       n*sin(pi*i/100) - h*sin((n/b)*pi*i/100)] for i in range(200)]
sage: line(L, rgbcolor=(1/4,1/4,3/4))
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> n = Integer(6); h = Integer(5); b = Integer(2)
>>> L = [[n*cos(pi*i/Integer(100)) + h*cos((n/b)*pi*i/Integer(100)),
...       n*sin(pi*i/Integer(100)) - h*sin((n/b)*pi*i/Integer(100))] for i in range(Integer(200))]
>>> line(L, rgbcolor=(Integer(1)/Integer(4),Integer(1)/Integer(4),Integer(3)/Integer(4)))
Graphics object consisting of 1 graphics primitive
../../_images/line-10.svg

A red limacon of Pascal:

sage: L = [[sin(pi*i/100) + sin(pi*i/50),
....:       -(1 + cos(pi*i/100) + cos(pi*i/50))] for i in range(-100,101)]
sage: line(L, rgbcolor=(1,1/4,1/2))
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> L = [[sin(pi*i/Integer(100)) + sin(pi*i/Integer(50)),
...       -(Integer(1) + cos(pi*i/Integer(100)) + cos(pi*i/Integer(50)))] for i in range(-Integer(100),Integer(101))]
>>> line(L, rgbcolor=(Integer(1),Integer(1)/Integer(4),Integer(1)/Integer(2)))
Graphics object consisting of 1 graphics primitive
../../_images/line-11.svg

A light green trisectrix of Maclaurin:

sage: L = [[2 * (1-4*cos(-pi/2+pi*i/100)^2),
....:       10 * tan(-pi/2+pi*i/100) * (1-4*cos(-pi/2+pi*i/100)^2)] for i in range(1,100)]
sage: line(L, rgbcolor=(1/4,1,1/8))
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> L = [[Integer(2) * (Integer(1)-Integer(4)*cos(-pi/Integer(2)+pi*i/Integer(100))**Integer(2)),
...       Integer(10) * tan(-pi/Integer(2)+pi*i/Integer(100)) * (Integer(1)-Integer(4)*cos(-pi/Integer(2)+pi*i/Integer(100))**Integer(2))] for i in range(Integer(1),Integer(100))]
>>> line(L, rgbcolor=(Integer(1)/Integer(4),Integer(1),Integer(1)/Integer(8)))
Graphics object consisting of 1 graphics primitive
../../_images/line-12.svg

A green lemniscate of Bernoulli:

sage: cosines = [cos(-pi/2+pi*i/100) for i in range(201)]
sage: v = [(1/c, tan(-pi/2+pi*i/100)) for i,c in enumerate(cosines) if c != 0]
sage: L = [(a/(a^2+b^2), b/(a^2+b^2)) for a,b in v]
sage: line(L, rgbcolor=(1/4,3/4,1/8))
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> cosines = [cos(-pi/Integer(2)+pi*i/Integer(100)) for i in range(Integer(201))]
>>> v = [(Integer(1)/c, tan(-pi/Integer(2)+pi*i/Integer(100))) for i,c in enumerate(cosines) if c != Integer(0)]
>>> L = [(a/(a**Integer(2)+b**Integer(2)), b/(a**Integer(2)+b**Integer(2))) for a,b in v]
>>> line(L, rgbcolor=(Integer(1)/Integer(4),Integer(3)/Integer(4),Integer(1)/Integer(8)))
Graphics object consisting of 1 graphics primitive
../../_images/line-13.svg

A red plot of the Jacobi elliptic function \(\text{sn}(x,2)\), \(-3 < x < 3\):

sage: L = [(i/100.0, real_part(jacobi('sn', i/100.0, 2.0)))
....:      for i in range(-300, 300, 30)]
sage: line(L, rgbcolor=(3/4, 1/4, 1/8))
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> L = [(i/RealNumber('100.0'), real_part(jacobi('sn', i/RealNumber('100.0'), RealNumber('2.0'))))
...      for i in range(-Integer(300), Integer(300), Integer(30))]
>>> line(L, rgbcolor=(Integer(3)/Integer(4), Integer(1)/Integer(4), Integer(1)/Integer(8)))
Graphics object consisting of 1 graphics primitive
../../_images/line-14.svg

A red plot of \(J\)-Bessel function \(J_2(x)\), \(0 < x < 10\):

sage: L = [(i/10.0, bessel_J(2,i/10.0)) for i in range(100)]
sage: line(L, rgbcolor=(3/4, 1/4, 5/8))
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> L = [(i/RealNumber('10.0'), bessel_J(Integer(2),i/RealNumber('10.0'))) for i in range(Integer(100))]
>>> line(L, rgbcolor=(Integer(3)/Integer(4), Integer(1)/Integer(4), Integer(5)/Integer(8)))
Graphics object consisting of 1 graphics primitive
../../_images/line-15.svg

A purple plot of the Riemann zeta function \(\zeta(1/2 + it)\), \(0 < t < 30\):

sage: # needs sage.libs.pari sage.rings.complex_double
sage: i = CDF.gen()
sage: v = [zeta(0.5 + n/10 * i) for n in range(300)]
sage: L = [(z.real(), z.imag()) for z in v]
sage: line(L, rgbcolor=(3/4, 1/2, 5/8))
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> # needs sage.libs.pari sage.rings.complex_double
>>> i = CDF.gen()
>>> v = [zeta(RealNumber('0.5') + n/Integer(10) * i) for n in range(Integer(300))]
>>> L = [(z.real(), z.imag()) for z in v]
>>> line(L, rgbcolor=(Integer(3)/Integer(4), Integer(1)/Integer(2), Integer(5)/Integer(8)))
Graphics object consisting of 1 graphics primitive
../../_images/line-16.svg

A purple plot of the Hasse-Weil \(L\)-function \(L(E, 1 + it)\), \(-1 < t < 10\):

sage: # needs sage.schemes
sage: E = EllipticCurve('37a')
sage: vals = E.lseries().values_along_line(1-I, 1+10*I, 100)  # critical line
sage: L = [(z[1].real(), z[1].imag()) for z in vals]
sage: line(L, rgbcolor=(3/4,1/2,5/8))
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> # needs sage.schemes
>>> E = EllipticCurve('37a')
>>> vals = E.lseries().values_along_line(Integer(1)-I, Integer(1)+Integer(10)*I, Integer(100))  # critical line
>>> L = [(z[Integer(1)].real(), z[Integer(1)].imag()) for z in vals]
>>> line(L, rgbcolor=(Integer(3)/Integer(4),Integer(1)/Integer(2),Integer(5)/Integer(8)))
Graphics object consisting of 1 graphics primitive
../../_images/line-17.svg

A red, blue, and green “cool cat”:

sage: # needs sage.symbolic
sage: G = plot(-cos(x), -2, 2, thickness=5, rgbcolor=(0.5,1,0.5))
sage: P = polygon([[1,2], [5,6], [5,0]], rgbcolor=(1,0,0))
sage: Q = polygon([(-x,y) for x,y in P[0]], rgbcolor=(0,0,1))
sage: G + P + Q   # show the plot
Graphics object consisting of 3 graphics primitives
>>> from sage.all import *
>>> # needs sage.symbolic
>>> G = plot(-cos(x), -Integer(2), Integer(2), thickness=Integer(5), rgbcolor=(RealNumber('0.5'),Integer(1),RealNumber('0.5')))
>>> P = polygon([[Integer(1),Integer(2)], [Integer(5),Integer(6)], [Integer(5),Integer(0)]], rgbcolor=(Integer(1),Integer(0),Integer(0)))
>>> Q = polygon([(-x,y) for x,y in P[Integer(0)]], rgbcolor=(Integer(0),Integer(0),Integer(1)))
>>> G + P + Q   # show the plot
Graphics object consisting of 3 graphics primitives
../../_images/line-18.svg