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])
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?
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.
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