Warning: when using both Plots and StatsPlots

I am working on a package which has both Plots and StatsPlots added. When using density from StatsPlots, even I use StatsPlots.density(blah), I got a warning twice for each density call:

┌ Warning: seriestype density has been moved to StatsPlots. To use: Pkg.add("StatsPlots"); using StatsPlots
└ @ Plots ~/.julia/packages/Plots/w4QRq/src/args.jl:1178
┌ Warning: seriestype density has been moved to StatsPlots. To use: Pkg.add("StatsPlots"); using StatsPlots
└ @ Plots ~/.julia/packages/Plots/w4QRq/src/args.jl:1178

The plot is working, but the warning is annoying. Any suggestion?

Why are you using both Plots and StatsPlots? StatsPlots is basically Plots with additional bells and whistles, so when you’re using StatsPlots you shouldn’t have to load Plots?

I removed Plots, the warnings still stick.

Hm, that’s odd. Can you just run the following in a fresh REPL?

julia> using StatsPlots

julia> density(rand(100))

(@v1.5) pkg> st StatsPlots
Status `~/.julia/environments/v1.5/Project.toml`
  [f3b207a7] StatsPlots v0.14.17

This works for me without warning

1 Like

I am using the same version of StatsPlots. Above gave no warning on my machine either.

I just found the problem. That is, I used Plots.measures somewhere. So, even I exclude Plots everywhere except Plots.Measures, I have the warnings. I don’t know how to circumvent those if am using .Measures.

Hm, could you post an MWE? When I do

julia> using StatsPlots

julia> Plots.Measures
Measures

julia> density(rand(100), margin = 5Plots.mm)

I still don’t get the warning.

Two other options:

  • Try explicitly qualifying StatsPlots.density
  • Use Suppressor.jl to suppress the warning

Thanks a lot. I don’t know when and where I messed the codes in the project. The warnings came back into it again. As before, explicitly using StatsPlots.density won’t work either. Purely run you codes won’t give warnings. I will temporarily use Suppressor. Hope I can find the bug later.

I think, that the problem is in the following code !isdefined(Main, :StatsPlots) from Plots (v1.10.0 in args.jl:1178). It checks if the StatsPlots is loaded in the Main, so a warning will not appear if code is run directly from REPL

julia> using StatsPlots

julia> density()

However, if the StatsPlots is loaded in a different module (let say in module A), the warning will appear

julia> module A
           using StatsPlots
       end
Main.A

julia> using .A

julia> A.density()
┌ Warning: seriestype density has been moved to StatsPlots.  To use: `Pkg.add("StatsPlots"); using StatsPlots`
└ @ Plots ~/.julia/packages/Plots/IjNHT/src/args.jl:1178

julia> isdefined(Main, :StatsPlots)
false

julia> isdefined(A, :StatsPlots)
true

The solution is to load StatsPlots in the Main module.

This is happening in pluto notebooks and can you help suppress them ?
using Suppressor.jl did not work.

That was fixed in recent versions of Plots