Description
Here we will show how to make contour plots in sage for functions with two variables, such as
(1)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: Plotting: Two-dimensional plots
Secondary Tags: Two-dimensional plots: Contour plots
Related Cells
- Plotting a Circle
- Plotting a Polygon
- Plotting an Implicit Function
- Two-Dimensional Plots
- Parametric Plots
- Line Plots
- Plotting Two-Dimensional Vector Fields
- Multiple Plots on the Same Graph
- Controlling the Viewing Window of a Plot
- Plotting Functions with Asymptotes
- Multiple Annotation Techniques for Graphing
- Occasional Issues in Polar Plotting.
- Plotting Inequalities in Sage
- Plotting Systems of Linear Inequalities
- Plotting Nonlinear Inequalities in Sage
- Making log-log Plots in Sage
Attribute
Permalink:
Author: Gregory V. Bard. Sage for Undergraduates. American Mathematical Society, Providence, RI, 2015. Available at http://www.gregorybard.com/Sage.html.
Date: 28 Feb 2019 21:50
Submitted by: Zane Corbiere