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 do var('t') beforehand.
  • Both functions come with a wide range of options, such as color, thickness, and linestyle. 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 the show function.

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" or vertical_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 option fill = {0:[1]} shades the region between curves. 0 is the first plot and [1] is the second plot.
  • Use plot. The option fill = "min" shades the region below the curve all the way to its minimum. Similarly, the option fill = "max" shades the region above the curve up to its maximum.
  • Use polygon.
  • Use parametric_plot.
  • Use line segments.