# Usage of Kwargs in a plot function PyPlot

**URL:** <https://discourse.julialang.org/t/usage-of-kwargs-in-a-plot-function-pyplot/22639>\
**Category:** New to Julia\
**Created:** [April 2, 2019, 1:54pm UTC](https://discourse.julialang.org/t/usage-of-kwargs-in-a-plot-function-pyplot/22639 "2019-04-02T13:54:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Santiago\_Cuervo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/santiago_cuervo/32/7403_2.png) [@Santiago\_Cuervo](https://discourse.julialang.org/u/Santiago_Cuervo)\
**Post date:** [April 2, 2019, 1:54pm UTC](https://discourse.julialang.org/t/usage-of-kwargs-in-a-plot-function-pyplot/22639/1 "2019-04-02T13:54:24Z")

</div>

Let’s say I define a Function that plot some data with a defined attributes. I 'd like to call that function but if I wish specifying/change any attribute. I read about kwarg… keywork, but I’ve not figured out how to use.

```julia
using PyPlot

function Track(depth, g,s)
spax=gca()                                               
spax.plot(sp,md,color="blue")
spax.set_xlim([0,50]) 

grax=spax.twiny()        
grax.plot(gamma,md,color="red")
spax.set_xlim([100,500])
return spax, grax
end

```

Then I’d like to call the function but changing for example the color of spax axes.

```julia
Track(x,y,z, color=spax.set_color("green")) #how to change for example the color of spax from blue to green in the call?

```

how to do this?

---

<div class="post-metadata">

**Author:** ![maxmouchet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxmouchet/32/7834_2.png) [@maxmouchet](https://discourse.julialang.org/u/maxmouchet)\
**Post date:** [April 6, 2019, 5:33pm UTC](https://discourse.julialang.org/t/usage-of-kwargs-in-a-plot-function-pyplot/22639/2 "2019-04-06T17:33:09Z")

</div>

You can add [keyword arguments](https://docs.julialang.org/en/v1/manual/functions/#Keyword-Arguments-1) as such:

```julia
function Track(depth, g, s; spax_color="blue", grax_color="blue")
# ...
spax.plot(sp, md, color=spax_color)
# ...
end

```

```julia
Track(depth, g, s, spax_color="green")

```

If you want to pass arbitrary arguments to your PyPlot call you can do:

```julia
function Track(depth, g, s; spax_args=Dict(), grax_args=Dict())
# ...
spax.plot(sp, md; spax_args...)
# ...
end

```

```julia
Track(depth, g, s, spax_args=Dict(:color => "green"))

```

Finally, you can also do something like:

```julia
function Track(depth, g, s; kwargs...)
# ...
spax.plot(sp, md; kwargs...)
# ...
end

```

```julia
Track(depth, g, s, color="green")

```
