# Plot function with multiple arguments

**URL:** <https://discourse.julialang.org/t/plot-function-with-multiple-arguments/55411>\
**Category:** Visualization\
**Tags:** plotting\
**Created:** [February 16, 2021, 6:37pm UTC](https://discourse.julialang.org/t/plot-function-with-multiple-arguments/55411 "2021-02-16T18:37:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Evan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evan/32/25369_2.png) [@Evan](https://discourse.julialang.org/u/Evan)\
**Post date:** [February 16, 2021, 6:37pm UTC](https://discourse.julialang.org/t/plot-function-with-multiple-arguments/55411/1 "2021-02-16T18:37:52Z")

</div>

I would like to plot a function that takes multiple inputs or arguments. An example for illustrative purpose:

using Plots

function dgp\_DD\_t(x, treatment=1)  
y = (2+ treatment)\*x  
end  
plot(dgp\_DD\_t,0,50)

But what i want:

function dgp\_DD\_t(x, treatment)  
y = (2+ treatment)\*x  
end  
plot(dgp\_DD\_t,0,50)

---

<div class="post-metadata">

**Author:** ![adamslc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adamslc/32/3452_2.png) [@adamslc](https://discourse.julialang.org/u/adamslc)\
**Post date:** [February 16, 2021, 6:54pm UTC](https://discourse.julialang.org/t/plot-function-with-multiple-arguments/55411/2 "2021-02-16T18:54:06Z")

</div>

I haven’t tested this, but you should be able to use an anonymous function like so:

```julia
function dgp_DD_t(x, treatment)
y = (2+ treatment) * x
end

plot(x -> dgp_DD_t(x, 1), 0, 50)

```

p.s. Code is much easier to read when it’s qouted. You can do that by starting and ending the code block with lines with three backticks: ````

---

<div class="post-metadata">

**Author:** ![Evan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evan/32/25369_2.png) [@Evan](https://discourse.julialang.org/u/Evan)\
**Post date:** [February 16, 2021, 7:44pm UTC](https://discourse.julialang.org/t/plot-function-with-multiple-arguments/55411/3 "2021-02-16T19:44:03Z")

</div>

thank you!

```julia
some code

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [February 17, 2021, 9:12am UTC](https://discourse.julialang.org/t/plot-function-with-multiple-arguments/55411/4 "2021-02-17T09:12:13Z")

</div>

For plotting the function for multiple parameters, one way is:

```julia
fig = plot(legend=:topleft);
[plot!(fig, x -> dgp_DD_t(x,t), 0, 50, label="t = $t") for t in -1:0.5:1.0];
fig

```

![Multiparameter_plot](https://global.discourse-cdn.com/julialang/original/3X/2/7/275b7eca75565dc2779aee4cfa7093cc0bc256e9.png)

But from description, not sure if you would want a surface plot instead:

```julia
surface(0:50,-1:0.5:1.0, dgp_DD_t, camera = (20,50))

```
