1153 lines
97 KiB
HTML
1153 lines
97 KiB
HTML
<!DOCTYPE html>
|
||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
|
||
|
||
<meta charset="utf-8">
|
||
<meta name="generator" content="quarto-1.0.32">
|
||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
|
||
|
||
|
||
<title>Calculus with Julia - 58 2D and 3D plots in Julia with Plots</title>
|
||
<style>
|
||
code{white-space: pre-wrap;}
|
||
span.smallcaps{font-variant: small-caps;}
|
||
span.underline{text-decoration: underline;}
|
||
div.column{display: inline-block; vertical-align: top; width: 50%;}
|
||
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
|
||
ul.task-list{list-style: none;}
|
||
pre > code.sourceCode { white-space: pre; position: relative; }
|
||
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
|
||
pre > code.sourceCode > span:empty { height: 1.2em; }
|
||
.sourceCode { overflow: visible; }
|
||
code.sourceCode > span { color: inherit; text-decoration: inherit; }
|
||
div.sourceCode { margin: 1em 0; }
|
||
pre.sourceCode { margin: 0; }
|
||
@media screen {
|
||
div.sourceCode { overflow: auto; }
|
||
}
|
||
@media print {
|
||
pre > code.sourceCode { white-space: pre-wrap; }
|
||
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
|
||
}
|
||
pre.numberSource code
|
||
{ counter-reset: source-line 0; }
|
||
pre.numberSource code > span
|
||
{ position: relative; left: -4em; counter-increment: source-line; }
|
||
pre.numberSource code > span > a:first-child::before
|
||
{ content: counter(source-line);
|
||
position: relative; left: -1em; text-align: right; vertical-align: baseline;
|
||
border: none; display: inline-block;
|
||
-webkit-touch-callout: none; -webkit-user-select: none;
|
||
-khtml-user-select: none; -moz-user-select: none;
|
||
-ms-user-select: none; user-select: none;
|
||
padding: 0 4px; width: 4em;
|
||
color: #aaaaaa;
|
||
}
|
||
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
|
||
div.sourceCode
|
||
{ }
|
||
@media screen {
|
||
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
|
||
}
|
||
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
|
||
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
|
||
code span.at { color: #7d9029; } /* Attribute */
|
||
code span.bn { color: #40a070; } /* BaseN */
|
||
code span.bu { } /* BuiltIn */
|
||
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
|
||
code span.ch { color: #4070a0; } /* Char */
|
||
code span.cn { color: #880000; } /* Constant */
|
||
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
|
||
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
|
||
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
|
||
code span.dt { color: #902000; } /* DataType */
|
||
code span.dv { color: #40a070; } /* DecVal */
|
||
code span.er { color: #ff0000; font-weight: bold; } /* Error */
|
||
code span.ex { } /* Extension */
|
||
code span.fl { color: #40a070; } /* Float */
|
||
code span.fu { color: #06287e; } /* Function */
|
||
code span.im { } /* Import */
|
||
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
|
||
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
|
||
code span.op { color: #666666; } /* Operator */
|
||
code span.ot { color: #007020; } /* Other */
|
||
code span.pp { color: #bc7a00; } /* Preprocessor */
|
||
code span.sc { color: #4070a0; } /* SpecialChar */
|
||
code span.ss { color: #bb6688; } /* SpecialString */
|
||
code span.st { color: #4070a0; } /* String */
|
||
code span.va { color: #19177c; } /* Variable */
|
||
code span.vs { color: #4070a0; } /* VerbatimString */
|
||
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
|
||
</style>
|
||
|
||
|
||
<script src="../site_libs/quarto-nav/quarto-nav.js"></script>
|
||
<script src="../site_libs/quarto-nav/headroom.min.js"></script>
|
||
<script src="../site_libs/clipboard/clipboard.min.js"></script>
|
||
<script src="../site_libs/quarto-search/autocomplete.umd.js"></script>
|
||
<script src="../site_libs/quarto-search/fuse.min.js"></script>
|
||
<script src="../site_libs/quarto-search/quarto-search.js"></script>
|
||
<meta name="quarto:offset" content="../">
|
||
<link href="../integral_vector_calculus/double_triple_integrals.html" rel="next">
|
||
<link href="../differentiable_vector_calculus/vector_fields.html" rel="prev">
|
||
<script src="../site_libs/quarto-html/quarto.js"></script>
|
||
<script src="../site_libs/quarto-html/popper.min.js"></script>
|
||
<script src="../site_libs/quarto-html/tippy.umd.min.js"></script>
|
||
<script src="../site_libs/quarto-html/anchor.min.js"></script>
|
||
<link href="../site_libs/quarto-html/tippy.css" rel="stylesheet">
|
||
<link href="../site_libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles">
|
||
<script src="../site_libs/bootstrap/bootstrap.min.js"></script>
|
||
<link href="../site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
|
||
<link href="../site_libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light">
|
||
<script id="quarto-search-options" type="application/json">{
|
||
"location": "navbar",
|
||
"copy-button": false,
|
||
"collapse-after": 3,
|
||
"panel-placement": "end",
|
||
"type": "overlay",
|
||
"limit": 20,
|
||
"language": {
|
||
"search-no-results-text": "No results",
|
||
"search-matching-documents-text": "matching documents",
|
||
"search-copy-link-title": "Copy link to search",
|
||
"search-hide-matches-text": "Hide additional matches",
|
||
"search-more-match-text": "more match in this document",
|
||
"search-more-matches-text": "more matches in this document",
|
||
"search-clear-button-title": "Clear",
|
||
"search-detached-cancel-button-title": "Cancel",
|
||
"search-submit-button-title": "Submit"
|
||
}
|
||
}</script>
|
||
<script async="" src="https://hypothes.is/embed.js"></script>
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" integrity="sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg==" crossorigin="anonymous"></script>
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous"></script>
|
||
<script type="application/javascript">define('jquery', [],function() {return window.jQuery;})</script>
|
||
|
||
<script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js" type="text/javascript"></script>
|
||
|
||
</head>
|
||
|
||
<body class="nav-sidebar floating nav-fixed">
|
||
|
||
<div id="quarto-search-results"></div>
|
||
<header id="quarto-header" class="headroom fixed-top">
|
||
<nav class="navbar navbar-expand-lg navbar-dark ">
|
||
<div class="navbar-container container-fluid">
|
||
<a class="navbar-brand" href="../index.html">
|
||
<img src="../logo.png" alt="">
|
||
<span class="navbar-title">Calculus with Julia</span>
|
||
</a>
|
||
<div id="quarto-search" class="" title="Search"></div>
|
||
</div> <!-- /container-fluid -->
|
||
</nav>
|
||
<nav class="quarto-secondary-nav" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar" aria-controls="quarto-sidebar" aria-expanded="false" aria-label="Toggle sidebar navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
|
||
<div class="container-fluid d-flex justify-content-between">
|
||
<h1 class="quarto-secondary-nav-title"><span class="chapter-number">58</span> <span class="chapter-title">2D and 3D plots in Julia with Plots</span></h1>
|
||
<button type="button" class="quarto-btn-toggle btn" aria-label="Show secondary navigation">
|
||
<i class="bi bi-chevron-right"></i>
|
||
</button>
|
||
</div>
|
||
</nav>
|
||
</header>
|
||
<!-- content -->
|
||
<div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article page-navbar">
|
||
<!-- sidebar -->
|
||
<nav id="quarto-sidebar" class="sidebar collapse sidebar-navigation floating overflow-auto">
|
||
<div class="mt-2 flex-shrink-0 align-items-center">
|
||
<div class="sidebar-search">
|
||
<div id="quarto-search" class="" title="Search"></div>
|
||
</div>
|
||
</div>
|
||
<div class="sidebar-menu-container">
|
||
<ul class="list-unstyled mt-1">
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../index.html" class="sidebar-item-text sidebar-link">Preface</a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item sidebar-item-section">
|
||
<div class="sidebar-item-container">
|
||
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="false">Precalculus Concepts</a>
|
||
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-1" aria-expanded="false">
|
||
<i class="bi bi-chevron-right ms-2"></i>
|
||
</a>
|
||
</div>
|
||
<ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 ">
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../precalc/calculator.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">1</span> <span class="chapter-title">From calculator to computer</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../precalc/variables.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">2</span> <span class="chapter-title">Variables</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../precalc/numbers_types.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">3</span> <span class="chapter-title">Number systems</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../precalc/logical_expressions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">4</span> <span class="chapter-title">Inequalities, Logical expressions</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../precalc/vectors.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">5</span> <span class="chapter-title">Vectors</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../precalc/ranges.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">6</span> <span class="chapter-title">Ranges and Sets</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../precalc/functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">7</span> <span class="chapter-title">Functions</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../precalc/plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">8</span> <span class="chapter-title">The Graph of a Function</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../precalc/transformations.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">9</span> <span class="chapter-title">Function manipulations</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../precalc/inversefunctions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">10</span> <span class="chapter-title">The Inverse of a Function</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../precalc/polynomial.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">11</span> <span class="chapter-title">Polynomials</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../precalc/polynomial_roots.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">12</span> <span class="chapter-title">Roots of a polynomial</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../precalc/polynomials_package.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">13</span> <span class="chapter-title">The Polynomials package</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../precalc/rational_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">14</span> <span class="chapter-title">Rational functions</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../precalc/exp_log_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">15</span> <span class="chapter-title">Exponential and logarithmic functions</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../precalc/trig_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">16</span> <span class="chapter-title">Trigonometric functions</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../precalc/julia_overview.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">17</span> <span class="chapter-title">Overview of Julia commands</span></a>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li class="sidebar-item sidebar-item-section">
|
||
<div class="sidebar-item-container">
|
||
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" aria-expanded="false">Limits</a>
|
||
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-2" aria-expanded="false">
|
||
<i class="bi bi-chevron-right ms-2"></i>
|
||
</a>
|
||
</div>
|
||
<ul id="quarto-sidebar-section-2" class="collapse list-unstyled sidebar-section depth1 ">
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../limits/limits.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">18</span> <span class="chapter-title">Limits</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../limits/limits_extensions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">19</span> <span class="chapter-title">Limits, issues, extensions of the concept</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../limits/continuity.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">20</span> <span class="chapter-title">Continuity</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../limits/intermediate_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">21</span> <span class="chapter-title">Implications of continuity</span></a>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li class="sidebar-item sidebar-item-section">
|
||
<div class="sidebar-item-container">
|
||
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" aria-expanded="false">Derivatives</a>
|
||
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-3" aria-expanded="false">
|
||
<i class="bi bi-chevron-right ms-2"></i>
|
||
</a>
|
||
</div>
|
||
<ul id="quarto-sidebar-section-3" class="collapse list-unstyled sidebar-section depth1 ">
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../derivatives/derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">22</span> <span class="chapter-title">Derivatives</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../derivatives/numeric_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">23</span> <span class="chapter-title">Numeric derivatives</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../derivatives/symbolic_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">24</span> <span class="chapter-title">Symbolic derivatives</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../derivatives/mean_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">25</span> <span class="chapter-title">The mean value theorem for differentiable functions.</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../derivatives/optimization.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">26</span> <span class="chapter-title">Optimization</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../derivatives/first_second_derivatives.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">27</span> <span class="chapter-title">The first and second derivatives</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../derivatives/curve_sketching.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">28</span> <span class="chapter-title">Curve Sketching</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../derivatives/linearization.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">29</span> <span class="chapter-title">Linearization</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../derivatives/newtons_method.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">30</span> <span class="chapter-title">Newton’s method</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../derivatives/more_zeros.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">31</span> <span class="chapter-title">Derivative-free alternatives to Newton’s method</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../derivatives/lhospitals_rule.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">32</span> <span class="chapter-title">L’Hospital’s Rule</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../derivatives/implicit_differentiation.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">33</span> <span class="chapter-title">Implicit Differentiation</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../derivatives/related_rates.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">34</span> <span class="chapter-title">Related rates</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../derivatives/taylor_series_polynomials.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">35</span> <span class="chapter-title">Taylor Polynomials and other Approximating Polynomials</span></a>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li class="sidebar-item sidebar-item-section">
|
||
<div class="sidebar-item-container">
|
||
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-4" aria-expanded="false">Integrals</a>
|
||
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-4" aria-expanded="false">
|
||
<i class="bi bi-chevron-right ms-2"></i>
|
||
</a>
|
||
</div>
|
||
<ul id="quarto-sidebar-section-4" class="collapse list-unstyled sidebar-section depth1 ">
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../integrals/area.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">36</span> <span class="chapter-title">Area under a curve</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../integrals/ftc.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">37</span> <span class="chapter-title">Fundamental Theorem or Calculus</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../integrals/substitution.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">38</span> <span class="chapter-title">Substitution</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../integrals/integration_by_parts.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">39</span> <span class="chapter-title">Integration By Parts</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../integrals/partial_fractions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">40</span> <span class="chapter-title">Partial Fractions</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../integrals/improper_integrals.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">41</span> <span class="chapter-title">Improper Integrals</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../integrals/mean_value_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">42</span> <span class="chapter-title">Mean value theorem for integrals</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../integrals/area_between_curves.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">43</span> <span class="chapter-title">Area between two curves</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../integrals/center_of_mass.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">44</span> <span class="chapter-title">Center of Mass</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../integrals/volumes_slice.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">45</span> <span class="chapter-title">Volumes by slicing</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../integrals/arc_length.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">46</span> <span class="chapter-title">Arc length</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../integrals/surface_area.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">47</span> <span class="chapter-title">Surface Area</span></a>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li class="sidebar-item sidebar-item-section">
|
||
<div class="sidebar-item-container">
|
||
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-5" aria-expanded="false">ODEs</a>
|
||
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-5" aria-expanded="false">
|
||
<i class="bi bi-chevron-right ms-2"></i>
|
||
</a>
|
||
</div>
|
||
<ul id="quarto-sidebar-section-5" class="collapse list-unstyled sidebar-section depth1 ">
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../ODEs/odes.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">48</span> <span class="chapter-title">ODEs</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../ODEs/euler.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">49</span> <span class="chapter-title">Euler’s method</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../ODEs/solve.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">50</span> <span class="chapter-title">The problem-algorithm-solve interface</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../ODEs/differential_equations.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">51</span> <span class="chapter-title">The <code>DifferentialEquations</code> suite</span></a>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li class="sidebar-item sidebar-item-section">
|
||
<div class="sidebar-item-container">
|
||
<a class="sidebar-item-text sidebar-link text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-6" aria-expanded="true">Differential vector calculus</a>
|
||
<a class="sidebar-item-toggle text-start" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-6" aria-expanded="true">
|
||
<i class="bi bi-chevron-right ms-2"></i>
|
||
</a>
|
||
</div>
|
||
<ul id="quarto-sidebar-section-6" class="collapse list-unstyled sidebar-section depth1 show">
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../differentiable_vector_calculus/polar_coordinates.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">52</span> <span class="chapter-title">Polar Coordinates and Curves</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../differentiable_vector_calculus/vectors.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">53</span> <span class="chapter-title">Vectors and matrices</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../differentiable_vector_calculus/vector_valued_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">54</span> <span class="chapter-title">Vector-valued functions, <span class="math inline">\(f:R \rightarrow R^n\)</span></span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../differentiable_vector_calculus/scalar_functions.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">55</span> <span class="chapter-title">Scalar functions</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../differentiable_vector_calculus/scalar_functions_applications.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">56</span> <span class="chapter-title">Applications with scalar functions</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../differentiable_vector_calculus/vector_fields.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">57</span> <span class="chapter-title">Functions <span class="math inline">\(R^n \rightarrow R^m\)</span></span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../differentiable_vector_calculus/plots_plotting.html" class="sidebar-item-text sidebar-link active"><span class="chapter-number">58</span> <span class="chapter-title">2D and 3D plots in Julia with Plots</span></a>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li class="sidebar-item sidebar-item-section">
|
||
<div class="sidebar-item-container">
|
||
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-7" aria-expanded="false">Integral vector calculus</a>
|
||
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-7" aria-expanded="false">
|
||
<i class="bi bi-chevron-right ms-2"></i>
|
||
</a>
|
||
</div>
|
||
<ul id="quarto-sidebar-section-7" class="collapse list-unstyled sidebar-section depth1 ">
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../integral_vector_calculus/double_triple_integrals.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">59</span> <span class="chapter-title">Multi-dimensional integrals</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../integral_vector_calculus/line_integrals.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">60</span> <span class="chapter-title">Line and Surface Integrals</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../integral_vector_calculus/div_grad_curl.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">61</span> <span class="chapter-title">The Gradient, Divergence, and Curl</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../integral_vector_calculus/stokes_theorem.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">62</span> <span class="chapter-title">Green’s Theorem, Stokes’ Theorem, and the Divergence Theorem</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../integral_vector_calculus/review.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">63</span> <span class="chapter-title">Quick Review of Vector Calculus</span></a>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li class="sidebar-item sidebar-item-section">
|
||
<div class="sidebar-item-container">
|
||
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-8" aria-expanded="false">Alternatives</a>
|
||
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-8" aria-expanded="false">
|
||
<i class="bi bi-chevron-right ms-2"></i>
|
||
</a>
|
||
</div>
|
||
<ul id="quarto-sidebar-section-8" class="collapse list-unstyled sidebar-section depth1 ">
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../alternatives/plotly_plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">64</span> <span class="chapter-title">JavaScript based plotting libraries</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../alternatives/makie_plotting.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">65</span> <span class="chapter-title">Calculus plots with Makie</span></a>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li class="sidebar-item sidebar-item-section">
|
||
<div class="sidebar-item-container">
|
||
<a class="sidebar-item-text sidebar-link text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-9" aria-expanded="false">Appendices</a>
|
||
<a class="sidebar-item-toggle text-start collapsed" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar-section-9" aria-expanded="false">
|
||
<i class="bi bi-chevron-right ms-2"></i>
|
||
</a>
|
||
</div>
|
||
<ul id="quarto-sidebar-section-9" class="collapse list-unstyled sidebar-section depth1 ">
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../misc/getting_started_with_julia.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">66</span> <span class="chapter-title">Getting started with Julia</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../misc/julia_interfaces.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">67</span> <span class="chapter-title">Julia interfaces</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../misc/calculus_with_julia.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">68</span> <span class="chapter-title">The <code>CalculusWithJulia</code> package</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../misc/unicode.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">69</span> <span class="chapter-title">Usages of Unicode symbols</span></a>
|
||
</div>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../misc/quick_notes.html" class="sidebar-item-text sidebar-link"><span class="chapter-number">70</span> <span class="chapter-title">Quick introduction to Calculus with Julia</span></a>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li class="sidebar-item">
|
||
<div class="sidebar-item-container">
|
||
<a href="../references.html" class="sidebar-item-text sidebar-link">References</a>
|
||
</div>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</nav>
|
||
<!-- margin-sidebar -->
|
||
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
|
||
<nav id="TOC" role="doc-toc">
|
||
<h2 id="toc-title">Table of contents</h2>
|
||
|
||
<ul>
|
||
<li><a href="#parametrically-described-curves-in-space" id="toc-parametrically-described-curves-in-space" class="nav-link active" data-scroll-target="#parametrically-described-curves-in-space"> <span class="header-section-number">58.1</span> Parametrically described curves in space</a>
|
||
<ul class="collapse">
|
||
<li><a href="#plotting-a-space-curve-in-3-dimensions" id="toc-plotting-a-space-curve-in-3-dimensions" class="nav-link" data-scroll-target="#plotting-a-space-curve-in-3-dimensions"> <span class="header-section-number">58.1.1</span> Plotting a space curve in 3 dimensions</a></li>
|
||
<li><a href="#adding-a-vector" id="toc-adding-a-vector" class="nav-link" data-scroll-target="#adding-a-vector"> <span class="header-section-number">58.1.2</span> Adding a vector</a></li>
|
||
<li><a href="#setting-a-viewing-angle-for-3d-plots" id="toc-setting-a-viewing-angle-for-3d-plots" class="nav-link" data-scroll-target="#setting-a-viewing-angle-for-3d-plots"> <span class="header-section-number">58.1.3</span> Setting a viewing angle for 3D plots</a></li>
|
||
</ul></li>
|
||
<li><a href="#visualizing-functions-from-r2-rightarrow-r" id="toc-visualizing-functions-from-r2-rightarrow-r" class="nav-link" data-scroll-target="#visualizing-functions-from-r2-rightarrow-r"> <span class="header-section-number">58.2</span> Visualizing functions from <span class="math inline">\(R^2 \rightarrow R\)</span></a>
|
||
<ul class="collapse">
|
||
<li><a href="#contour-plots" id="toc-contour-plots" class="nav-link" data-scroll-target="#contour-plots"> <span class="header-section-number">58.2.1</span> Contour plots</a></li>
|
||
<li><a href="#combining-surface-plots-and-contour-plots" id="toc-combining-surface-plots-and-contour-plots" class="nav-link" data-scroll-target="#combining-surface-plots-and-contour-plots"> <span class="header-section-number">58.2.2</span> Combining surface plots and contour plots</a></li>
|
||
<li><a href="#gradient-and-surface-plots" id="toc-gradient-and-surface-plots" class="nav-link" data-scroll-target="#gradient-and-surface-plots"> <span class="header-section-number">58.2.3</span> Gradient and surface plots</a></li>
|
||
<li><a href="#the-tangent-plane" id="toc-the-tangent-plane" class="nav-link" data-scroll-target="#the-tangent-plane"> <span class="header-section-number">58.2.4</span> The tangent plane</a></li>
|
||
<li><a href="#parameterized-surface-plots" id="toc-parameterized-surface-plots" class="nav-link" data-scroll-target="#parameterized-surface-plots"> <span class="header-section-number">58.2.5</span> Parameterized surface plots</a></li>
|
||
<li><a href="#plotting-fxy-z-c" id="toc-plotting-fxy-z-c" class="nav-link" data-scroll-target="#plotting-fxy-z-c"> <span class="header-section-number">58.2.6</span> Plotting F(x,y, z) = c</a></li>
|
||
</ul></li>
|
||
</ul>
|
||
<div class="toc-actions"><div><i class="bi bi-github"></i></div><div class="action-links"><p><a href="https://github.com/jverzani/CalculusWithJuliaNotes.jl/edit/main/quarto/differentiable_vector_calculus/plots_plotting.qmd" class="toc-action">Edit this page</a></p><p><a href="https://github.com/jverzani/CalculusWithJuliaNotes.jl/issues/new" class="toc-action">Report an issue</a></p></div></div></nav>
|
||
</div>
|
||
<!-- main -->
|
||
<main class="content" id="quarto-document-content">
|
||
|
||
<header id="title-block-header" class="quarto-title-block default">
|
||
<div class="quarto-title">
|
||
<h1 class="title d-none d-lg-block"><span class="chapter-number">58</span> <span class="chapter-title">2D and 3D plots in Julia with Plots</span></h1>
|
||
</div>
|
||
|
||
|
||
|
||
<div class="quarto-title-meta">
|
||
|
||
|
||
|
||
</div>
|
||
|
||
|
||
</header>
|
||
|
||
<p>This section uses these add-on packages:</p>
|
||
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">CalculusWithJulia</span></span>
|
||
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">Plots</span></span>
|
||
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> <span class="bu">Contour</span>: contours, levels, level, lines, coordinates</span>
|
||
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">LinearAlgebra</span></span>
|
||
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="im">using</span> <span class="bu">ForwardDiff</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<hr>
|
||
<p>This covers plotting the typical 2D and 3D plots in Julia with the <code>Plots</code> package.</p>
|
||
<p>We will make use of some helper functions that will simplify plotting provided by the <code>CalculusWithJulia</code> package. As well, we will need to manipulate contours directly, so pull in the <code>Contours</code> package, using <code>import</code> to avoid name collisions and explicitly listing the methods we will use.</p>
|
||
<section id="parametrically-described-curves-in-space" class="level2" data-number="58.1">
|
||
<h2 data-number="58.1" class="anchored" data-anchor-id="parametrically-described-curves-in-space"><span class="header-section-number">58.1</span> Parametrically described curves in space</h2>
|
||
<p>Let <span class="math inline">\(r(t)\)</span> be a vector-valued function with values in <span class="math inline">\(R^d\)</span>, <span class="math inline">\(d\)</span> being <span class="math inline">\(2\)</span> or <span class="math inline">\(3\)</span>. A familiar example is the equation for a line that travels in the direction of <span class="math inline">\(\vec{v}\)</span> and goes through the point <span class="math inline">\(P\)</span>: <span class="math inline">\(r(t) = P + t \cdot \vec{v}\)</span>. A <em>parametric plot</em> over <span class="math inline">\([a,b]\)</span> is the collection of all points <span class="math inline">\(r(t)\)</span> for <span class="math inline">\(a \leq t \leq b\)</span>.</p>
|
||
<p>In <code>Plots</code>, parameterized curves can be plotted through two interfaces, here illustrated for <span class="math inline">\(d=2\)</span>: <code>plot(f1, f2, a, b)</code> or <code>plot(xs, ys)</code>. The former is convenient for some cases, but typically we will have a function <code>r(t)</code> which is vector-valued, as opposed to a vector of functions. As such, we only discuss the latter.</p>
|
||
<p>An example helps illustrate. Suppose <span class="math inline">\(r(t) = \langle \sin(t), 2\cos(t) \rangle\)</span> and the goal is to plot the full ellipse by plotting over <span class="math inline">\(0 \leq t \leq 2\pi\)</span>. As with plotting of curves, the goal would be to take many points between <code>a</code> and <code>b</code> and from there generate the <span class="math inline">\(x\)</span> values and <span class="math inline">\(y\)</span> values.</p>
|
||
<p>Let’s see this with 5 points, the first and last being identical due to the curve:</p>
|
||
<div class="cell" data-execution_count="4">
|
||
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="fu">r₂</span>(t) <span class="op">=</span> [<span class="fu">sin</span>(t), <span class="fl">2</span><span class="fu">cos</span>(t)]</span>
|
||
<span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a>ts <span class="op">=</span> <span class="fu">range</span>(<span class="fl">0</span>, stop<span class="op">=</span><span class="fl">2</span>pi, length<span class="op">=</span><span class="fl">5</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="5">
|
||
<pre><code>0.0:1.5707963267948966:6.283185307179586</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>Then we can create the <span class="math inline">\(5\)</span> points easily through broadcasting:</p>
|
||
<div class="cell" data-execution_count="5">
|
||
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>vs <span class="op">=</span> <span class="fu">r₂</span>.(ts)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="6">
|
||
<pre><code>5-element Vector{Vector{Float64}}:
|
||
[0.0, 2.0]
|
||
[1.0, 1.2246467991473532e-16]
|
||
[1.2246467991473532e-16, -2.0]
|
||
[-1.0, -3.6739403974420594e-16]
|
||
[-2.4492935982947064e-16, 2.0]</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>This returns a vector of points (stored as vectors). The plotting function wants two collections: the set of <span class="math inline">\(x\)</span> values for the points and the set of <span class="math inline">\(y\)</span> values. The data needs to be generated differently or reshaped. The function <code>unzip</code> above takes data in this style and returns the desired format, returning a tuple with the <span class="math inline">\(x\)</span> values and <span class="math inline">\(y\)</span> values pulled out:</p>
|
||
<div class="cell" data-execution_count="6">
|
||
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="fu">unzip</span>(vs)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="7">
|
||
<pre><code>([0.0, 1.0, 1.2246467991473532e-16, -1.0, -2.4492935982947064e-16], [2.0, 1.2246467991473532e-16, -2.0, -3.6739403974420594e-16, 2.0])</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>To plot this, we “splat” the tuple so that <code>plot</code> gets the arguments separately:</p>
|
||
<div class="cell" data-execution_count="7">
|
||
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">unzip</span>(vs)<span class="op">...</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="8">
|
||
<p><img src="plots_plotting_files/figure-html/cell-8-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
<p>This basic plot is lacking, of course, as there are not enough points. Using more initially is a remedy.</p>
|
||
<div class="cell" data-hold="true" data-execution_count="8">
|
||
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>ts <span class="op">=</span> <span class="fu">range</span>(<span class="fl">0</span>, <span class="fl">2</span>pi, length<span class="op">=</span><span class="fl">100</span>)</span>
|
||
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot</span>(<span class="fu">unzip</span>(<span class="fu">r₂</span>.(ts))<span class="op">...</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="9">
|
||
<p><img src="plots_plotting_files/figure-html/cell-9-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
<p>As a convenience, <code>CalculusWithJulia</code> provides <code>plot_parametric</code> to produce this plot. The interval is specified with the <code>a..b</code> notation of <code>IntervalSets</code> (which is available when the <code>CalculusWithJulia</code> package is loaded), the points to plot are adaptively chosen:</p>
|
||
<div class="cell" data-execution_count="9">
|
||
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot_parametric</span>(<span class="fl">0</span><span class="op">..</span><span class="fl">2</span>pi, r₂) <span class="co"># interval first</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="10">
|
||
<p><img src="plots_plotting_files/figure-html/cell-10-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
<section id="plotting-a-space-curve-in-3-dimensions" class="level3" data-number="58.1.1">
|
||
<h3 data-number="58.1.1" class="anchored" data-anchor-id="plotting-a-space-curve-in-3-dimensions"><span class="header-section-number">58.1.1</span> Plotting a space curve in 3 dimensions</h3>
|
||
<p>A parametrically described curve in 3D is similarly created. For example, a helix is described mathematically by <span class="math inline">\(r(t) = \langle \sin(t), \cos(t), t \rangle\)</span>. Here we graph two turns:</p>
|
||
<div class="cell" data-execution_count="10">
|
||
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="fu">r₃</span>(t) <span class="op">=</span> [<span class="fu">sin</span>(t), <span class="fu">cos</span>(t), t]</span>
|
||
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot_parametric</span>(<span class="fl">0</span><span class="op">..</span><span class="fl">4</span>pi, r₃)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="11">
|
||
<p><img src="plots_plotting_files/figure-html/cell-11-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="adding-a-vector" class="level3" data-number="58.1.2">
|
||
<h3 data-number="58.1.2" class="anchored" data-anchor-id="adding-a-vector"><span class="header-section-number">58.1.2</span> Adding a vector</h3>
|
||
<p>The tangent vector indicates the instantaneous direction one would travel were they walking along the space curve. We can add a tangent vector to the graph. The <code>quiver!</code> function would be used to add a 2D vector, but <code>Plots</code> does not currently have a <code>3D</code> analog. In addition, <code>quiver!</code> has a somewhat cumbersome calling pattern when adding just one vector. The <code>CalculusWithJulia</code> package defines an <code>arrow!</code> function that uses <code>quiver</code> for 2D arrows and a simple line for 3D arrows. As a vector incorporates magnitude and direction, but not a position, <code>arrow!</code> needs both a point for the position and a vector.</p>
|
||
<p>Here is how we can visualize the tangent vector at a few points on the helix:</p>
|
||
<div class="sourceCode cell-code" id="cb12"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="fu">plot_parametric</span>(<span class="fl">0</span><span class="op">..</span><span class="fl">4</span>pi, r₃, legend<span class="op">=</span><span class="cn">false</span>)</span>
|
||
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a>ts <span class="op">=</span> <span class="fu">range</span>(<span class="fl">0</span>, <span class="fl">4</span>pi, length<span class="op">=</span><span class="fl">5</span>)</span>
|
||
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> t <span class="kw">in</span> ts</span>
|
||
<span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a> <span class="fu">arrow!</span>(<span class="fu">r₃</span>(t), r₃<span class="op">'</span>(t))</span>
|
||
<span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a><span class="cf">end</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell" data-execution_count="12">
|
||
<div class="cell-output cell-output-display" data-execution_count="13">
|
||
<div class="markdown"><div class="admonition info"><p class="admonition-title">Info</p><p>Adding many arrows this way would be inefficient.</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="setting-a-viewing-angle-for-3d-plots" class="level3" data-number="58.1.3">
|
||
<h3 data-number="58.1.3" class="anchored" data-anchor-id="setting-a-viewing-angle-for-3d-plots"><span class="header-section-number">58.1.3</span> Setting a viewing angle for 3D plots</h3>
|
||
<p>For 3D plots, the viewing angle can make the difference in visualizing the key features. In <code>Plots</code>, some backends allow the viewing angle to be set with the mouse by clicking and dragging. Not all do. For such, the <code>camera</code> argument is used, as in <code>camera(azimuthal, elevation)</code> where the angles are given in degrees. If the <span class="math inline">\(x\)</span>-<span class="math inline">\(y\)</span>-<span class="math inline">\(z\)</span> coorinates are given, then <code>elevation</code> or <em>inclination</em>, is the angle between the <span class="math inline">\(z\)</span> axis and the <span class="math inline">\(x-y\)</span> plane (so <code>90</code> is a top view) and <code>azimuthal</code> is the angle in the <span class="math inline">\(x-y\)</span> plane from the <span class="math inline">\(x\)</span> axes.</p>
|
||
</section>
|
||
</section>
|
||
<section id="visualizing-functions-from-r2-rightarrow-r" class="level2" data-number="58.2">
|
||
<h2 data-number="58.2" class="anchored" data-anchor-id="visualizing-functions-from-r2-rightarrow-r"><span class="header-section-number">58.2</span> Visualizing functions from <span class="math inline">\(R^2 \rightarrow R\)</span></h2>
|
||
<p>If a function <span class="math inline">\(f: R^2 \rightarrow R\)</span> then a graph of <span class="math inline">\((x,y,f(x,y))\)</span> can be represented in 3D. It will form a surface. Such graphs can be most simply made by specifying a set of <span class="math inline">\(x\)</span> values, a set of <span class="math inline">\(y\)</span> values and a function <span class="math inline">\(f\)</span>, as with:</p>
|
||
<div class="cell" data-execution_count="13">
|
||
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">2</span>, stop<span class="op">=</span><span class="fl">2</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
|
||
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a>ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="cn">pi</span>, stop<span class="op">=</span><span class="cn">pi</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
|
||
<span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> <span class="fu">x*sin</span>(y)</span>
|
||
<span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(xs, ys, f)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="14">
|
||
<p><img src="plots_plotting_files/figure-html/cell-14-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
<p>Rather than pass in a function, values can be passed in. Here they are generated with a list comprehension. The <code>y</code> values are innermost to match the graphic when passing in a function object:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="14">
|
||
<div class="sourceCode cell-code" id="cb14"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a>zs <span class="op">=</span> [<span class="fu">f</span>(x,y) for y <span class="kw">in</span> ys, x <span class="kw">in</span> xs]</span>
|
||
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(xs, ys, zs)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="15">
|
||
<p><img src="plots_plotting_files/figure-html/cell-15-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
<p>Remembering if the <code>ys</code> or <code>xs</code> go first in the above can be hard. Alternatively, broadcasting can be used. The command <code>f.(xs,ys)</code> would return a vector, as the <code>xs</code> and <code>ys</code> match in shape–they are both column vectors. But the <em>transpose</em> of <code>xs</code> looks like a <em>row</em> vector and <code>ys</code> looks like a column vector, so broadcasting will create a matrix of values, as desired here:</p>
|
||
<div class="cell" data-execution_count="15">
|
||
<div class="sourceCode cell-code" id="cb15"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(xs, ys, <span class="fu">f</span>.(xs<span class="op">'</span>, ys))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="16">
|
||
<p><img src="plots_plotting_files/figure-html/cell-16-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
<p>This graph shows the tessalation algorithm. Here only the grid in the <span class="math inline">\(x\)</span>-<span class="math inline">\(y\)</span> plane is just one cell:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="16">
|
||
<div class="sourceCode cell-code" id="cb16"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">1</span>, <span class="fl">1</span>, length<span class="op">=</span><span class="fl">2</span>)</span>
|
||
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> x<span class="op">*</span>y</span>
|
||
<span id="cb16-3"><a href="#cb16-3" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(xs, ys, f)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="17">
|
||
<p><img src="plots_plotting_files/figure-html/cell-17-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
<p>A more accurate graph, can be seen here:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="17">
|
||
<div class="sourceCode cell-code" id="cb17"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">1</span>, <span class="fl">1</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
|
||
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> x<span class="op">*</span>y</span>
|
||
<span id="cb17-3"><a href="#cb17-3" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(xs, ys, f)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="18">
|
||
<p><img src="plots_plotting_files/figure-html/cell-18-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
<section id="contour-plots" class="level3" data-number="58.2.1">
|
||
<h3 data-number="58.2.1" class="anchored" data-anchor-id="contour-plots"><span class="header-section-number">58.2.1</span> Contour plots</h3>
|
||
<p>Returning to the</p>
|
||
<p>The contour plot of <span class="math inline">\(f:R^2 \rightarrow R\)</span> draws level curves, <span class="math inline">\(f(x,y)=c\)</span>, for different values of <span class="math inline">\(c\)</span> in the <span class="math inline">\(x-y\)</span> plane. They are produced in a similar manner as the surface plots:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="18">
|
||
<div class="sourceCode cell-code" id="cb18"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb18-1"><a href="#cb18-1" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">2</span>,<span class="fl">2</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
|
||
<span id="cb18-2"><a href="#cb18-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> x<span class="op">*</span>y</span>
|
||
<span id="cb18-3"><a href="#cb18-3" aria-hidden="true" tabindex="-1"></a><span class="fu">contour</span>(xs, ys, f)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="19">
|
||
<p><img src="plots_plotting_files/figure-html/cell-19-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
<p>The cross in the middle corresponds to <span class="math inline">\(c=0\)</span>, as when <span class="math inline">\(x=0\)</span> or <span class="math inline">\(y=0\)</span> then <span class="math inline">\(f(x,y)=0\)</span>.</p>
|
||
<p>Similarly, computed values for <span class="math inline">\(f(x,y)\)</span> can be passed in. Here we change the function:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="19">
|
||
<div class="sourceCode cell-code" id="cb19"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> <span class="fl">2</span> <span class="op">-</span> (x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">2</span>)</span>
|
||
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">2</span>,<span class="fl">2</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
|
||
<span id="cb19-3"><a href="#cb19-3" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb19-4"><a href="#cb19-4" aria-hidden="true" tabindex="-1"></a>zs <span class="op">=</span> [<span class="fu">f</span>(x,y) for y <span class="kw">in</span> ys, x <span class="kw">in</span> xs]</span>
|
||
<span id="cb19-5"><a href="#cb19-5" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb19-6"><a href="#cb19-6" aria-hidden="true" tabindex="-1"></a><span class="fu">contour</span>(xs, ys, zs)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="20">
|
||
<p><img src="plots_plotting_files/figure-html/cell-20-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
<p>The chosen levels can be specified by the user through the <code>levels</code> argument, as in:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="20">
|
||
<div class="sourceCode cell-code" id="cb20"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb20-1"><a href="#cb20-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> <span class="fl">2</span> <span class="op">-</span> (x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">2</span>)</span>
|
||
<span id="cb20-2"><a href="#cb20-2" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">2</span>,<span class="fl">2</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
|
||
<span id="cb20-3"><a href="#cb20-3" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb20-4"><a href="#cb20-4" aria-hidden="true" tabindex="-1"></a>zs <span class="op">=</span> [<span class="fu">f</span>(x,y) for y <span class="kw">in</span> ys, x <span class="kw">in</span> xs]</span>
|
||
<span id="cb20-5"><a href="#cb20-5" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb20-6"><a href="#cb20-6" aria-hidden="true" tabindex="-1"></a><span class="fu">contour</span>(xs, ys, zs, levels <span class="op">=</span> [<span class="op">-</span><span class="fl">1.0</span>, <span class="fl">0.0</span>, <span class="fl">1.0</span>])</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="21">
|
||
<p><img src="plots_plotting_files/figure-html/cell-21-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
<p>If only a single level is desired, as scalar value can be specified. Though not with all backends for <code>Plots</code>. For example, this next graphic shows the <span class="math inline">\(0\)</span>-level of the <a href="http://www-groups.dcs.st-and.ac.uk/~history/Curves/Devils.html">devil</a>’s curve.</p>
|
||
<div class="cell" data-hold="true" data-execution_count="21">
|
||
<div class="sourceCode cell-code" id="cb21"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb21-1"><a href="#cb21-1" aria-hidden="true" tabindex="-1"></a>a, b <span class="op">=</span> <span class="op">-</span><span class="fl">1</span>, <span class="fl">2</span></span>
|
||
<span id="cb21-2"><a href="#cb21-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> y<span class="op">^</span><span class="fl">4</span> <span class="op">-</span> x<span class="op">^</span><span class="fl">4</span> <span class="op">+</span> a<span class="op">*</span>y<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> b<span class="op">*</span>x<span class="op">^</span><span class="fl">2</span></span>
|
||
<span id="cb21-3"><a href="#cb21-3" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">5</span>, stop<span class="op">=</span><span class="fl">5</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
|
||
<span id="cb21-4"><a href="#cb21-4" aria-hidden="true" tabindex="-1"></a><span class="fu">contour</span>(xs, ys, f, levels<span class="op">=</span>[<span class="fl">0.0</span>])</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="22">
|
||
<p><img src="plots_plotting_files/figure-html/cell-22-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
<p>Contour plots are well known from the presence of contour lines on many maps. Contour lines indicate constant elevations. A peak is characterized by a series of nested closed paths. The following graph shows this for the peak at <span class="math inline">\((x,y)=(0,0)\)</span>.</p>
|
||
<div class="cell" data-hold="true" data-execution_count="22">
|
||
<div class="sourceCode cell-code" id="cb22"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>, stop<span class="op">=</span><span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
|
||
<span id="cb22-2"><a href="#cb22-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> <span class="fu">sinc</span>(<span class="fu">sqrt</span>(x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">2</span>)) <span class="co"># sinc(x) is sin(x)/x</span></span>
|
||
<span id="cb22-3"><a href="#cb22-3" aria-hidden="true" tabindex="-1"></a><span class="fu">contour</span>(xs, ys, f)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="23">
|
||
<p><img src="plots_plotting_files/figure-html/cell-23-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
<p>Contour plots can be filled with colors through the <code>contourf</code> function:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="23">
|
||
<div class="sourceCode cell-code" id="cb23"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb23-1"><a href="#cb23-1" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>, stop<span class="op">=</span><span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
|
||
<span id="cb23-2"><a href="#cb23-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> <span class="fu">sinc</span>(<span class="fu">sqrt</span>(x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">2</span>))</span>
|
||
<span id="cb23-3"><a href="#cb23-3" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb23-4"><a href="#cb23-4" aria-hidden="true" tabindex="-1"></a><span class="fu">contourf</span>(xs, ys, f)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="24">
|
||
<p><img src="plots_plotting_files/figure-html/cell-24-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="combining-surface-plots-and-contour-plots" class="level3" data-number="58.2.2">
|
||
<h3 data-number="58.2.2" class="anchored" data-anchor-id="combining-surface-plots-and-contour-plots"><span class="header-section-number">58.2.2</span> Combining surface plots and contour plots</h3>
|
||
<p>In <code>PyPlot</code> it is possible to add a contour lines to the surface, or projected onto an axis. To replicate something similar, though not as satisfying, in <code>Plots</code> we use the <code>Contour</code> package.</p>
|
||
<div class="cell" data-hold="true" data-execution_count="24">
|
||
<div class="sourceCode cell-code" id="cb24"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> <span class="fl">2</span> <span class="op">+</span> x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">2</span></span>
|
||
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">2</span>, stop<span class="op">=</span><span class="fl">2</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
|
||
<span id="cb24-3"><a href="#cb24-3" aria-hidden="true" tabindex="-1"></a>zs <span class="op">=</span> [<span class="fu">f</span>(x,y) for y <span class="kw">in</span> ys, x <span class="kw">in</span> xs]</span>
|
||
<span id="cb24-4"><a href="#cb24-4" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb24-5"><a href="#cb24-5" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> <span class="fu">surface</span>(xs, ys, zs, legend<span class="op">=</span><span class="cn">false</span>, fillalpha<span class="op">=</span><span class="fl">0.5</span>)</span>
|
||
<span id="cb24-6"><a href="#cb24-6" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb24-7"><a href="#cb24-7" aria-hidden="true" tabindex="-1"></a><span class="co">## we add to the graphic p, then plot</span></span>
|
||
<span id="cb24-8"><a href="#cb24-8" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> cl <span class="kw">in</span> <span class="fu">levels</span>(<span class="fu">contours</span>(xs, ys, zs))</span>
|
||
<span id="cb24-9"><a href="#cb24-9" aria-hidden="true" tabindex="-1"></a> lvl <span class="op">=</span> <span class="fu">level</span>(cl) <span class="co"># the z-value of this contour level</span></span>
|
||
<span id="cb24-10"><a href="#cb24-10" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> line <span class="kw">in</span> <span class="fu">lines</span>(cl)</span>
|
||
<span id="cb24-11"><a href="#cb24-11" aria-hidden="true" tabindex="-1"></a> _xs, _ys <span class="op">=</span> <span class="fu">coordinates</span>(line) <span class="co"># coordinates of this line segment</span></span>
|
||
<span id="cb24-12"><a href="#cb24-12" aria-hidden="true" tabindex="-1"></a> _zs <span class="op">=</span> <span class="fl">0</span> <span class="op">*</span> _xs</span>
|
||
<span id="cb24-13"><a href="#cb24-13" aria-hidden="true" tabindex="-1"></a> <span class="fu">plot!</span>(p, _xs, _ys, lvl <span class="op">.+</span> _zs, alpha<span class="op">=</span><span class="fl">0.5</span>) <span class="co"># add on surface</span></span>
|
||
<span id="cb24-14"><a href="#cb24-14" aria-hidden="true" tabindex="-1"></a> <span class="fu">plot!</span>(p, _xs, _ys, _zs, alpha<span class="op">=</span><span class="fl">0.5</span>) <span class="co"># add on x-y plane</span></span>
|
||
<span id="cb24-15"><a href="#cb24-15" aria-hidden="true" tabindex="-1"></a> <span class="cf">end</span></span>
|
||
<span id="cb24-16"><a href="#cb24-16" aria-hidden="true" tabindex="-1"></a><span class="cf">end</span></span>
|
||
<span id="cb24-17"><a href="#cb24-17" aria-hidden="true" tabindex="-1"></a>p</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="25">
|
||
<p><img src="plots_plotting_files/figure-html/cell-25-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
<p>There is no hidden line calculuation, in place we give the contour lines a transparency through the argument <code>alpha=0.5</code>.</p>
|
||
</section>
|
||
<section id="gradient-and-surface-plots" class="level3" data-number="58.2.3">
|
||
<h3 data-number="58.2.3" class="anchored" data-anchor-id="gradient-and-surface-plots"><span class="header-section-number">58.2.3</span> Gradient and surface plots</h3>
|
||
<p>The surface plot of <span class="math inline">\(f: R^2 \rightarrow R\)</span> plots <span class="math inline">\((x, y, f(x,y))\)</span> as a surface. The <em>gradient</em> of <span class="math inline">\(f\)</span> is <span class="math inline">\(\langle \partial f/\partial x, \partial f/\partial y\rangle\)</span>. It is a two-dimensional object indicating the direction at a point <span class="math inline">\((x,y)\)</span> where the surface has the greatest ascent. Illurating the gradient and the surface on the same plot requires embedding the 2D gradient into the 3D surface. This can be done by adding a constant <span class="math inline">\(z\)</span> value to the gradient, such as <span class="math inline">\(0\)</span>.</p>
|
||
<div class="cell" data-hold="true" data-execution_count="25">
|
||
<div class="sourceCode cell-code" id="cb25"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb25-1"><a href="#cb25-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> <span class="fl">2</span> <span class="op">-</span> (x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">2</span>)</span>
|
||
<span id="cb25-2"><a href="#cb25-2" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">2</span>, stop<span class="op">=</span><span class="fl">2</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
|
||
<span id="cb25-3"><a href="#cb25-3" aria-hidden="true" tabindex="-1"></a>zs <span class="op">=</span> [<span class="fu">f</span>(x,y) for y <span class="kw">in</span> ys, x <span class="kw">in</span> xs]</span>
|
||
<span id="cb25-4"><a href="#cb25-4" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb25-5"><a href="#cb25-5" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(xs, ys, zs, camera<span class="op">=</span>(<span class="fl">40</span>, <span class="fl">25</span>), legend<span class="op">=</span><span class="cn">false</span>)</span>
|
||
<span id="cb25-6"><a href="#cb25-6" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> [<span class="op">-</span><span class="fl">1</span>, <span class="fl">1</span>] <span class="co"># in the region graphed, [-2,2] × [-2, 2]</span></span>
|
||
<span id="cb25-7"><a href="#cb25-7" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb25-8"><a href="#cb25-8" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x) <span class="op">=</span> <span class="fu">f</span>(x<span class="op">...</span>)</span>
|
||
<span id="cb25-9"><a href="#cb25-9" aria-hidden="true" tabindex="-1"></a>v <span class="op">=</span> ForwardDiff.<span class="fu">gradient</span>(f, p)</span>
|
||
<span id="cb25-10"><a href="#cb25-10" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb25-11"><a href="#cb25-11" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb25-12"><a href="#cb25-12" aria-hidden="true" tabindex="-1"></a><span class="co"># add 0 to p and v (two styles)</span></span>
|
||
<span id="cb25-13"><a href="#cb25-13" aria-hidden="true" tabindex="-1"></a><span class="fu">push!</span>(p, <span class="op">-</span><span class="fl">15</span>)</span>
|
||
<span id="cb25-14"><a href="#cb25-14" aria-hidden="true" tabindex="-1"></a><span class="fu">scatter!</span>(<span class="fu">unzip</span>([p])<span class="op">...</span>, markersize<span class="op">=</span><span class="fl">3</span>)</span>
|
||
<span id="cb25-15"><a href="#cb25-15" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb25-16"><a href="#cb25-16" aria-hidden="true" tabindex="-1"></a>v <span class="op">=</span> <span class="fu">vcat</span>(v, <span class="fl">0</span>)</span>
|
||
<span id="cb25-17"><a href="#cb25-17" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(p, v)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="26">
|
||
<p><img src="plots_plotting_files/figure-html/cell-26-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="the-tangent-plane" class="level3" data-number="58.2.4">
|
||
<h3 data-number="58.2.4" class="anchored" data-anchor-id="the-tangent-plane"><span class="header-section-number">58.2.4</span> The tangent plane</h3>
|
||
<p>Let <span class="math inline">\(z = f(x,y)\)</span> describe a surface, and <span class="math inline">\(F(x,y,z) = f(x,y) - z\)</span>. The the gradient of <span class="math inline">\(F\)</span> at a point <span class="math inline">\(p\)</span> on the surface, <span class="math inline">\(\nabla F(p)\)</span>, will be normal to the surface and for a function, <span class="math inline">\(f(p) + \nabla f \cdot (x-p)\)</span> describes the tangent plane. We can visualize each, as follows:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="26">
|
||
<div class="sourceCode cell-code" id="cb26"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb26-1"><a href="#cb26-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y) <span class="op">=</span> <span class="fl">2</span> <span class="op">-</span> x<span class="op">^</span><span class="fl">2</span> <span class="op">-</span> y<span class="op">^</span><span class="fl">2</span></span>
|
||
<span id="cb26-2"><a href="#cb26-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(v) <span class="op">=</span> <span class="fu">f</span>(v<span class="op">...</span>)</span>
|
||
<span id="cb26-3"><a href="#cb26-3" aria-hidden="true" tabindex="-1"></a><span class="fu">F</span>(x,y,z) <span class="op">=</span> z <span class="op">-</span> <span class="fu">f</span>(x,y)</span>
|
||
<span id="cb26-4"><a href="#cb26-4" aria-hidden="true" tabindex="-1"></a><span class="fu">F</span>(v) <span class="op">=</span> <span class="fu">F</span>(v<span class="op">...</span>)</span>
|
||
<span id="cb26-5"><a href="#cb26-5" aria-hidden="true" tabindex="-1"></a>p <span class="op">=</span> [<span class="fl">1</span><span class="op">/</span><span class="fl">10</span>, <span class="op">-</span><span class="fl">1</span><span class="op">/</span><span class="fl">10</span>]</span>
|
||
<span id="cb26-6"><a href="#cb26-6" aria-hidden="true" tabindex="-1"></a><span class="kw">global</span> p1 <span class="op">=</span> <span class="fu">vcat</span>(p, <span class="fu">f</span>(p<span class="op">...</span>)) <span class="co"># note F(p1) == 0</span></span>
|
||
<span id="cb26-7"><a href="#cb26-7" aria-hidden="true" tabindex="-1"></a><span class="kw">global</span> n⃗ <span class="op">=</span> ForwardDiff.<span class="fu">gradient</span>(F, p1)</span>
|
||
<span id="cb26-8"><a href="#cb26-8" aria-hidden="true" tabindex="-1"></a><span class="kw">global</span> <span class="fu">tl</span>(x) <span class="op">=</span> <span class="fu">f</span>(p) <span class="op">+</span> ForwardDiff.<span class="fu">gradient</span>(f, p) <span class="op">⋅</span> (x <span class="op">-</span> p)</span>
|
||
<span id="cb26-9"><a href="#cb26-9" aria-hidden="true" tabindex="-1"></a><span class="fu">tl</span>(x,y) <span class="op">=</span> <span class="fu">tl</span>([x,y])</span>
|
||
<span id="cb26-10"><a href="#cb26-10" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb26-11"><a href="#cb26-11" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> ys <span class="op">=</span> <span class="fu">range</span>(<span class="op">-</span><span class="fl">2</span>, stop<span class="op">=</span><span class="fl">2</span>, length<span class="op">=</span><span class="fl">100</span>)</span>
|
||
<span id="cb26-12"><a href="#cb26-12" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(xs, ys, f)</span>
|
||
<span id="cb26-13"><a href="#cb26-13" aria-hidden="true" tabindex="-1"></a><span class="fu">surface!</span>(xs, ys, tl)</span>
|
||
<span id="cb26-14"><a href="#cb26-14" aria-hidden="true" tabindex="-1"></a><span class="fu">arrow!</span>(p1, <span class="fl">5</span>n⃗)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="27">
|
||
<p><img src="plots_plotting_files/figure-html/cell-27-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
<p>From some viewing angles, the normal does not look perpendicular to the tangent plane. This is a quick verification for a randomly chosen point in the <span class="math inline">\(x-y\)</span> plane:</p>
|
||
<div class="cell" data-execution_count="27">
|
||
<div class="sourceCode cell-code" id="cb27"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb27-1"><a href="#cb27-1" aria-hidden="true" tabindex="-1"></a>a, b <span class="op">=</span> <span class="fu">randn</span>(<span class="fl">2</span>)</span>
|
||
<span id="cb27-2"><a href="#cb27-2" aria-hidden="true" tabindex="-1"></a><span class="fu">dot</span>(n⃗, (p1 <span class="op">-</span> [a,b, <span class="fu">tl</span>(a,b)]))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="28">
|
||
<pre><code>-2.220446049250313e-16</code></pre>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="parameterized-surface-plots" class="level3" data-number="58.2.5">
|
||
<h3 data-number="58.2.5" class="anchored" data-anchor-id="parameterized-surface-plots"><span class="header-section-number">58.2.5</span> Parameterized surface plots</h3>
|
||
<p>As illustrated, we can plot surfaces of the form <span class="math inline">\((x,y,f(x,y)\)</span>. However, not all surfaces are so readily described. For example, if <span class="math inline">\(F(x,y,z)\)</span> is a function from <span class="math inline">\(R^3 \rightarrow R\)</span>, then <span class="math inline">\(F(x,y,z)=c\)</span> is a surface of interest. For example, the sphere of radius one is a solution to <span class="math inline">\(F(x,y,z)=1\)</span> where <span class="math inline">\(F(x,y,z) = x^2 + y^2 + z^2\)</span>.</p>
|
||
<p>Plotting such generally described surfaces is not so easy, but <em>parameterized</em> surfaces can be represented. For example, the sphere as a surface is not represented as a surface of a function, but can be represented in spherical coordinates as parameterized by two angles, essentially an “azimuth” and and “elevation”, as used with the <code>camera</code> argument.</p>
|
||
<p>Here we define functions that represent <span class="math inline">\((x,y,z)\)</span> coordinates in terms of the corresponding spherical coordinates <span class="math inline">\((r, \theta, \phi)\)</span>.</p>
|
||
<div class="cell" data-execution_count="28">
|
||
<div class="sourceCode cell-code" id="cb29"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb29-1"><a href="#cb29-1" aria-hidden="true" tabindex="-1"></a><span class="co"># spherical: (radius r, inclination θ, azimuth φ)</span></span>
|
||
<span id="cb29-2"><a href="#cb29-2" aria-hidden="true" tabindex="-1"></a><span class="fu">X</span>(r,theta,phi) <span class="op">=</span> r <span class="op">*</span> <span class="fu">sin</span>(theta) <span class="op">*</span> <span class="fu">sin</span>(phi)</span>
|
||
<span id="cb29-3"><a href="#cb29-3" aria-hidden="true" tabindex="-1"></a><span class="fu">Y</span>(r,theta,phi) <span class="op">=</span> r <span class="op">*</span> <span class="fu">sin</span>(theta) <span class="op">*</span> <span class="fu">cos</span>(phi)</span>
|
||
<span id="cb29-4"><a href="#cb29-4" aria-hidden="true" tabindex="-1"></a><span class="fu">Z</span>(r,theta,phi) <span class="op">=</span> r <span class="op">*</span> <span class="fu">cos</span>(theta)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="29">
|
||
<pre><code>Z (generic function with 1 method)</code></pre>
|
||
</div>
|
||
</div>
|
||
<p>We can parameterize the sphere by plotting values for <span class="math inline">\(x\)</span>, <span class="math inline">\(y\)</span>, and <span class="math inline">\(z\)</span> produced by a sequence of values for <span class="math inline">\(\theta\)</span> and <span class="math inline">\(\phi\)</span>, holding <span class="math inline">\(r=1\)</span>:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="29">
|
||
<div class="sourceCode cell-code" id="cb31"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb31-1"><a href="#cb31-1" aria-hidden="true" tabindex="-1"></a>thetas <span class="op">=</span> <span class="fu">range</span>(<span class="fl">0</span>, stop<span class="op">=</span><span class="cn">pi</span>, length<span class="op">=</span><span class="fl">50</span>)</span>
|
||
<span id="cb31-2"><a href="#cb31-2" aria-hidden="true" tabindex="-1"></a>phis <span class="op">=</span> <span class="fu">range</span>(<span class="fl">0</span>, stop<span class="op">=</span><span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>, length<span class="op">=</span><span class="fl">50</span>)</span>
|
||
<span id="cb31-3"><a href="#cb31-3" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb31-4"><a href="#cb31-4" aria-hidden="true" tabindex="-1"></a>xs <span class="op">=</span> [<span class="fu">X</span>(<span class="fl">1</span>, theta, phi) for theta <span class="kw">in</span> thetas, phi <span class="kw">in</span> phis]</span>
|
||
<span id="cb31-5"><a href="#cb31-5" aria-hidden="true" tabindex="-1"></a>ys <span class="op">=</span> [<span class="fu">Y</span>(<span class="fl">1</span>, theta, phi) for theta <span class="kw">in</span> thetas, phi <span class="kw">in</span> phis]</span>
|
||
<span id="cb31-6"><a href="#cb31-6" aria-hidden="true" tabindex="-1"></a>zs <span class="op">=</span> [<span class="fu">Z</span>(<span class="fl">1</span>, theta, phi) for theta <span class="kw">in</span> thetas, phi <span class="kw">in</span> phis]</span>
|
||
<span id="cb31-7"><a href="#cb31-7" aria-hidden="true" tabindex="-1"></a></span>
|
||
<span id="cb31-8"><a href="#cb31-8" aria-hidden="true" tabindex="-1"></a><span class="fu">surface</span>(xs, ys, zs)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="30">
|
||
<p><img src="plots_plotting_files/figure-html/cell-30-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
<div class="cell" data-execution_count="30">
|
||
<div class="cell-output cell-output-display" data-execution_count="31">
|
||
<div class="markdown"><div class="admonition info"><p class="admonition-title">Info</p><p>The above may not work with all backends for <code>Plots</code>, even if those that support 3D graphics.</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<p>For convenience, the <code>plot_parametric</code> function from <code>CalculusWithJulia</code> can produce these plots using interval notation, <code>a..b</code>, and a function:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="31">
|
||
<div class="sourceCode cell-code" id="cb32"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a><span class="fu">F</span>(theta, phi) <span class="op">=</span> [<span class="fu">X</span>(<span class="fl">1</span>, theta, phi), <span class="fu">Y</span>(<span class="fl">1</span>, theta, phi), <span class="fu">Z</span>(<span class="fl">1</span>, theta, phi)]</span>
|
||
<span id="cb32-2"><a href="#cb32-2" aria-hidden="true" tabindex="-1"></a><span class="fu">plot_parametric</span>(<span class="fl">0</span><span class="op">..</span><span class="cn">pi</span>, <span class="fl">0</span><span class="op">..</span><span class="cn">pi</span><span class="op">/</span><span class="fl">2</span>, F)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="32">
|
||
<p><img src="plots_plotting_files/figure-html/cell-32-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<section id="plotting-fxy-z-c" class="level3" data-number="58.2.6">
|
||
<h3 data-number="58.2.6" class="anchored" data-anchor-id="plotting-fxy-z-c"><span class="header-section-number">58.2.6</span> Plotting F(x,y, z) = c</h3>
|
||
<p>There is no built in functionality in <code>Plots</code> to create surface described by <span class="math inline">\(F(x,y,z) = c\)</span>. An example of how to provide some such functionality for <code>PyPlot</code> appears <a href="https://stackoverflow.com/questions/4680525/plotting-implicit-equations-in-3d">here</a>. The non-exported <code>plot_implicit_surface</code> function can be used to approximate this.</p>
|
||
<p>To use it, we see what happens when a sphere if rendered:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="32">
|
||
<div class="sourceCode cell-code" id="cb33"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb33-1"><a href="#cb33-1" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y,z) <span class="op">=</span> x<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> y<span class="op">^</span><span class="fl">2</span> <span class="op">+</span> z<span class="op">^</span><span class="fl">2</span> <span class="op">-</span> <span class="fl">25</span></span>
|
||
<span id="cb33-2"><a href="#cb33-2" aria-hidden="true" tabindex="-1"></a>CalculusWithJulia.<span class="fu">plot_implicit_surface</span>(f)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="33">
|
||
<p><img src="plots_plotting_files/figure-html/cell-33-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
<p>This figure comes from a February 14, 2019 article in the <a href="https://www.nytimes.com/2019/02/14/science/math-algorithm-valentine.html">New York Times</a>. It shows an equation for a “heart,” as the graphic will illustrate:</p>
|
||
<div class="cell" data-hold="true" data-execution_count="33">
|
||
<div class="sourceCode cell-code" id="cb34"><pre class="sourceCode julia code-with-copy"><code class="sourceCode julia"><span id="cb34-1"><a href="#cb34-1" aria-hidden="true" tabindex="-1"></a>a,b <span class="op">=</span> <span class="fl">1</span>,<span class="fl">3</span></span>
|
||
<span id="cb34-2"><a href="#cb34-2" aria-hidden="true" tabindex="-1"></a><span class="fu">f</span>(x,y,z) <span class="op">=</span> (x<span class="op">^</span><span class="fl">2</span><span class="fu">+</span>((<span class="fl">1</span><span class="op">+</span>b)<span class="op">*</span>y)<span class="op">^</span><span class="fl">2</span><span class="op">+</span>z<span class="op">^</span><span class="fl">2</span><span class="op">-</span><span class="fl">1</span>)<span class="op">^</span><span class="fl">3</span><span class="op">-</span>x<span class="op">^</span><span class="fl">2</span><span class="op">*</span>z<span class="op">^</span><span class="fl">3</span><span class="op">-</span>a<span class="op">*</span>y<span class="op">^</span><span class="fl">2</span><span class="op">*</span>z<span class="op">^</span><span class="fl">3</span></span>
|
||
<span id="cb34-3"><a href="#cb34-3" aria-hidden="true" tabindex="-1"></a>CalculusWithJulia.<span class="fu">plot_implicit_surface</span>(f, xlim<span class="op">=-</span><span class="fl">2</span><span class="op">..</span><span class="fl">2</span>, ylim<span class="op">=-</span><span class="fl">1</span><span class="op">..</span><span class="fl">1</span>, zlim<span class="op">=-</span><span class="fl">1</span><span class="op">..</span><span class="fl">2</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
|
||
<div class="cell-output cell-output-display" data-execution_count="34">
|
||
<p><img src="plots_plotting_files/figure-html/cell-34-output-1.svg" class="img-fluid"></p>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
</section>
|
||
</section>
|
||
|
||
</main> <!-- /main -->
|
||
<script id="quarto-html-after-body" type="application/javascript">
|
||
window.document.addEventListener("DOMContentLoaded", function (event) {
|
||
const toggleBodyColorMode = (bsSheetEl) => {
|
||
const mode = bsSheetEl.getAttribute("data-mode");
|
||
const bodyEl = window.document.querySelector("body");
|
||
if (mode === "dark") {
|
||
bodyEl.classList.add("quarto-dark");
|
||
bodyEl.classList.remove("quarto-light");
|
||
} else {
|
||
bodyEl.classList.add("quarto-light");
|
||
bodyEl.classList.remove("quarto-dark");
|
||
}
|
||
}
|
||
const toggleBodyColorPrimary = () => {
|
||
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
|
||
if (bsSheetEl) {
|
||
toggleBodyColorMode(bsSheetEl);
|
||
}
|
||
}
|
||
toggleBodyColorPrimary();
|
||
const icon = "";
|
||
const anchorJS = new window.AnchorJS();
|
||
anchorJS.options = {
|
||
placement: 'right',
|
||
icon: icon
|
||
};
|
||
anchorJS.add('.anchored');
|
||
const clipboard = new window.ClipboardJS('.code-copy-button', {
|
||
target: function(trigger) {
|
||
return trigger.previousElementSibling;
|
||
}
|
||
});
|
||
clipboard.on('success', function(e) {
|
||
// button target
|
||
const button = e.trigger;
|
||
// don't keep focus
|
||
button.blur();
|
||
// flash "checked"
|
||
button.classList.add('code-copy-button-checked');
|
||
var currentTitle = button.getAttribute("title");
|
||
button.setAttribute("title", "Copied!");
|
||
setTimeout(function() {
|
||
button.setAttribute("title", currentTitle);
|
||
button.classList.remove('code-copy-button-checked');
|
||
}, 1000);
|
||
// clear code selection
|
||
e.clearSelection();
|
||
});
|
||
function tippyHover(el, contentFn) {
|
||
const config = {
|
||
allowHTML: true,
|
||
content: contentFn,
|
||
maxWidth: 500,
|
||
delay: 100,
|
||
arrow: false,
|
||
appendTo: function(el) {
|
||
return el.parentElement;
|
||
},
|
||
interactive: true,
|
||
interactiveBorder: 10,
|
||
theme: 'quarto',
|
||
placement: 'bottom-start'
|
||
};
|
||
window.tippy(el, config);
|
||
}
|
||
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
|
||
for (var i=0; i<noterefs.length; i++) {
|
||
const ref = noterefs[i];
|
||
tippyHover(ref, function() {
|
||
let href = ref.getAttribute('href');
|
||
try { href = new URL(href).hash; } catch {}
|
||
const id = href.replace(/^#\/?/, "");
|
||
const note = window.document.getElementById(id);
|
||
return note.innerHTML;
|
||
});
|
||
}
|
||
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
|
||
for (var i=0; i<bibliorefs.length; i++) {
|
||
const ref = bibliorefs[i];
|
||
const cites = ref.parentNode.getAttribute('data-cites').split(' ');
|
||
tippyHover(ref, function() {
|
||
var popup = window.document.createElement('div');
|
||
cites.forEach(function(cite) {
|
||
var citeDiv = window.document.createElement('div');
|
||
citeDiv.classList.add('hanging-indent');
|
||
citeDiv.classList.add('csl-entry');
|
||
var biblioDiv = window.document.getElementById('ref-' + cite);
|
||
if (biblioDiv) {
|
||
citeDiv.innerHTML = biblioDiv.innerHTML;
|
||
}
|
||
popup.appendChild(citeDiv);
|
||
});
|
||
return popup.innerHTML;
|
||
});
|
||
}
|
||
var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
|
||
var filterRegex = new RegExp('/' + window.location.host + '/');
|
||
var isInternal = (href) => {
|
||
return filterRegex.test(href) || localhostRegex.test(href);
|
||
}
|
||
// Inspect non-navigation links and adorn them if external
|
||
var links = window.document.querySelectorAll('a:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external)');
|
||
for (var i=0; i<links.length; i++) {
|
||
const link = links[i];
|
||
if (!isInternal(link.href)) {
|
||
// target, if specified
|
||
link.setAttribute("target", "_blank");
|
||
}
|
||
}
|
||
});
|
||
</script>
|
||
<nav class="page-navigation">
|
||
<div class="nav-page nav-page-previous">
|
||
<a href="../differentiable_vector_calculus/vector_fields.html" class="pagination-link">
|
||
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">57</span> <span class="chapter-title">Functions <span class="math inline">\(R^n \rightarrow R^m\)</span></span></span>
|
||
</a>
|
||
</div>
|
||
<div class="nav-page nav-page-next">
|
||
<a href="../integral_vector_calculus/double_triple_integrals.html" class="pagination-link">
|
||
<span class="nav-page-text"><span class="chapter-number">59</span> <span class="chapter-title">Multi-dimensional integrals</span></span> <i class="bi bi-arrow-right-short"></i>
|
||
</a>
|
||
</div>
|
||
</nav>
|
||
</div> <!-- /content -->
|
||
<footer class="footer">
|
||
<div class="nav-footer">
|
||
<div class="nav-footer-center">Copyright 2022, John Verzani</div>
|
||
</div>
|
||
</footer>
|
||
|
||
|
||
|
||
</body></html> |