Circles

class sage.plot.circle.Circle(x, y, r, options)[source]

Bases: GraphicPrimitive

Primitive class for the Circle graphics type. See circle? for information about actually plotting circles.

INPUT:

  • x\(x\)-coordinate of center of Circle

  • y\(y\)-coordinate of center of Circle

  • r – radius of Circle object

  • options – dictionary of valid plot options to pass to constructor

EXAMPLES:

Note this should normally be used indirectly via circle:

sage: from sage.plot.circle import Circle
sage: C = Circle(2,3,5,{'zorder':2})
sage: C
Circle defined by (2.0,3.0) with r=5.0
sage: C.options()['zorder']
2
sage: C.r
5.0
>>> from sage.all import *
>>> from sage.plot.circle import Circle
>>> C = Circle(Integer(2),Integer(3),Integer(5),{'zorder':Integer(2)})
>>> C
Circle defined by (2.0,3.0) with r=5.0
>>> C.options()['zorder']
2
>>> C.r
5.0
get_minmax_data()[source]

Return a dictionary with the bounding box data.

EXAMPLES:

sage: p = circle((3, 3), 1)
sage: d = p.get_minmax_data()
sage: d['xmin']
2.0
sage: d['ymin']
2.0
>>> from sage.all import *
>>> p = circle((Integer(3), Integer(3)), Integer(1))
>>> d = p.get_minmax_data()
>>> d['xmin']
2.0
>>> d['ymin']
2.0
plot3d(z=0, **kwds)[source]

Plots a 2D circle (actually a 50-gon) in 3D, with default height zero.

INPUT:

  • z – (optional) 3D height above \(xy\)-plane

EXAMPLES:

sage: circle((0,0), 1).plot3d()
Graphics3d Object
>>> from sage.all import *
>>> circle((Integer(0),Integer(0)), Integer(1)).plot3d()
Graphics3d Object

This example uses this method implicitly, but does not pass the optional parameter z to this method:

sage: sum(circle((random(),random()), random()).plot3d(z=random())
....:     for _ in range(20))
Graphics3d Object
>>> from sage.all import *
>>> sum(circle((random(),random()), random()).plot3d(z=random())
...     for _ in range(Integer(20)))
Graphics3d Object
../../_images/circle-1.svg

These examples are explicit, and pass z to this method:

sage: from math import pi
sage: C = circle((2,pi), 2, hue=.8, alpha=.3, fill=True)
sage: c = C[0]
sage: d = c.plot3d(z=2)
sage: d.texture.opacity
0.3
>>> from sage.all import *
>>> from math import pi
>>> C = circle((Integer(2),pi), Integer(2), hue=RealNumber('.8'), alpha=RealNumber('.3'), fill=True)
>>> c = C[Integer(0)]
>>> d = c.plot3d(z=Integer(2))
>>> d.texture.opacity
0.3

sage: C = circle((2,pi), 2, hue=.8, alpha=.3, linestyle='dotted')
sage: c = C[0]
sage: d = c.plot3d(z=2)
sage: d.jmol_repr(d.testing_render_params())[0][-1]
'color $line_1 translucent 0.7 [204,0,255]'
>>> from sage.all import *
>>> C = circle((Integer(2),pi), Integer(2), hue=RealNumber('.8'), alpha=RealNumber('.3'), linestyle='dotted')
>>> c = C[Integer(0)]
>>> d = c.plot3d(z=Integer(2))
>>> d.jmol_repr(d.testing_render_params())[Integer(0)][-Integer(1)]
'color $line_1 translucent 0.7 [204,0,255]'
sage.plot.circle.circle(center, radius, alpha=1, fill=False, thickness=1, edgecolor='blue', facecolor='blue', linestyle='solid', zorder=5, legend_label=None, legend_color=None, clip=True, aspect_ratio=1.0, **options)[source]

Return a circle at a point center = \((x,y)\) (or \((x,y,z)\) and parallel to the \(xy\)-plane) with radius = \(r\). Type circle.options to see all options.

OPTIONS:

  • alpha – (default: 1)

  • fill – (default: False)

  • thickness – (default: 1)

  • linestyle – (default: 'solid') (2D plotting only) the style of the line, which is one of 'dashed', 'dotted', 'solid', 'dashdot', or '--', ':', '-', '-.', respectively

  • edgecolor – (default: 'blue') 2D plotting only

  • facecolor – (default: 'blue') 2D plotting only, useful only if fill=True

  • rgbcolor – 2D or 3D plotting. This option overrides edgecolor and facecolor for 2D plotting

  • legend_label – the label for this item in the legend

  • legend_color – the color for the legend label

EXAMPLES:

The default color is blue, the default linestyle is solid, but this is easy to change:

sage: c = circle((1,1), 1)
sage: c
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> c = circle((Integer(1),Integer(1)), Integer(1))
>>> c
Graphics object consisting of 1 graphics primitive
../../_images/circle-2.svg
sage: c = circle((1,1), 1, rgbcolor=(1,0,0), linestyle='-.')
sage: c
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> c = circle((Integer(1),Integer(1)), Integer(1), rgbcolor=(Integer(1),Integer(0),Integer(0)), linestyle='-.')
>>> c
Graphics object consisting of 1 graphics primitive
../../_images/circle-3.svg

