GiovineItalia / Gadfly.jl

Crafty statistical graphics for Julia.
http://gadflyjl.org/stable/
Other
1.91k stars 250 forks source link

Easier plotting of 2D array data #327

Closed andrewsimper closed 7 years ago

andrewsimper commented 10 years ago

I've got data in a 2D array and would love to plot it easily with Gadfly. Right now I have to jump through the hoops of DataFrames which goes something like:

data = # a 2D array of Float64, the first column is time, the next ones are different signals df = vcat( DataFrame(f=["input" for i in 1:dlen], x=data[:,1], y=data[:,2]), DataFrame(f=["lp" for i in 1:dlen], x=data[:,1], y=data[:,3]), DataFrame(f=["hp" for i in 1:dlen], x=data[:,1], y=data[:,4]) ) plot(df, x=:x, y=:y, color=:f, Geom.line)

Which is a whole lot of not much fun.

I have a feature request: I would love if I could pass a 2D array to Gadfly and use column indexes to plot the signals, and get the colours allocated by column index for me:

plot(data, x=1, y=[2:4], Geom.line)

dcjones commented 10 years ago

I like the idea of defining plot methods that make plotting particular types convenient. One concern I have here is that if someone passed a matrix to plot they might expect to get a heatmap and be surprised when they see points or lines.

andrewsimper commented 10 years ago

In packages like Mathematica everything is lines / dots unless you specifically make another call, eg for a heatmap you would have to call DensityPlot: http://reference.wolfram.com/mathematica/ref/DensityPlot.html

Also in this case you could actually infer what is wanted directly from the arguments. If you pass in a 2D array but not specify x or y indexes then you could plot it as a density plot, but with x and y specified there is no confusion as to what you want.

lucasb-eyer commented 10 years ago

+1

I was looking for exactly this today (and figured the same workaround.)

Relatedly, how would I set the lines' colors? Geom.line([c1, c2, c3, ...])? For now, I chose between a "gradient" of colors or distinct colors by having the f field in @andrewsimper's example being a number or a string, respectively, which feels even more hacky.

lucasb-eyer commented 10 years ago

Would that best be dealt with by adding another plot signature to poetry.jl, or by making render(::LineGeometry, ...) aware of a matrix y? In the latter case, there's a bit more to do, because this line in render(::Plot) (I didn't dig deeper than that) flattens y, losing all dimensionality information.

diegozea commented 10 years ago

+1

bjarthur commented 7 years ago

closed by https://github.com/GiovineItalia/Gadfly.jl/pull/1013