Different behavior of zcolor in Scatter and Plot

Hello,
I noticed that I can change the color of markers easily in Scatter, but not in Plots.
Here an example:

using Plots

x = 1:0.1:10
y1 = x .+ 1
y2 = x .+ 2
y3 = x .+ 3

scatter(x, y1, color=:reds, zcolor=1)
scatter!(x, y2, color=:reds, zcolor=2)
scatter!(x, y3, color=:reds, zcolor=3)

plot(x, y1, color=:reds, zcolor=1)
plot!(x, y2, color=:reds, zcolor=2)
plot!(x, y3, color=:reds, zcolor=3)

Here, the results
scat
plot

Is this intentional ? :thinking::thinking:

I don’t know if it’s directly intentional, but it’s by design. zcolor is an alias for marker_z. Use line_z to control the color of a line.

2 Likes

I noticed that my example does not work anymore. I got this long message:

Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: InexactError: trunc(Int64, NaN)
Stacktrace:
 [1] trunc at ./float.jl:703 [inlined]
 [2] round at ./floatfuncs.jl:124 [inlined]
 [3] _broadcast_getindex_evalf at ./broadcast.jl:631 [inlined]
 [4] _broadcast_getindex at ./broadcast.jl:614 [inlined]
 [5] getindex at ./broadcast.jl:564 [inlined]
 [6] copy at ./broadcast.jl:830 [inlined]
 [7] materialize at ./broadcast.jl:820 [inlined]
 [8] get(::ColorSchemes.ColorScheme{Array{RGBA{Float64},1},String,String}, ::Int64, ::Tuple{Float64,Float64}) at /home/noel/.julia/packages/ColorSchemes/3n8HS/src/ColorSchemes.jl:207
 [9] get(::PlotUtils.ContinuousColorGradient, ::Int64, ::Tuple{Float64,Float64}) at /home/noel/.julia/packages/PlotUtils/S1cG3/src/colorschemes.jl:18
 [10] get_markercolor(::Plots.Series, ::Float64, ::Float64, ::Int64) at /home/noel/.julia/packages/Plots/FYxdA/src/utils.jl:530
 [11] get_markercolor at /home/noel/.julia/packages/Plots/FYxdA/src/utils.jl:534 [inlined]
 [12] gr_draw_marker(::Plots.Series, ::Float64, ::Float64, ::Tuple{Float64,Float64}, ::Int64, ::Int64, ::Int64, ::Symbol) at /home/noel/.julia/packages/Plots/FYxdA/src/backends/gr.jl:329
 [13] gr_draw_markers(::Plots.Series, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::Tuple{Float64,Float64}, ::Int64, ::Int64) at /home/noel/.julia/packages/Plots/FYxdA/src/backends/gr.jl:356
 [14] gr_draw_markers(::Plots.Series, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::StepRangeLen{Float64,Base.TwicePrecision{Float64},Base.TwicePrecision{Float64}}, ::Tuple{Float64,Float64}) at /home/noel/.julia/packages/Plots/FYxdA/src/backends/gr.jl:347
 [15] gr_display(::Plots.Subplot{Plots.GRBackend}, ::Measures.Length{:mm,Float64}, ::Measures.Length{:mm,Float64}, ::Array{Float64,1}) at /home/noel/.julia/packages/Plots/FYxdA/src/backends/gr.jl:1653
 [16] gr_display(::Plots.Plot{Plots.GRBackend}, ::String) at /home/noel/.julia/packages/Plots/FYxdA/src/backends/gr.jl:673
 [17] gr_display at /home/noel/.julia/packages/Plots/FYxdA/src/backends/gr.jl:637 [inlined]
 [18] _display(::Plots.Plot{Plots.GRBackend}) at /home/noel/.julia/packages/Plots/FYxdA/src/backends/gr.jl:1973
 [19] display(::Plots.PlotsDisplay, ::Plots.Plot{Plots.GRBackend}) at /home/noel/.julia/packages/Plots/FYxdA/src/output.jl:150
 [20] display(::Any) at ./multimedia.jl:323
 [21] #invokelatest#1 at ./essentials.jl:712 [inlined]
 [22] invokelatest at ./essentials.jl:711 [inlined]
 [23] print_response(::IO, ::Any, ::Bool, ::Bool, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:161
 [24] print_response(::REPL.AbstractREPL, ::Any, ::Bool, ::Bool) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:146
 [25] (::REPL.var"#do_respond#38"{Bool,REPL.var"#48#57"{REPL.LineEditREPL,REPL.REPLHistoryProvider},REPL.LineEditREPL,REPL.LineEdit.Prompt})(::Any, ::Any, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:729
 [26] (::REPL.var"#53#62")(::Any, ::Any, ::Vararg{Any,N} where N) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:997
 [27] #invokelatest#1 at ./essentials.jl:712 [inlined]
 [28] invokelatest at ./essentials.jl:711 [inlined]
 [29] (::REPL.LineEdit.var"#22#23"{REPL.var"#53#62",String})(::Any, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/REPL/src/LineEdit.jl:1364
 [30] prompt!(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/REPL/src/LineEdit.jl:2446
 [31] run_interface(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/REPL/src/LineEdit.jl:2349
 [32] run_frontend(::REPL.LineEditREPL, ::REPL.REPLBackendRef) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:1055
 [33] run_repl(::REPL.AbstractREPL, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.4/REPL/src/REPL.jl:206
 [34] (::Base.var"#764#766"{Bool,Bool,Bool,Bool})(::Module) at ./client.jl:383
 [35] #invokelatest#1 at ./essentials.jl:712 [inlined]
 [36] invokelatest at ./essentials.jl:711 [inlined]
 [37] run_main_repl(::Bool, ::Bool, ::Bool, ::Bool, ::Bool) at ./client.jl:367
 [38] exec_options(::Base.JLOptions) at ./client.jl:305
 [39] _start() at ./client.jl:484

I’m running Julia v1.4.0 and Plots v1.3.2