Evan
1
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)
adamslc
2
I haven’t tested this, but you should be able to use an anonymous function like so:
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: ````
1 Like
For plotting the function for multiple parameters, one way is:
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
But from description, not sure if you would want a surface plot instead:
surface(0:50,-1:0.5:1.0, dgp_DD_t, camera = (20,50))
2 Likes