# Plot doesn't show up when calling \`x=\`, \`y=\` explicitly

**URL:** <https://discourse.julialang.org/t/plot-doesnt-show-up-when-calling-x-y-explicitly/56851>\
**Category:** New to Julia\
**Created:** [March 10, 2021, 4:45am UTC](https://discourse.julialang.org/t/plot-doesnt-show-up-when-calling-x-y-explicitly/56851 "2021-03-10T04:45:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)\
**Post date:** [March 10, 2021, 4:45am UTC](https://discourse.julialang.org/t/plot-doesnt-show-up-when-calling-x-y-explicitly/56851/1 "2021-03-10T04:45:11Z")

</div>

Am I wrong for being surprised by this behavior?

```julia
julia> using Plots

julia> a = rand(10); b = rand(10);

julia> plot(a, b) # Works

julia> plot(x=a, y=b) # Plots a blank canvas

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 10, 2021, 7:12am UTC](https://discourse.julialang.org/t/plot-doesnt-show-up-when-calling-x-y-explicitly/56851/3 "2021-03-10T07:12:51Z")

</div>

I wouldn’t say you’re wrong, but I think it makes sense given how multiple dispatch work. Methods are chosen on the type of all arguments, and keyword arguments don’t participate in dispatch.

So if you call plot with only keyword arguments, you are in effect calling the method without arguments (ie `plot()`), which indeed just gives an empty canvas.

---

<div class="post-metadata">

**Author:** ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)\
**Post date:** [March 10, 2021, 7:23am UTC](https://discourse.julialang.org/t/plot-doesnt-show-up-when-calling-x-y-explicitly/56851/4 "2021-03-10T07:23:45Z")

</div>

In general, if I use keywords on a positional argument, I expect an _error,_ not blank output, as in the following:

```julia
julia> g(x) = 2x
g (generic function with 1 method)

julia> g(x=3)
ERROR: MethodError: no method matching g(; x=3)
Closest candidates are:
  g(::Any) at REPL[3]:1 got unsupported keyword argument "x"
Stacktrace:
 [1] top-level scope at REPL[4]:1

```

But seeing `x` and `y` listed as kwargs in the documentation led me to expect the same behavior whether using them positionally or as keywords:

[https://docs.juliaplots.org/latest/generated/attributes\_series/](https://docs.juliaplots.org/latest/generated/attributes_series/)

Clearly, the `x` and `y` keywords do _something_ (and I have seen them used in examples before), but it’s not clear to me exactly what.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 10, 2021, 7:40am UTC](https://discourse.julialang.org/t/plot-doesnt-show-up-when-calling-x-y-explicitly/56851/5 "2021-03-10T07:40:15Z")

</div>

Maybe this helps:

```julia
julia> using Plots

julia> plot(rand(10), some_keyword = "let's see what happens")

julia> g(x) = 2x
g (generic function with 1 method)

julia> g(x; args...) = 3x
g (generic function with 1 method)

julia> g(2)
6

julia> g(2, x = 5)
6

```

While `x` and `y` (just like `z`) are series attributes, I don’t think they are meant to be used as keyword arguments, they rather hold information on the `x` and `y` values of any series on the final plot:

```julia
julia> p = plot(rand(10, 2));

julia> p.series_list
2-element Vector{Plots.Series}:
 Plots.Series(RecipesPipeline.DefaultsDict(:plot_object => Plot{Plots.GRBackend() n=2}, :subplot => Subplot{1}, :label => "y1", :fillalpha => nothing, :linealpha => nothing, :linecolor => RGBA{Float64}(0.0,0.6056031611752245,0.9786801175696073,1.0), :markerstrokealpha => nothing, :markeralpha => nothing, :seriestype => :path, :x => Base.OneTo(10)…))
 Plots.Series(RecipesPipeline.DefaultsDict(:plot_object => Plot{Plots.GRBackend() n=2}, :subplot => Subplot{1}, :label => "y2", :fillalpha => nothing, :linealpha => nothing, :linecolor => RGBA{Float64}(0.8888735002725198,0.43564919034818994,0.2781229361419438,1.0), :markerstrokealpha => nothing, :markeralpha => nothing, :seriestype => :path, :x => Base.OneTo(10)…))

```

I might be speaking out of turn here as I don’t know much about the underlying implementation of `plot`, but it seems hard to me to have the behaviour you want: because you are not using dispatch, you’d have to complicate the `plot()` function without arguments to go through the list of keyword arguments and decide what to do (as presumably `plot(x = rand(5), y = rand(5))` should behave differently from `plot(x = rand(5), y = rand(5), z = rand(5))`).

---

<div class="post-metadata">

**Author:** ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)\
**Post date:** [March 10, 2021, 7:46am UTC](https://discourse.julialang.org/t/plot-doesnt-show-up-when-calling-x-y-explicitly/56851/6 "2021-03-10T07:46:12Z")

</div>

Thank you. This example clears up a lot.

The outstanding issue for me is then the intended purpose of the `x=` and `y=` series keywords, which are defined in the documentation linked above as “Input data. First Dimension” etc.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 10, 2021, 10:04am UTC](https://discourse.julialang.org/t/plot-doesnt-show-up-when-calling-x-y-explicitly/56851/7 "2021-03-10T10:04:58Z")

</div>

Again I’m actually not too familiar with the plots internals, but it might be that these are not “keywords” in the sense that are meant to be used, but rather just series attributes (which is after all the title of the table), that is a series that is created by `plot()` will have them and they can be queried after creation of the plot (as I show above with `series_list`)
