Plots.jl: PlotlyJS backend: apply "columnar" attributes to each series

Created on 13 Dec 2017  路  3Comments  路  Source: JuliaPlots/Plots.jl

I opened an issue for this with PlotlyJS (sglyon/PlotlyJS.jl#154) since what I describe works fine for GR, but am reporting here as well since it seems to be specific to Plots + PlotlyJS

I get an error when I try to apply an attribute like color to each series elementwise by passing a columnar value (vector or Nx1 matrix):

julia> using Plots; plotlyjs()

julia> scatter(rand(2,2), color=[:red, :blue])
ERROR: MethodError: no method matching rgba_string(::Array{ColorTypes.RGBA{Float64},1})
Closest candidates are:
  rgba_string(::PlotUtils.ColorGradient) at /home/dave/.julia/v0.6/PlotUtils/src/color_gradients.jl:247
  rgba_string(::ColorTypes.Colorant) at /home/dave/.julia/v0.6/PlotUtils/src/color_utils.jl:156
Stacktrace:
 [1] plotly_series(::Plots.Plot{Plots.PlotlyJSBackend}, ::Plots.Series) at /home/dave/.julia/v0.6/Plots/src/backends/plotly.jl:618
 [2] _series_added(::Plots.Plot{Plots.PlotlyJSBackend}, ::Plots.Series) at /home/dave/.julia/v0.6/Plots/src/backends/plotlyjs.jl:56
 [3] _add_the_series(::Plots.Plot{Plots.PlotlyJSBackend}, ::Plots.Subplot{Plots.PlotlyJSBackend}, ::Dict{Symbol,Any}) at /home/dave/.julia/v0.6/Plots/src/pipeline.jl:380
 [4] _process_seriesrecipe(::Plots.Plot{Plots.PlotlyJSBackend}, ::Dict{Symbol,Any}) at /home/dave/.julia/v0.6/Plots/src/pipeline.jl:402
 [5] _plot!(::Plots.Plot{Plots.PlotlyJSBackend}, ::Dict{Symbol,Any}, ::Tuple{Array{Float64,2}}) at /home/dave/.julia/v0.6/Plots/src/plot.jl:233
 [6] (::RecipesBase.#kw##plot)(::Array{Any,1}, ::RecipesBase.#plot, ::Array{Float64,2}) at ./<missing>:0
 [7] #scatter#607(::Array{Any,1}, ::Function, ::Array{Float64,2}, ::Vararg{Array{Float64,2},N} where N) at /home/dave/.julia/v0.6/RecipesBase/src/RecipesBase.jl:381
 [8] (::Plots.#kw##scatter)(::Array{Any,1}, ::Plots.#scatter, ::Array{Float64,2}, ::Vararg{Array{Float64,2},N} where N) at ./<missing>:0
 [9] macro expansion at ./REPL.jl:97 [inlined]
 [10] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:73

julia> scatter(rand(2,2), color=[:red; :blue])
ERROR: MethodError: no method matching rgba_string(::Array{ColorTypes.RGBA{Float64},1})
Closest candidates are:
  rgba_string(::PlotUtils.ColorGradient) at /home/dave/.julia/v0.6/PlotUtils/src/color_gradients.jl:247
  rgba_string(::ColorTypes.Colorant) at /home/dave/.julia/v0.6/PlotUtils/src/color_utils.jl:156
Stacktrace:
 [1] plotly_series(::Plots.Plot{Plots.PlotlyJSBackend}, ::Plots.Series) at /home/dave/.julia/v0.6/Plots/src/backends/plotly.jl:618
 [2] _series_added(::Plots.Plot{Plots.PlotlyJSBackend}, ::Plots.Series) at /home/dave/.julia/v0.6/Plots/src/backends/plotlyjs.jl:56
 [3] _add_the_series(::Plots.Plot{Plots.PlotlyJSBackend}, ::Plots.Subplot{Plots.PlotlyJSBackend}, ::Dict{Symbol,Any}) at /home/dave/.julia/v0.6/Plots/src/pipeline.jl:380
 [4] _process_seriesrecipe(::Plots.Plot{Plots.PlotlyJSBackend}, ::Dict{Symbol,Any}) at /home/dave/.julia/v0.6/Plots/src/pipeline.jl:402
 [5] _plot!(::Plots.Plot{Plots.PlotlyJSBackend}, ::Dict{Symbol,Any}, ::Tuple{Array{Float64,2}}) at /home/dave/.julia/v0.6/Plots/src/plot.jl:233
 [6] (::RecipesBase.#kw##plot)(::Array{Any,1}, ::RecipesBase.#plot, ::Array{Float64,2}) at ./<missing>:0
 [7] #scatter#607(::Array{Any,1}, ::Function, ::Array{Float64,2}, ::Vararg{Array{Float64,2},N} where N) at /home/dave/.julia/v0.6/RecipesBase/src/RecipesBase.jl:381
 [8] (::Plots.#kw##scatter)(::Array{Any,1}, ::Plots.#scatter, ::Array{Float64,2}, ::Vararg{Array{Float64,2},N} where N) at ./<missing>:0
 [9] macro expansion at ./REPL.jl:97 [inlined]
 [10] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:73

The above two work as expected in GR.

Applying one color to each series with a "row-wise" 1xN matrix works as expected:

julia> scatter(rand(2,2), color=[:red :blue])

All 3 comments

I have a partial fix for this bug. In https://github.com/JuliaPlots/Plots.jl/blob/5b85cd83f270e433a311277a249f29d761ddfe38/src/backends/plotly.jl#L620

rgba_string should be the dotted version rgba_string.(series[:markercolor]). There are a few other instances of rgba_string that also need to be modified to prevent errors from being thrown for other series types.

I say the fix only works partially, because while this gets rid of the error,

using Plots
plotlyjs()
scatter(randn(10,2),color=[:blue,:red])

results in

plots1306-plotly

whereas GR gives you

plots1306-gr

I'll take another look at this tomorrow to figure out how best to cycle through each of the entries in the series[:markercolor] vector for the whole series, unless anyone else has a suggestion.

@wkearn you can use Plots._cycle like _cycle(rgba_string.(series[:markercolor]), eachindex(x))

This particular bug should be fixed now by #1324. The remaining problems with rgba_string are with the linecolor argument (#1325), which is orthogonal to this bug, so I'm going to close this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SebastianM-C picture SebastianM-C  路  4Comments

dancsi picture dancsi  路  4Comments

pkofod picture pkofod  路  3Comments

tbenst picture tbenst  路  3Comments

cortner picture cortner  路  4Comments