1
coordinate_distance(x,z) = abs.(x .- z)

square1(x) = sum(coordinate_distance(x,z).^2)

using Plots

LB,UB = 0,20 # Defining Lowerboud and Upperbound

plot(square1, LB, UB, legend=false)

scatter!(z, [square1(x) for x in z])

square1-custom function

z-interger array

Error Message:

MethodError: no method matching Val{:scatter}(::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char, ::Char)

Stacktrace:

[1] apply_recipe(plotattributes::Dict{Symbol, Any}, #unused#::Type{Val{:scatter}}, plt::Plots.Plot{Plots.GRBackend})
@ Plots C:\Users\pradnk\.julia\packages\Plots\HcxwM\src\recipes.jl:49
[2] _process_plotrecipe(plt::Any, kw::Any, kw_list::Any, still_to_process::Any)
@ RecipesPipeline 
C:\Users\pradnk\.julia\packages\RecipesPipeline\3x4B9\src\plot_recipe.jl:32
[3] _process_plotrecipes!(plt::Any, kw_list::Any)
@ RecipesPipeline 
C:\Users\pradnk\.julia\packages\RecipesPipeline\3x4B9\src\plot_recipe.jl:18
[4] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
@ RecipesPipeline C:\Users\pradnk\.julia\packages\RecipesPipeline\3x4B9\src\RecipesPipeline.jl:81
[5] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
@ Plots C:\Users\pradnk\.julia\packages\Plots\HcxwM\src\plot.jl:208
[6] #plot#154
@ C:\Users\pradnk\.julia\packages\Plots\HcxwM\src\plot.jl:91 [inlined]
[7] scatter(::Any, ::Vararg{Any, N} where N; kw::Any)
@ Plots C:\Users\pradnk\.julia\packages\RecipesBase\3fzVq\src\RecipesBase.jl:404
[8] top-level scope
@ In[10]:2
[9] eval
@ .\boot.jl:360 [inlined]
[10] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base .\loading.jl:1116

I am new to Julia and I have never come across this error before.

Pradnk77
  • 11
  • 2
  • Which version of Julia are you using? In 1.6.2, I'm able to run this code (with z = 1:20) and get the plots, no error messages. This looks like some definition before this code is messing with the `scatter!` call, could you open a fresh Julia session and try running this again? – Sundar R Sep 08 '21 at 18:27
  • Post the `z` you're using that causes the error. I'm somewhat suspecting that `z` isn't an integer array. For example, the operations you use inside `coordinate_distance` also work on `Char`, the types that show up in your `MethodError` message. – BatWannaBe Sep 08 '21 at 19:16
  • @sundar-RememberMonica Yes. I am using 1.6.2. I tried running fresh session, I am getting the same error – Pradnk77 Sep 08 '21 at 19:51
  • @BatWannaBe typeof(z): Vector{Int64} (alias for Array{Int64, 1}) – Pradnk77 Sep 08 '21 at 20:21
  • I'm curious what this'll turn out to be. Can you type just `scatter!` in the Julia REPL and see what that returns? Maybe there's something in your startup.jl file (`$HOME/.julia/config/startup.jl`)? A screenshot of the error would probably help too, maybe there's some little detail there that wasn't mentioned in the question. – Sundar R Sep 09 '21 at 12:45
  • @sundar-RememberMonica I typed scatter! in REPL. It says "UndefVarError: scatter! not defined". I tried plotting histogram today and got the same error as in my post above. I have added additional detail about the error in my post. Please check. – Pradnk77 Sep 09 '21 at 13:19

0 Answers0