Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous color scale with Date type (Gadfly 1.2.1 vs Gadfly 1.3.1) #1486

Closed
riccmin opened this issue Oct 21, 2020 · 1 comment · Fixed by #1491
Closed

Continuous color scale with Date type (Gadfly 1.2.1 vs Gadfly 1.3.1) #1486

riccmin opened this issue Oct 21, 2020 · 1 comment · Fixed by #1491

Comments

@riccmin
Copy link

riccmin commented Oct 21, 2020

In Gadfly 1.2.1 I was able to color points based on a continuous color scale of Date values using the following code:

using Gadfly
using Dates

xdata = collect(1:4)
ydata = collect(1:4)
cdata = collect(Date("2017-10-01"):Day(1):Date("2017-10-04"))
plot(x=xdata, y=ydata, color=cdata, Scale.color_continuous(minvalue=Date("2017-10-01"),maxvalue=Date("2017-10-08")))

This is the resulting image:
Gadfly_Plot

In Gadfly 1.3.1 the same code produces this error:

Error showing value of type Plot:
ERROR: There appears to be mixing of a continuous variable and a discrete variable in the `color` aesthetic.
This can happen when the color aesthetic is assigned in more than 1 layer (which is ok to do),
or you have forgotten to assign it. Either:
    1) make sure that the `color` variable in all layers is the same (i.e. discrete or continuous), or
    2) add `Scale.color_continuous` or `Scale.color_discrete` to the plot, or
    3) in a layer where `color` is a discrete variable, instead assign e.g. `color=[colorant"red"]`, or a vector of colorants.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] apply_scale(::Gadfly.Scale.ContinuousColorScale, ::Array{Gadfly.Aesthetics,1}, ::Gadfly.Data) at /home/ricky/.julia/packages/Gadfly/Xnkmc/src/scale.jl:664
 [3] apply_scales(::IterTools.Distinct{Base.ValueIterator{Dict{Symbol,Gadfly.ScaleElement}},Gadfly.ScaleElement}, ::Array{Gadfly.Aesthetics,1}, ::Gadfly.Data) at /home/ricky/.julia/packages/Gadfly/Xnkmc/src/scale.jl:24
 [4] apply_scales(::IterTools.Distinct{Base.ValueIterator{Dict{Symbol,Gadfly.ScaleElement}},Gadfly.ScaleElement}, ::Gadfly.Data) at /home/ricky/.julia/packages/Gadfly/Xnkmc/src/scale.jl:34
 [5] render_prepare(::Plot) at /home/ricky/.julia/packages/Gadfly/Xnkmc/src/Gadfly.jl:645
 [6] render(::Plot) at /home/ricky/.julia/packages/Gadfly/Xnkmc/src/Gadfly.jl:740
 [7] draw at /home/ricky/.julia/packages/Gadfly/Xnkmc/src/Gadfly.jl:847 [inlined]
 [8] display(::Gadfly.GadflyDisplay, ::MIME{Symbol("text/html")}, ::Plot) at /home/ricky/.julia/packages/Gadfly/Xnkmc/src/Gadfly.jl:1052
 [9] display(::Gadfly.GadflyDisplay, ::String, ::Any) at ./multimedia.jl:216
 [10] display(::Gadfly.GadflyDisplay, ::Plot) at /home/ricky/.julia/packages/Gadfly/Xnkmc/src/Gadfly.jl:1009
 [11] display(::Any) at ./multimedia.jl:328
 [12] #invokelatest#1 at ./essentials.jl:710 [inlined]
 [13] invokelatest at ./essentials.jl:709 [inlined]
 [14] print_response(::IO, ::Any, ::Bool, ::Bool, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:238
 [15] print_response(::REPL.AbstractREPL, ::Any, ::Bool, ::Bool) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:223
 [16] (::REPL.var"#do_respond#54"{Bool,Bool,REPL.var"#64#73"{REPL.LineEditREPL,REPL.REPLHistoryProvider},REPL.LineEditREPL,REPL.LineEdit.Prompt})(::Any, ::Any, ::Any) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:822
 [17] #invokelatest#1 at ./essentials.jl:710 [inlined]
 [18] invokelatest at ./essentials.jl:709 [inlined]
 [19] run_interface(::REPL.Terminals.TextTerminal, ::REPL.LineEdit.ModalInterface, ::REPL.LineEdit.MIState) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/REPL/src/LineEdit.jl:2355
 [20] run_frontend(::REPL.LineEditREPL, ::REPL.REPLBackendRef) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:1144
 [21] (::REPL.var"#38#42"{REPL.LineEditREPL,REPL.REPLBackendRef})() at ./task.jl:356

I cannot completely figure out the meaning of the error message. Am I missing something obvious? What exactly changed in Gadfly 1.3?
I am on linux MX and I am running julia 1.5.1

@tlnagy
Copy link
Member

tlnagy commented Oct 27, 2020

That error message/check was introduced by #1448 (@Mattriks). It appears that Scale.color_continuous only works for structs that subtype Number:

isa(first(cdata), Number) || error(colorclash)
. Generally, it would be nice to support any type that supports interpolation between its values, Number or otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants