Problem with scatter plot of a dataframe

This code doesn’t plot anything:

using Plots
using DataFrames
df = DataFrame(a=rand(30), b=rand(30), c=repeat(["a", "b", "c"], outer=10));
g = groupby(df, "c");
scatter()
for (s, x) in pairs(g)
    scatter!(x[!, "a"], x[!, "b"])
end

However, this seems to work just fine:

scatter()
scatter!(g[1][!, "a"], g[1][!, "b"])
scatter!(g[2][!, "a"], g[2][!, "b"])
scatter!(g[3][!, "a"], g[3][!, "b"])

Versions:

% julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.6.3 (2021-09-23)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

(@v1.6) pkg> st Plots GR DataFrames
      Status `~/.julia/environments/v1.6/Project.toml`
  [a93c6f00] DataFrames v1.2.2
  [28b8d3ca] GR v0.62.1
  [7073ff75] IJulia v1.23.2
  [91a5bcdd] Plots v1.23.5

(@v1.6) pkg>

Thanks

Oops. Problem is nothing returned from for loop.
Need an additional call to plot!()

1 Like