We can also use this command to plot three-dimensional circles parallel to the \(xy\)-plane:

sage: c = circle((1,1,3), 1, rgbcolor=(1,0,0))
sage: c
Graphics3d Object
sage: type(c)
<class 'sage.plot.plot3d.base.TransformGroup'>
>>> from sage.all import *
>>> c = circle((Integer(1),Integer(1),Integer(3)), Integer(1), rgbcolor=(Integer(1),Integer(0),Integer(0)))
>>> c
Graphics3d Object
>>> type(c)
<class 'sage.plot.plot3d.base.TransformGroup'>
../../_images/circle-4.svg

To correct the aspect ratio of certain graphics, it is necessary to show with a figsize of square dimensions:

sage: c.show(figsize=[5,5],xmin=-1,xmax=3,ymin=-1,ymax=3)
>>> from sage.all import *
>>> c.show(figsize=[Integer(5),Integer(5)],xmin=-Integer(1),xmax=Integer(3),ymin=-Integer(1),ymax=Integer(3))

Here we make a more complicated plot, with many circles of different colors:

sage: g = Graphics()
sage: step = 6; ocur = 1/5; paths = 16
sage: PI = math.pi    # numerical for speed -- fine for graphics
sage: for r in range(1,paths+1):
....:     for x,y in [((r+ocur)*math.cos(n), (r+ocur)*math.sin(n))
....:                 for n in srange(0, 2*PI+PI/step, PI/step)]:
....:         g += circle((x,y), ocur, rgbcolor=hue(r/paths))
....:     rnext = (r+1)^2
....:     ocur = (rnext-r)-ocur
sage: g.show(xmin=-(paths+1)^2, xmax=(paths+1)^2,
....:        ymin=-(paths+1)^2, ymax=(paths+1)^2, figsize=[6,6])
>>> from sage.all import *
>>> g = Graphics()
>>> step = Integer(6); ocur = Integer(1)/Integer(5); paths = Integer(16)
>>> PI = math.pi    # numerical for speed -- fine for graphics
>>> for r in range(Integer(1),paths+Integer(1)):
...     for x,y in [((r+ocur)*math.cos(n), (r+ocur)*math.sin(n))
...                 for n in srange(Integer(0), Integer(2)*PI+PI/step, PI/step)]:
...         g += circle((x,y), ocur, rgbcolor=hue(r/paths))
...     rnext = (r+Integer(1))**Integer(2)
...     ocur = (rnext-r)-ocur
>>> g.show(xmin=-(paths+Integer(1))**Integer(2), xmax=(paths+Integer(1))**Integer(2),
...        ymin=-(paths+Integer(1))**Integer(2), ymax=(paths+Integer(1))**Integer(2), figsize=[Integer(6),Integer(6)])
../../_images/circle-5.svg

Note that the rgbcolor option overrides the other coloring options. This produces red fill in a blue circle:

sage: circle((2,3), 1, fill=True, edgecolor='blue', facecolor='red')
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> circle((Integer(2),Integer(3)), Integer(1), fill=True, edgecolor='blue', facecolor='red')
Graphics object consisting of 1 graphics primitive
../../_images/circle-6.svg

This produces an all-green filled circle:

sage: circle((2,3), 1, fill=True, edgecolor='blue', rgbcolor='green')
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> circle((Integer(2),Integer(3)), Integer(1), fill=True, edgecolor='blue', rgbcolor='green')
Graphics object consisting of 1 graphics primitive
../../_images/circle-7.svg

The option hue overrides all other options, so be careful with its use. This produces a purplish filled circle:

sage: circle((2,3), 1, fill=True, edgecolor='blue', rgbcolor='green', hue=.8)
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> circle((Integer(2),Integer(3)), Integer(1), fill=True, edgecolor='blue', rgbcolor='green', hue=RealNumber('.8'))
Graphics object consisting of 1 graphics primitive
../../_images/circle-8.svg

And circles with legends:

sage: circle((4,5), 1, rgbcolor='yellow', fill=True,
....:        legend_label='the sun').show(xmin=0, ymin=0)
>>> from sage.all import *
>>> circle((Integer(4),Integer(5)), Integer(1), rgbcolor='yellow', fill=True,
...        legend_label='the sun').show(xmin=Integer(0), ymin=Integer(0))
../../_images/circle-9.svg
sage: circle((4,5), 1,
....:        legend_label='the sun', legend_color='yellow').show(xmin=0, ymin=0)
>>> from sage.all import *
>>> circle((Integer(4),Integer(5)), Integer(1),
...        legend_label='the sun', legend_color='yellow').show(xmin=Integer(0), ymin=Integer(0))
../../_images/circle-10.svg

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

sage: circle((0, 0), 2, figsize=[10,10])  # That circle is huge!
Graphics object consisting of 1 graphics primitive
>>> from sage.all import *
>>> circle((Integer(0), Integer(0)), Integer(2), figsize=[Integer(10),Integer(10)])  # That circle is huge!
Graphics object consisting of 1 graphics primitive

sage: circle((0, 0), 2).show(figsize=[10,10])  # These are equivalent
>>> from sage.all import *
>>> circle((Integer(0), Integer(0)), Integer(2)).show(figsize=[Integer(10),Integer(10)])  # These are equivalent