@df not defined

Hiya, this is the example given by Plots.jl for plotting with dataframe (Tutorial · Plots). But everytime I tried, it reported ERROR:

LoadError: UndefVarError: @df not defined

Is there anything I missed causing this error?

using StatsPlots # Required for the DataFrame user recipe
## Now let's create the DataFrame
using DataFrames
df = DataFrame(a = 1:10, b = 10 * rand(10), c = 10 * rand(10))
## Plot the DataFrame by declaring the points by the column names
@df df plot(:a, [:b :c])
2 Likes

I do not use Plots.jl but appears to me that the documentation is for the dev version, unless you have cloned master, you may be using a package that is old enough to not have the macro you are calling. Which is your version of Plots.jl?

Works for me.

I suggest you start a new environment and try again

] activate statsplots-test
] add StatsPlots DataFrames

@df is a macro defined in StatsPlots.jl

1 Like

I ran into the same problem when (because I mistyped) I installed and used the deprecated StatPlots (instead of StatsPlots) then removed it and installed StatsPlots. Consequently, @df was exported by both StatPlots and StatsPlots. The fully-qualified macro name, @StatsPlots.df, worked at that stage, but restarting allowed @df to work properly.

Perhaps something similar happened for you?

3 Likes

Out of my expectation, after moving to new environment my old packages are still available. This is awesome.

This shouldn’t happen, unless for example you initially installed things in the base environment (@v1.5 for example). I would advise only putting things you use for development (Revise, Benchmark tools and the like) in the base environment - anything used in your actual project should be in that project’s Project.toml

2 Likes

maybe df is ambiguous.

@df refer to df(datafram)