5

In Julia, is there a way to plot a dataframe similarly to df.plot() in Python's Pandas?

More specifically, I am using Plots, plotlyjs() and the DataFrames package.

Joris Limonier
  • 681
  • 1
  • 10
  • 27

2 Answers2

8

Just to add to Przemyslaw answer, there's an extension of Plots.jl called StatsPlots.jl which provides lots of extra methods and macros to plot DataFrames in a concise way while also including things like grouping variables in the data etc.

Worth checking out the full readme over there to see what it can do, but two equivalent ways of achieving the same output you see in Prezemyslaw's answer are:

julia> @df df plot([:series1 :series2 :series3])

or, more concisely:

julia> @df df plot(cols())

Note in either case StatsPlots will label the series according to the names of their respective source columns automatically.

Nils Gudat
  • 13,222
  • 3
  • 39
  • 60
7

Suppose you have a DataFrame:

using DataFrames, Plots
df = DataFrame(series1 = 1:10, series2 = sin.(1:10), series3=rand(10));

Than you can do:

plot(Matrix(df), labels=permutedims(names(df)), legend=:topleft)

enter image description here

Przemyslaw Szufel
  • 40,002
  • 3
  • 32
  • 62