Skip to main content
Mathematics LibreTexts

11.3: Other Function Plots

  • Page ID
    63930
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Here's some preliminary commands to run if they haven't been yet.

    using Pkg; Pkg.add("Plots")
       Updating registry at `/srv/julia/pkg/registries/General`
      Resolving package versions...
    Updating `~/Project.toml`
      [91a5bcdd] + Plots v1.14.0
    Updating `~/Manifest.toml`
      [6e34b625] + Bzip2_jll v1.0.6+5
      [83423d85] + Cairo_jll v1.16.0+6
      [35d6a980] + ColorSchemes v3.12.1
      [5ae413db] + EarCut_jll v2.1.5+1
      [2e619515] + Expat_jll v2.2.7+6
      [c87230d0] + FFMPEG v0.4.0
      [b22a6f82] + FFMPEG_jll v4.3.1+4
      [a3f928ae] + Fontconfig_jll v2.13.1+14
      [d7e528f0] + FreeType2_jll v2.10.1+5
      [559328eb] + FriBidi_jll v1.0.5+6
      [0656b61e] + GLFW_jll v3.3.4+0
      [28b8d3ca] + GR v0.57.4
      [d2c73de3] + GR_jll v0.57.2+0
      [5c1252a2] + GeometryBasics v0.3.12
      [78b55507] + Gettext_jll v0.20.1+7
      [7746bdde] + Glib_jll v2.59.0+4
      [aacddb02] + JpegTurbo_jll v2.0.1+3
      [c1c5ebd0] + LAME_jll v3.100.0+3
      [dd4b983a] + LZO_jll v2.10.0+3
      [b964fa9f] + LaTeXStrings v1.2.1
      [23fbe1c1] + Latexify v0.15.5
      [dd192d2f] + LibVPX_jll v1.9.0+1
      [e9f186c6] + Libffi_jll v3.2.1+4
      [d4300ac3] + Libgcrypt_jll v1.8.5+4
      [7e76a0d4] + Libglvnd_jll v1.3.0+3
      [7add5ba3] + Libgpg_error_jll v1.36.0+3
      [4b2f31a3] + Libmount_jll v2.34.0+3
      [89763e89] + Libtiff_jll v4.1.0+2
      [38a345b3] + Libuuid_jll v2.34.0+7
      [77ba4419] + NaNMath v0.3.5
      [e7412a2a] + Ogg_jll v1.3.4+2
      [91d4177d] + Opus_jll v1.3.1+3
      [2f80f16e] + PCRE_jll v8.42.0+4
      [30392449] + Pixman_jll v0.40.0+0
      [ccf2f8ad] + PlotThemes v2.0.1
      [995b91a9] + PlotUtils v1.0.10
      [91a5bcdd] + Plots v1.14.0
      [ea2cea3b] + Qt5Base_jll v5.15.2+0
      [01d81517] + RecipesPipeline v0.3.2
      [f50d1b31] ↑ Rmath_jll v0.2.2+1 ⇒ v0.2.2+2
      [6c6a2e73] + Scratch v1.0.3
      [09ab397b] + StructArrays v0.5.1
      [a2964d1f] + Wayland_jll v1.17.0+4
      [2381bf8a] + Wayland_protocols_jll v1.18.0+4
      [aed1982a] + XSLT_jll v1.1.33+4
      [4f6342f7] + Xorg_libX11_jll v1.6.9+4
      [0c0b7dd1] + Xorg_libXau_jll v1.0.9+4
      [935fb764] + Xorg_libXcursor_jll v1.2.0+4
      [a3789734] + Xorg_libXdmcp_jll v1.1.3+4
      [1082639a] + Xorg_libXext_jll v1.3.4+4
      [d091e8ba] + Xorg_libXfixes_jll v5.0.3+4
      [a51aa0fd] + Xorg_libXi_jll v1.7.10+4
      [d1454406] + Xorg_libXinerama_jll v1.1.4+4
      [ec84b674] + Xorg_libXrandr_jll v1.5.2+4
      [ea2f1a96] + Xorg_libXrender_jll v0.9.10+4
      [14d82f49] + Xorg_libpthread_stubs_jll v0.1.0+3
      [c7cfdc94] + Xorg_libxcb_jll v1.13.0+3
      [cc61e674] + Xorg_libxkbfile_jll v1.1.0+4
      [12413925] + Xorg_xcb_util_image_jll v0.4.0+1
      [2def613f] + Xorg_xcb_util_jll v0.4.0+1
      [975044d2] + Xorg_xcb_util_keysyms_jll v0.4.0+1
      [0d47668e] + Xorg_xcb_util_renderutil_jll v0.3.9+1
      [c22f9ab0] + Xorg_xcb_util_wm_jll v0.4.1+1
      [35661453] + Xorg_xkbcomp_jll v1.4.2+4
      [33bec58e] + Xorg_xkeyboard_config_jll v2.27.0+4
      [c5fb5394] + Xorg_xtrans_jll v1.4.0+3
      [0ac62f75] + libass_jll v0.14.0+4
      [f638f0a6] + libfdk_aac_jll v0.1.6+4
      [b53b4c65] + libpng_jll v1.6.37+6
      [f27f6e37] + libvorbis_jll v1.3.6+6
      [1270edf5] + x264_jll v2020.7.14+2
      [dfaa095f] + x265_jll v3.0.0+3
      [d8fb68d0] + xkbcommon_jll v0.9.1+5
    
    using Plots
     

    Parametric Plots

    Recall that a parametric curve is a set of points in the \(xy\)-plane given by \( (x(t),y(t)\) for functions \(x(t)\) and \(y(t)\).  The variable \(t\) is called the parameter.  A classic example is the circle that can be written as

    \[x(t) = \cos t, \qquad y(t) = \sin t \nonumber \]

    To plot the circle using this form, enter

    plot(t->cos(t),t->sin(t),0,2*pi,legend=false)
    UndefVarError: plot not defined
    
    Stacktrace:
     [1] top-level scope at In[1]:1
     [2] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091

    and note that the legend is turned off, since with one curve, it doesn’t make much sense. Notice that this should be a circle, but it looks like an ellipse due to the aspect ratio. If one instead adds the aspect_ratio=:equal option, as in

    plot(t->cos(t),t->sin(t),0,2*pi,aspect_ratio=:equal, legend=false)
     

    Exercise

    Produce a plot of the curve \( x(t) = t^3-t, y(t)=t^2 \) for \(-2 \leq t \leq 2\).

    # insert your code here
     

    Implicit Curves

    An implicit curve is the set of points such that \(f (x, y) = 0\) (or any constant) and a circle is the classic example.  For example, \(x^2+y^2=1\).  Although there are others ways of doing this, we will use some algebra to write the circle as \( f(x,y) = x^2+y^2-1 \). 

    We can plot this with the contourfunction for example

    contour(-1.05:0.05:1.05, -1.05:0.05:1.05, (x,y) -> x^2+y^2-1, levels=[0], aspect_ratio = :equal, legend = false)
     

    Note that again, we have used the option aspect_ratio = :equal to ensure that the circle looks like a circle. The resulting plot is exactly the same as the circle above. 

    The following example is a bit more visually interesting.  This is the function \( f(x,y) = sin(x+y)-cos(xy)+1 \)

    contour(-10.1:0.1:10.1, -10.1:0.1:10.1, (x,y) -> sin(x+y)-cos(x*y)+1, levels=[0], aspect_ratio = :equal, colorbar_entry = false)
     

    Exercise

    A cardiod is a 2D curve that looks a bit like a heart.  It can be represented by an implicit curve with the equation

    \[ (x^2+y^2)^2 +4ax(x^2+y^2) -4a^2y^2 = 0 \nonumber \]

    Plot the cardiod with \(a=1\) using the code block below

    # insert your code here
     

    Surface Plots

    If we have a function of 2 variables, a surface plot is nice to use. For example, if we have the function

    \[f(x,y) = e^{-0.1(x^2+y^2)} \label{3dbell}\]

     and we want to plot it from -3 to 3 in both directions, if we define

    f(x,y)=exp(-0.1*(x^2+y^2))
    x = y = range(-5, stop = 5, length = 40)
     
    -5.0:0.2564102564102564:5.0

    and then plot with

    surface(x,y, f, legend = false)
    UndefVarError: surface not defined
    
    Stacktrace:
     [1] top-level scope at In[2]:1
     [2] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091

    Exercise

    Produce a surface plot of the function \(f(x,y)=\sin x \cos y\) for \(0\leq x \leq 2\pi, 0\leq y \leq 2\pi\) using the code block below

    # insert your code here
     

    Heat Maps

    A heat map is a 2-dimensional version of a surface plot in which the height of each value is given a color.  The following produces a heat map of the function in \ref{3dbell}

    heatmap(x,y,f)
    UndefVarError: heatmap not defined
    
    Stacktrace:
     [1] top-level scope at In[2]:1
     [2] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091

    Exercise 

    Produce a surface plot of the function \(f(x,y)=\sin x \cos y\) for \(0\leq x \leq 2\pi, 0\leq y \leq 2\pi\) using the code block below

    # Insert your code here
     

     


    11.3: Other Function Plots is shared under a not declared license and was authored, remixed, and/or curated by LibreTexts.

    • Was this article helpful?