Multiple Plots

Description

Here is an example of how to display multiple plots on one set of axes. We will plot the following polynomials:

(1)
\begin{align} P_1 &= (x - 1)(x - 2)(x - 3)\\ P_2 &= (x - 1)(x - 2)(x - 4)\\ P_3 &= (x - 1)(x - 2)(x - 5)\\ P_4 &= (x - 1)(x - 2)(x - 6)(x - 10) \end{align}

Setting each of the plots to a different variable, then adding them together to another variable and using the .show() method allows us to show multiple plots on the same set of axes.

Sage Cell

Code

P1 = plot((x - 1) * (x - 2) * (x - 3), 1, 6)
P2 = plot((x - 1) * (x - 2) * (x - 4), 1, 6)
P3 = plot((x - 1) * (x - 2) * (x - 5), 1, 6)
P4 = plot((x - 1) * (x - 2) * (x - 6) * (x - 10), 1, 6)
P = P1 + P2 + P3 + P4
P.show()

Options

Option

Plotting the functions in different colors is possible. A full list of built in colors can be found by evaluating sorted(colors) in a cell. To set a plot to a certain color, set the color property, with the color you want in single or double quotes after the equal sign.

Code

P1 = plot((x - 1) * (x - 2) * (x - 3), 1, 6, color = 'red')
P2 = plot((x - 1) * (x - 2) * (x - 4), 1, 6, color = 'blue')
P3 = plot((x - 1) * (x - 2) * (x - 5), 1, 6, color = 'purple')
P4 = plot((x - 1) * (x - 2) * (x - 6) * (x - 10), 1, 6, color = 'purple')
P = P1 + P2 + P3 + P4
P.show()

Tags

Primary Tags: Plotting: Two-dimensional plots

Secondary Tags: Two-dimensional plots: Rectangular plots

Related Cells

Attribute

Permalink:

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

Date: 13 Feb 2019 22:34

Submitted by: Zane Corbiere

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