Contour Plots Test

Description

Here we will show how to make contour plots in sage for functions with two variables, such as

(1)
\begin{equation} f(x, y) = x^2 + y^2. \end{equation}

Sage Cell

Code

y = var('y')
contour_plot(x^2 + y^2, (x, -10, 10), (y, -10, 10))

Options

Multicolor plots

By using the cmap option, we can make a contour plot in multiple different colors instead of shades:

Code

y = var('y')
contour_plot(x^2 + y^2, (x, -10, 10), (y, -10, 10), cmap='jet')

Adding a legend

We can also set colorbar to True for a legend to increase readability

Code

y = var('y')
contour_plot(x^2 + y^2, (x, -10, 10), (y, -10, 10), cmap='jet', colorbar=True)

Fill, Axes and Labels

When creating a contour plot, you can set the fill, axes and labels properties to True or False (Their default values are True, False and False, respectively). If you're setting axes or labels to True, it's a good idea to set fill to False, otherwise the fill will cover them up.

Code

y = var('y')
contour_plot(x^2 + y^2, (x, -10, 10), (y, -10, 10), fill=False, axes=True, labels=True)

Tags

Primary Tags:

Secondary Tags:

A list of possible tags can be found at The WeBWorK Open Problem Library. For linear algebra tags see the Curated Courses Project.

Related Cells

Any related cells go here. Provide a link to the page containing the information about the cell.

Attribute

Permalink:

Author: Gregory V. Bard. Sage for Undergraduates. American Mathematical Society, Providence, RI, 2015. Available at http://www.gregorybard.com/Sage.html.

Date: 23 Mar 2019 23:33

Submitted by: Tom Judson

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License