I see, you’re running your code as a script. In general you should then place (almost) all of the code inside functions (e.g. a main function which you call at the end of your script). This will help for performance, and also get rid of your scope issue when defining vertex_counter (and later i) outside of the for loop.
Example
When run as a script
x = 0
for i = 1:5
x += 1
end
println(x)
indeed throws an exception
┌ Warning: Assignment to `x` in soft scope is ambiguous because a global variable by the same name exists: `x` will be treated as a new local. Disambiguate by using `local x` to suppress this warning or `global x` to assign to the existing global variable.
└ @ (...)\example.jl:3
ERROR: LoadError: UndefVarError: `x` not defined
Stacktrace:
[1] top-level scope
@ (...)\example.jl:3
in expression starting at (...)\example.jl:2
while
function main()
x = 0
for i = 1:5
x += 1
end
println(x)
end
main()
runs fine:
5
If you then define your variables outside of the loop (which you should, keeping the first note in my previous post in mind), you will still run into the second error. The solution here is to simply not use hex.
Example
using Plots
function main()
x = rand(10) |> sort
y = rand(10)
color_palette = distinguishable_colors(10)
plot(x, y, color=hex.(color_palette))
end
main()
will throw
ERROR: Unknown color: 000000
but
using Plots
function main()
x = rand(10) |> sort
y = rand(10)
color_palette = distinguishable_colors(10)
plot(x, y, color=color_palette)
end
main()
successfully displays.