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 – making some contour plots


The following code will demonstrate four different ways to make a 2D plot of a 3D surface with Sage:

var('x, y')
text_coords = (2, -3.5)

cp = contour_plot(y^2 + 1 - x^3 - x, (x, -3, 3), (y, -3, 3),
    contours=8, linewidths=srange(0.5, 4.0, 0.5), fill=False,
    labels=True, label_colors='black', cmap='gray', colorbar=False)
cp += text("Contour", text_coords)

ip = implicit_plot(y^2 + 1 - x^3 - x, (x, -3, 3), (y, -3, 3))
ip += text("Implicit", text_coords)

rp = region_plot(y^2 + 1 - x^3 - x < 0, (x, -3, 3), (y, -3, 3),
    incol=(0.8, 0.8, 0.8))    # color is an (R,G,B) tuple
rp += text("Region", text_coords)

dp = density_plot(y^2 + 1 - x^3 - x, (x, -3, 3), (y, -3, 3))
dp += text("Density", text_coords)

show(graphics_array([cp, ip, rp, dp], 2, 2), aspect_ratio=1, 
    figsize=(6, 6))

The output should be as follows:

What just happened?

The plots we made demonstrate four different ways of visualizing the function we plotted in the previous...