Error using StatPlots

Hello, there! I’m trying to use the StatPlots package to plot some grouped bar graphics using the
groupedbar function. As can be seen in this picture that i got from their Github page.

673f6c78-863d-11e6-9ee9-8ca104e5d2a3

Basically, this is my code:

workspace()

using StatPlots

Dbefore = [0.2410; 4.6709; 4.7775; 4.9210; 4.9397; 5.0426; 5.0677; 5.2084; 5.2080; 4.7775; 5.8069; 6.3106; 6.3101; 7.5012; 7.9857;8.3787; 8.3786];
Dafter = [0.1192; 2.3108; 2.4009; 2.4932; 2.4922; 2.4441; 2.4702; 2.6176; 2.6173; 2.4009; 2.8985; 3.1818; 3.1925; 4.2242; 4.6714; 5.0027; 5.0027];

groupedbar([Dbefore Dafter], bar_position = :dodge, bar_width=0.7)

But i’m getting this error:

ERROR: LoadError: LoadError: MethodError: all(::Reexport.##2#6, ::Array{Any,1}) is ambiguous. Candidates:
  all(f, A::AbstractArray{#s18,N} where N where #s18>:LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMai
n.LastMain.LastMain.LastMain.LastMain.Missings.Missing) in LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.La
stMain.LastMain.LastMain.LastMain.LastMain.Missings at C:\Users\Muril\.julia\v0.6\Missings\src\Missings.jl:190
  all(f, A::AbstractArray{#s18,N} where N where #s18>:LastMain.LastMain.LastMain.LastMain.LastMain.Missings.Missing) in LastMain.LastMain.Last
Main.LastMain.LastMain.Missings at C:\Users\Muril\.julia\v0.6\Missings\src\Missings.jl:190
  all(f, A::AbstractArray{#s18,N} where N where #s18>:LastMain.LastMain.LastMain.LastMain.Missings.Missing) in LastMain.LastMain.LastMain.Last
Main.Missings at C:\Users\Muril\.julia\v0.6\Missings\src\Missings.jl:190
  all(f, A::AbstractArray{#s18,N} where N where #s18>:LastMain.LastMain.LastMain.Missings.Missing) in LastMain.LastMain.LastMain.Missings at C
:\Users\Muril\.julia\v0.6\Missings\src\Missings.jl:190
  all(f, A::AbstractArray{#s18,N} where N where #s18>:LastMain.LastMain.Missings.Missing) in LastMain.LastMain.Missings at C:\Users\Muril\.jul
ia\v0.6\Missings\src\Missings.jl:190
  all(f, A::AbstractArray{#s18,N} where N where #s18>:LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMai
n.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.Missings.Missing) in LastMain.LastMain.LastMain.LastMain.La
stMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.Missings
at C:\Users\Muril\.julia\v0.6\Missings\src\Missings.jl:190
Possible fix, define
  all(::Any, ::AbstractArray{#s18,N} where N where #s18>:Union{LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMai
n.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.Missings.Missing, LastMain.LastMain.LastMain.LastM
ain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.Missings.Missing, LastMain.LastMain.LastMain.Las
tMain.LastMain.Missings.Missing, LastMain.LastMain.LastMain.LastMain.Missings.Missing, LastMain.LastMain.LastMain.Missings.Missing, LastMain.L
astMain.Missings.Missing})
Stacktrace:
 [1] include_from_node1(::String) at .\loading.jl:576
 [2] eval(::Module, ::Any) at .\boot.jl:235
 [3] _require(::Symbol) at .\loading.jl:490
 [4] require(::Symbol) at .\loading.jl:405
 [5] include_string(::String, ::String) at .\loading.jl:522
 [6] include_string(::Module, ::String, ::String) at C:\Users\Muril\.julia\v0.6\Compat\src\Compat.jl:88
 [7] (::LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain
.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMa
in.LastMain.LastMain.Atom.##112#116{String,String})() at C:\Users\Muril\.julia\v0.6\Atom\src\eval.jl:109
 [8] withpath(::LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.
LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMai
n.LastMain.LastMain.LastMain.Atom.##112#116{String,String}, ::String) at C:\Users\Muril\.julia\v0.6\CodeTools\src\utils.jl:30
 [9] withpath(::Function, ::String) at C:\Users\Muril\.julia\v0.6\Atom\src\eval.jl:38
 [10] hideprompt(::LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMa
in.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.Last
Main.LastMain.LastMain.LastMain.Atom.##111#115{String,String}) at C:\Users\Muril\.julia\v0.6\Atom\src\repl.jl:67
 [11] macro expansion at C:\Users\Muril\.julia\v0.6\Atom\src\eval.jl:106 [inlined]
 [12] (::LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMai
n.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastM
ain.LastMain.LastMain.Atom.##110#114{Dict{String,Any}})() at .\task.jl:80
while loading C:\Users\Muril\.julia\v0.6\StatPlots\src\StatPlots.jl, in expression starting on line 5
while loading C:\Users\Muril\AppData\Local\atom\app-1.28.0\Arquivos Feitos\dsadasdsa.jl, in expression starting on line 3

Any help fixing this would be trully apreciated!

The workspace() command is deprecated in latest Julia as it’s known to cause issues. I think it simply cannot be used in combination with StatPlots. The same code without workspace() should work. If you’re used to the workspace() command from other languages (say close all; clear all in matlab), I’m not too sure what is the recommended alternative in Julia.

1 Like

Yeah, i was using it because i came from Matlab… thats bad to hear.

Well, i tried without it, and got this error now:

ERROR: LoadError: MethodError: Cannot `convert` an object of type Type{Any} to an object of type Abs
tractFloat
This may have arisen from a call to the constructor AbstractFloat(...),
since type constructors fall back to convert methods.
Stacktrace:
 [1] _preprocess_barlike(::Dict{Symbol,Any}, ::Array{Float64,1}, ::Array{Any,1}) at C:\Users\Muril\.
julia\v0.6\Plots\src\recipes.jl:458
 [2] macro expansion at C:\Users\Muril\.julia\v0.6\Plots\src\recipes.jl:327 [inlined]
 [3] apply_recipe(::Dict{Symbol,Any}, ::Type{Val{:bar}}, ::Array{Float64,1}, ::Array{Any,1}, ::Void)
 at C:\Users\Muril\.julia\v0.6\RecipesBase\src\RecipesBase.jl:291
 [4] _process_seriesrecipe(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}) at C:\Users\Muril\.jul
ia\v0.6\Plots\src\pipeline.jl:406
 [5] _plot!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{StatPlots.GroupedBar}) at C:\
Users\Muril\.julia\v0.6\Plots\src\plot.jl:235
 [6] (::RecipesBase.#kw##plot)(::Array{Any,1}, ::RecipesBase.#plot, ::StatPlots.GroupedBar) at .\<mi
ssing>:0
 [7] #groupedbar#76(::Array{Any,1}, ::Function, ::Array{Any,2}, ::Vararg{Array{Any,2},N} where N) at
 C:\Users\Muril\.julia\v0.6\RecipesBase\src\RecipesBase.jl:367
 [8] (::StatPlots.#kw##groupedbar)(::Array{Any,1}, ::StatPlots.#groupedbar, ::Array{Any,2}, ::Vararg
{Array{Any,2},N} where N) at .\<missing>:0
 [9] include_string(::String, ::String) at .\loading.jl:522
 [10] include_string(::Module, ::String, ::String) at C:\Users\Muril\.julia\v0.6\Compat\src\Compat.j
l:88
 [11] (::Atom.##112#116{String,String})() at C:\Users\Muril\.julia\v0.6\Atom\src\eval.jl:109
 [12] withpath(::Atom.##112#116{String,String}, ::String) at C:\Users\Muril\.julia\v0.6\CodeTools\sr
c\utils.jl:30
 [13] withpath(::Function, ::String) at C:\Users\Muril\.julia\v0.6\Atom\src\eval.jl:38
 [14] hideprompt(::Atom.##111#115{String,String}) at C:\Users\Muril\.julia\v0.6\Atom\src\repl.jl:67
 [15] macro expansion at C:\Users\Muril\.julia\v0.6\Atom\src\eval.jl:106 [inlined]
 [16] (::Atom.##110#114{Dict{String,Any}})() at .\task.jl:80
while loading C:\Users\Muril\AppData\Local\atom\app-1.28.0\Arquivos Feitos\dsadasdsa.jl, in expressi
on starting on line 195

I’m unable to reproduce it. To clarify, if you start Julia and give the command:

using StatPlots

Dbefore = [0.2410; 4.6709; 4.7775; 4.9210; 4.9397; 5.0426; 5.0677; 5.2084; 5.2080; 4.7775; 5.8069; 6.3106; 6.3101; 7.5012; 7.9857;8.3787; 8.3786];
Dafter = [0.1192; 2.3108; 2.4009; 2.4932; 2.4922; 2.4441; 2.4702; 2.6176; 2.6173; 2.4009; 2.8985; 3.1818; 3.1925; 4.2242; 4.6714; 5.0027; 5.0027];

groupedbar([Dbefore Dafter], bar_position = :dodge, bar_width=0.7)

you get an error?

What’s your Pkg.status() ?

Actually, no. If i start Julia and just type that, it works. But when i run my code, it doesn’t.

Here the status:

julia> Pkg.status()
9 required packages:
 - AmplNLWriter                  0.4.0
 - Atom                          0.6.14
 - Clp                           0.4.0
 - CoinOptServices               0.3.0
 - Combinatorics                 0.6.0
 - Debug                         0.1.6
 - JuMP                          0.18.2
 - Plotly                        0.1.1
 - StatPlots                     0.7.2
97 additional packages:
 - ASTInterpreter2               0.1.1
 - AssetRegistry                 0.0.1
 - AxisAlgorithms                0.2.0
 - BinDeps                       0.8.8
 - BinaryProvider                0.3.2
 - Blink                         0.6.2
 - BufferedStreams               0.4.0
 - Calculus                      0.4.0
 - Cbc                           0.3.2
 - CodeTools                     0.5.0
 - Codecs                        0.4.0
 - ColorTypes                    0.6.7
 - Colors                        0.8.2
 - CommonSubexpressions          0.1.0
 - Compat                        0.69.0
 - Contour                       0.4.0
 - DataStructures                0.8.3
 - DataValues                    0.3.3
 - DebuggerFramework             0.1.2
 - DiffEqDiffTools               0.4.1
 - DiffResults                   0.0.3
 - DiffRules                     0.0.5
 - Distances                     0.6.0
 - Distributions                 0.15.0
 - DocSeeker                     0.1.0
 - DocStringExtensions           0.4.4
 - DualNumbers                   0.4.0
 - FixedPointNumbers             0.4.6
 - ForwardDiff                   0.7.5
 - GR                            0.31.0
 - Hiccup                        0.1.1
 - HttpCommon                    0.4.0
 - HttpParser                    0.4.0
 - HttpServer                    0.3.1
 - Interpolations                0.7.3
 - Ipopt                         0.4.0
 - IterTools                     0.2.1
 - IterableTables                0.7.1
 - IteratorInterfaceExtensions   0.0.2
 - JSON                          0.17.2
 - Juno                          0.4.1
 - KernelDensity                 0.4.1
 - LNR                           0.0.2
 - LaTeXStrings                  1.0.0
 - Lazy                          0.12.1
 - LibExpat                      0.4.2
 - Libz                          0.2.4
 - LightXML                      0.6.0
 - LineSearches                  6.0.2
 - MacroTools                    0.4.2
 - MathOptInterface              0.4.1
 - MathProgBase                  0.7.1
 - MbedTLS                       0.5.11
 - Measures                      0.2.0
 - Media                         0.3.0
 - Missings                      0.2.10
 - Mustache                      0.3.3
 - Mux                           0.3.0
 - NLSolversBase                 6.1.1
 - NaNMath                       0.3.1
 - NamedTuples                   4.0.2
 - Nullables                     0.0.5
 - Optim                         0.15.1
 - PDMats                        0.8.0
 - Parameters                    0.9.0
 - Pidfile                       1.0.0
 - PlotThemes                    0.2.0
 - PlotUtils                     0.4.4
 - PlotlyBase                    0.1.2
 - PlotlyJS                      0.10.2
 - Plots                         0.17.2
 - Polynomials                   0.3.2
 - PositiveFactorizations        0.1.0
 - QuadGK                        0.2.1
 - Ratios                        0.2.0
 - RecipesBase                   0.3.1
 - Reexport                      0.1.0
 - Requests                      0.5.1
 - Requires                      0.4.4
 - ReverseDiffSparse             0.8.1
 - Rmath                         0.4.0
 - SHA                           0.5.7
 - ShowItLikeYouBuildIt          0.2.0
 - Showoff                       0.2.0
 - SortingAlgorithms             0.2.1
 - SpecialFunctions              0.6.0
 - StaticArrays                  0.7.2
 - StatsBase                     0.23.1
 - StatsFuns                     0.6.0
 - StringDistances               0.2.1
 - TableTraits                   0.2.0
 - TableTraitsUtils              0.1.3
 - Tokenize                      0.4.2
 - URIParser                     0.3.1
 - WebSockets                    0.5.0
 - WinRPM                        0.3.2
 - WoodburyMatrices              0.2.2

By the way, in the last error i posted here, it says it starts on the line 195. That line, is the last line of my code, wich is:

groupedbar([Dbefore Dafter], bar_position = :dodge, bar_width=0.7)

If i remove the using StatPlots and groupedbar([Dbefore Dafter], bar_position = :dodge, bar_width=0.7) commands, my code works fine. But when i add them, i get that error.

I think what may be happening is that instead of Vector{Float64} you’re getting Vector{Any} inside your code (for Dbefore and Dafter). you could try:

groupedbar(convert(Array{Float64}, [Dbefore Dafter]), bar_position = :dodge, bar_width=0.7)

and see if that fixes it. If that’s the case I’d also recommend figuring it out why you got Vector{Any} in the first place. For performance reasons (and to be able to call functions from other packages), it’d be much better to work with Vector{Float64}.

Yes, that was the problem. My Dbefore was Vector{Any} while the Dafter was Vector{Float64}

Thanks for your help piever!

EDIT: So, i tried running my code again (after it worked once with that convert function as a parameter for the groupedbar), and i’m getting this error now:

ERROR: LoadError: UndefVarError: groupedbar not defined
Stacktrace:
 [1] include_string(::String, ::String) at .\loading.jl:522
 [2] include_string(::Module, ::String, ::String) at C:\Users\Muril\.julia\v0.6\Compat\src\Compat.jl
:88
 [3] (::LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.La
stMain.Atom.##112#116{String,String})() at C:\Users\Muril\.julia\v0.6\Atom\src\eval.jl:109
 [4] withpath(::LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.Las
tMain.LastMain.Atom.##112#116{String,String}, ::String) at C:\Users\Muril\.julia\v0.6\CodeTools\src\
utils.jl:30
 [5] withpath(::Function, ::String) at C:\Users\Muril\.julia\v0.6\Atom\src\eval.jl:38
 [6] hideprompt(::LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.L
astMain.LastMain.Atom.##111#115{String,String}) at C:\Users\Muril\.julia\v0.6\Atom\src\repl.jl:67
 [7] macro expansion at C:\Users\Muril\.julia\v0.6\Atom\src\eval.jl:106 [inlined]
 [8] (::LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.LastMain.La
stMain.Atom.##110#114{Dict{String,Any}})() at .\task.jl:80
while loading C:\Users\Muril\AppData\Local\atom\app-1.28.0\Arquivos Feitos\dsadasdsa.jl, in expressi
on starting on line 196

It says groupedbar is not defined. Really odd, since i got the using StatPlots at the start of my code…
`

Hello everyone!

Today i had to update some packages in Atom (ink to 0.9.0, julia-client to 0.7.0, and other i can’t recall now). After the update, i’m not getting more error when using the workspace() and using StatPlots commands. But when i run my code, my graphic doesn’t appear in the Plot Tab.