Controlling the Viewing Window of a Plot

Description

Here we will show how to remove a plot's axes and control a plot's $y$-axis. We will plot the function

(1)
\begin{equation} f(x) = x^3 \end{equation}

from $x = 5$ to $x = 10$, removing the axes with the axes = false option. When plotting, axes will be automatically shown, but they can be turned off by assigning the boolean value "false" to axes in the plot command.

Sage Cell

Code

plot(x^3, (x, 5, 10), axes=false)

Options

Forcing the y-axis

We will plot

(2)
\begin{equation} f(x) = x^3 - x \end{equation}

from $x = -3$ to $x = 3$. We will force the $y$-axis to be limited to between $-6$ and $6$ using the commands ymin and ymax. These commands determine the maximum and minimum $y$-values that will be shown. When unset, the ymax and ymin will be the local maximum and local minimum for the domain of the function being plotted.

Code

plot(x^3 - x, (x,-3, 3), ymin=-6, ymax=6)

Forcing the x-axis

Sage usually automatically determines the x-axis domain through the domains of what it is asked to plot. However, if you want to set the x-axis maximum and minimum to something else, you may insert xmin and xmax into the .show() method. We will be plotting the function

(3)
\begin{align} f(x) = \sqrt{5x + 8} + \ln(3 - 9x) + \sqrt{1 - 4x}. \end{align}

which has a domain of $-8/5 \leq x \leq 1/4$ on a graph from $-2 \leq x \leq 2$.

The error message here is simply a warning that the domain requested is greater than the actual domain of the function, but Sage will complete the request anyway. Note that xmin and xmax are set in .show(), not in plot().

Code

plot( sqrt(5*x + 8) + log(3 - 9*x) + sqrt(1 - 4*x),(x, -2, 2), gridlines = True).show(xmin=-2,xmax=2)

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: 15 Feb 2019 01:07

Submitted by: Zane Corbiere

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