Description
The Sage command for plotting $y = \sin(x)$ for $-10 \leq x \leq 10$.
Sage Cell
Code
plot(sin(x),(x, -10,10))
Options
Option
We may change the aspect ratio of the plot. The aspect ratio describes the apparently height/width ratio of a unit square. If the aspect ratio is not specified, it is set to automatic and will try to fill the graphics object.
Code
plot(sin(x),(x, -10,10), aspect_ratio = 2)
Option
We may add bounds for the y-axis so that a function with a vertical asymptote like $y = 1/x$ can be shown
Code
plot(1/(x), (x,-10, 10), detect_poles='show',ymin = -10, ymax = 10)
Option
We may change the line thickness and color of plots.
Code
plot(sin(x), (x, -10,10), thickness = 3, color = "red")
Option
We can add axes labels and customize tick marks.
Code
plot(sin(x),(x, -10,10), ticks=[[-7,-3,0,3,7],[-1/2,0,1/2]], axes_labels=['$x$','$y$'])
Option
We may combine plots.
Code
p = plot(sin(x),(x, -10,10))
p += plot(cos(x),(x, -10,10), color="red")
p
Option
We can add a legend for our plots.
Code
p = plot(sin(x),(x, -10,10), legend_label='$\sin x$')
p += plot(cos(x),(x, -10,10), color="red", legend_label='$\cos x$')
p
Option
We can add grid lines inside the graph when gridlines is either True or 'minor'.
Code
p = plot(sin(x),gridlines=True)
p
Option
We can make a graph have a frame.
Code
p = plot( sin(x), frame = True )
p
Option
We can add arrows, points, and text to graphs in order to draw attention to certain things.
Code
tangent_line = plot( 1 , 0,2*pi )
p = plot( sin(x) , 0,2*pi )
dot = point( ( pi/2 , 1), size=60)
arrow = arrow( ( pi/2 + .2 , 1.8), ( pi/2+.05, 1.1) )
words = text( '$f(x)=\sin(x)$ and the tangent line.',(4 , 1.5), fontsize=10)
h=p+tangent_line+dot+arrow+words
h
Option
We can shade graphs when dealing with integrals.
Code
integral= text('$\int_0^{2\pi} \sin( x ) dx$' , ( 4 , 1), fontsize=13)
p = plot( sin(x), 0 , 2*pi , fill = True)
h=p+integral
h
Option
We can make lines dotted or dashed.
Code
p = plot(x, 0, 10, gridlines=True)
q = plot( 2 * x, 0, 10, linestyle='-')
r = plot( 3 * x, 0, 10, linestyle='-.')
s = plot( 4 * x, 0, 10, linestyle=':')
t = plot( 5 * x, 0, 10, linestyle='--')
h=p+q+r+s+t
h
Tags
Primary Tags—Plotting: Two-dimensional plots
Secondary Tags—Two-dimensional plots: Rectangular plots
Related Cells
Attribute
Author: T. Judson
Permalink: http://doc.sagemath.org/html/en/reference/plotting/sage/plot/plot.html#sage.plot.plot.plot
Date: 16 Jun 2017 18:58
Submitted by: Tom Judson