Contour Plots Test


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

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

Sage Cell


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


Multicolor plots

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


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


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.


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


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.



Author: Gregory V. Bard. Sage for Undergraduates. American Mathematical Society, Providence, RI, 2015. Available at

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