Sharedsage_worksheets / venn diagrams.sagewsOpen in CoCalc
Author: Ken Levasseur
Description: Worksheets related to Applied Discrete Structures
m=2 scale = 1.7 sx=3 sy=2 centers = [(cos(n*2*pi/m), sin(n*2*pi/m)) for n in range(m)] clr = ['blue', 'blue', 'green'] G = Graphics() for i in range(m): G += circle(centers[i], scale, rgbcolor=clr[i],fill=True, alpha=0.3) for i in range(m): G += circle(centers[i], scale, rgbcolor='black') G+=line([[-sx,-sy],[sx,-sy],[sx,sy],[-sx,sy],[-sx,-sy]],rgbcolor=(0,0,0)) G+=text('B',centers[0]) G+=text('A',centers[1]) show(G,axes=false)
circle?
File: /projects/sage/sage-6.9/local/lib/python2.7/site-packages/sage/misc/decorators.py Signature : circle(center, radius, edgecolor='blue', legend_color=None, facecolor='blue', clip=True, linestyle='solid', thickness=1, zorder=5, aspect_ratio=1.0, alpha=1, legend_label=None, fill=False, **kwds) Docstring : 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 sage: c = circle((1,1), 1, rgbcolor=(1,0,0), linestyle='-.') sage: c Graphics object consisting of 1 graphics primitive 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'> 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) 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]) 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') Graphics object consisting of 1 graphics primitive 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 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 And circles with legends: sage: circle((4,5), 1, rgbcolor='yellow', fill=True, legend_label='the sun').show(xmin=0, ymin=0) sage: circle((4,5), 1, legend_label='the sun', legend_color='yellow').show(xmin=0, ymin=0) 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 sage: circle((0, 0), 2).show(figsize=[10,10]) # These are equivalent TESTS: We cannot currently plot circles in more than three dimensions: sage: circle((1,1,1,1), 1, rgbcolor=(1,0,0)) Traceback (most recent call last): ... ValueError: The center of a plotted circle should have two or three coordinates. The default aspect ratio for a circle is 1.0: sage: P = circle((1,1), 1) sage: P.aspect_ratio() 1.0