Book Image

Sage Beginner's Guide

By : Craig Finch
1 (1)
Book Image

Sage Beginner's Guide

1 (1)
By: Craig Finch

Overview of this book

Table of Contents (17 chapters)
Sage Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – plotting with graphics primitives


A class of mathematical models called random sequential adsorption (RSA) models deals with the patterns that result when two-dimensional shapes are randomly deposited onto a plane. The following method can be used to visualize these kinds of models:

# Since the circles are random, your plot will not
# look exactly like the example!
circle_list = []
for i in range(15):
    x = -5 + 10 * random()
    y = -5 + 10 * random()
    circle_list.append(circle((x, y), 1, facecolor='red',
        edgecolor=(0, 0, 1), thickness=2, fill=True))
gr = sum(circle_list)
gr.axes(False)
gr.show(aspect_ratio=1, frame=True, gridlines=True, figsize=(4, 4))

You should get a plot that resembles the one below. Because the positions of the circles are randomly generated, your plot will not look exactly like this one.

What just happened?

We created a list of graphics objects with a for loop and the circle function. The basic syntax for the circle function is as follows...