9.1 Plots (2D)
9.1.1 Basic Plots
The plot
and the parametric_plot
functions are sufficient for basic plots.
- The default variable for the domain is \(x\). Other parameters need to be declared in advance. For example, \(t\) is used in the
parametric_plot
function, so we dovar('t')
beforehand. - Both functions come with a wide range of options, such as
color
,thickness
, andlinestyle
. The complete list of options can be looked up by?plot
. - The graphic object can be put together in one variable (e.g.,
fig
). Use=
for initiating the first plot and+=
for adding subsequent plots. - The
show
function draws graphic object. Axes limits, axes ticks, and aspect ratio can be defined inside theshow
function.
9.1.2 Popular Objects
Popular geometric objects such as lines, segments, and circles have predefined graphic commands.
- line( [ ( x1, y1 ), ( x2, y2 ) ] )
- list_plot( [ ( x1, y1 ), ( x2, y2 ), ( x3, y3 ) ], plotjoined = True)
- circle( ( xcenter, ycenter ), radius)
9.1.3 Text
The text
function adds text strings to the graph. Simply use text( "string", (x, y))
.
- Math symbols in LaTeX are supported. For example,
text(r"$\sqrt{x}$", (1, 1))
. The letter r forces the string to be interpreted as a raw string. - Rotation. The option
rotation = 45
will rotate the text string counterclockwise by 45°. - Anchor. The anchor of the string is pinned by the options
horizontal_alignment = "left"/"right"
orvertical_alignment = "top"/"bottom"
. - Other common options such as color and fontsize are also supported.
9.1.4 Fill a Region
There are a few ways to shade a region.
- Use
plot
. The optionfill = {0:[1]}
shades the region between curves. 0 is the first plot and [1] is the second plot. - Use
plot
. The optionfill = "min"
shades the region below the curve all the way to its minimum. Similarly, the optionfill = "max"
shades the region above the curve up to its maximum. - Use
polygon
. - Use
parametric_plot
. - Use line segments.