# Plot a Differential Equation or a 3 variable function

**URL:** <https://discourse.julialang.org/t/plot-a-differential-equation-or-a-3-variable-function/71625>\
**Category:** General Usage\
**Tags:** question, plots\
**Created:** [November 16, 2021, 11:59pm UTC](https://discourse.julialang.org/t/plot-a-differential-equation-or-a-3-variable-function/71625 "2021-11-16T23:59:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [November 16, 2021, 11:59pm UTC](https://discourse.julialang.org/t/plot-a-differential-equation-or-a-3-variable-function/71625/1 "2021-11-16T23:59:57Z")

</div>

How do I plot a function with 3 variables, either in 3d or a 2d contour plot.

```julia
U(x,y)=16*log(x)+9*log(y)

```

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [November 17, 2021, 12:38am UTC](https://discourse.julialang.org/t/plot-a-differential-equation-or-a-3-variable-function/71625/2 "2021-11-17T00:38:50Z")

</div>

[http://docs.juliaplots.org/latest/generated/gr/#gr-ref22](http://docs.juliaplots.org/latest/generated/gr/#gr-ref22)  
[http://docs.juliaplots.org/latest/generated/gr/#gr-ref50](http://docs.juliaplots.org/latest/generated/gr/#gr-ref50)

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [November 17, 2021, 12:38am UTC](https://discourse.julialang.org/t/plot-a-differential-equation-or-a-3-variable-function/71625/3 "2021-11-17T00:38:53Z")

</div>

[https://docs.juliaplots.org/latest/generated/gr/#gr-ref50](https://docs.juliaplots.org/latest/generated/gr/#gr-ref50)

---

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [November 17, 2021, 12:39am UTC](https://discourse.julialang.org/t/plot-a-differential-equation-or-a-3-variable-function/71625/4 "2021-11-17T00:39:26Z")

</div>

How about this?

```julia
using StatsPlots

U(x,y)=16*log(x)+9*log(y)

x = 0.1:0.1:2.0
y = 0.1:0.1:2.0
z = [U(i,j) for i in x, j in y]

p = plot(
    x,
    y,
    z,
    linetype=:wireframe,
    legend=false,
    xlabel="x",
    ylabel="y",
    zlabel="z"
)

plot!(
    x,
    y,
    z,
    linetype=:surface,
    legend=false,
    xlabel="x",
    ylabel="y",
    zlabel="z",
    alpha=0.8
)

```

![test](https://global.discourse-cdn.com/julialang/original/3X/7/1/712f554005a003e5ecba50e86516357e9002a667.png)

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [November 17, 2021, 12:53am UTC](https://discourse.julialang.org/t/plot-a-differential-equation-or-a-3-variable-function/71625/5 "2021-11-17T00:53:20Z")

</div>

That should work. Is there a way to do a 2d contour plot?

---

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [November 17, 2021, 1:14am UTC](https://discourse.julialang.org/t/plot-a-differential-equation-or-a-3-variable-function/71625/6 "2021-11-17T01:14:32Z")

</div>

Just call `contour` instead of `plot` and omit the `linetype` keyword argument. If you have a look at the links that @Jeff_Emanuel and @odow replied with you’ll find this very quickly. Just navigate to the section for your backend of choice (e.g. GR, Plotly) and push `Ctrl + f` on your keyboard; then, type `contour` and you can go straight to the section of the docs that demonstrate contour plot examples.

EDIT: actually, you can just do `linetype=:contour` and not change anything else.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [November 17, 2021, 1:47am UTC](https://discourse.julialang.org/t/plot-a-differential-equation-or-a-3-variable-function/71625/7 "2021-11-17T01:47:55Z")

</div>

this looks good, but I don’t know how to limit the y range to positive values
