[ANN]: Gnuplot v1.1.0 - A Julia interface to gnuplot

Thanks! That works great!

Maybe this sort of goes against the whole idea but have you considered creating a second package, maybe GnuplotSimple.jl, that wraps the necessary functionality to make basic plotting easier? I am starting to get the hang of all of this, and I’m sure there are shortcuts I don’t yet know about, but it does seem a bit excessive in terms of LOC to make even the easiest of line plots.

Something like

function gnuplot(x,Y; title="", xlab="", ylab="", labels="", grid=true, xr=nothing, yr=nothing, save=false)
# all the @gp stuff
# save commands if asked

for the really basic functionality?

Anyways, this is likely my main plotting package for now.

One of the main driving idea of Gnuplot.jl is indeed to save typing as much as possible, and you can already pass x, y and many of the keywords you mentioned directly to @gp, e.g.:

@gp x y
@gp x y "w l"
@gp xlab="X" x y
@gp xr=[1,5] x y

I’m afraid that trying to be even more concise, may only result in a loss of generality…

In your case, no keyword is foreseen for terminal options and output file names, hence I guess you want to hardcode them in the function body to save typing. This is perfectly fine, but this would hardly be a general solution…

I understand. So maybe you could provide me with a hint then. Suppose I am plotting 3 lines, each against the same x points, and I want to assign a label to each line. Let’s also say I want to plot from [0,1] only, and label each axis and the plot itself.

Do I need to write out

# setup
x = 0:0.05:2
y = x.^(1:3)'
# I won't count these lines against you :)

@gp "set grid"
@gp :- tit="The Example" xlab="My x" ylab="The y value" xr=[0,1]
@gp :- x y[:,1] "w l tit 'y1'"
@gp :- x y[:,2] "w l tit 'y2'"
@gp :- x y[:,3] "w l tit 'y3'"

or is there a shorter way?

Also, to be clear, my suggestion dealt with cases like this example. Certainly, you could not wrap all functionality in a plot function like that. But it is not often that you need to rapidly build plots that use all of the sophisticated features.

Yes, a shorter way (but hopefully still readable…) is:

@gp "set grid" ti="The Example" xla="My x" yla="The y value" xr=[0,1]
@gp :- x y[:,1] "w l t 'y1'" x y[:,2] "w l t 'y2'" x y[:,3] "w l t 'y3'"

Also, if you’re simply exploring data and don’t care about aesthetic details, you may simply type:

@gp x y[:,1] "w l" x y[:,2] "w l" x y[:,3] "w l"
1 Like

Forgive me if I don’t find that vastly better than what I wrote :wink:

I think I’ll probably just write it up myself

1 Like

Yes, of course!

Just consider that I don’t think you could get anything shorter with other plotting packages… :wink:

I started it here: https://github.com/tbeason/GnuplotSimple.jl

Have not done extensive testing, but it does work well enough for the stuff I’ve tried so far.

I stumbled upon your recipe example and thought it would work well if I built it off of that, so I did.

OK, now I got it! You want shortcut to plot the columns of the Y matrix against the x values.

Here’s how I would do it:

using Gnuplot

# Define an explicit recipe for this particular problem
function multiY(x::AbstractVector{Float64}, Y::AbstractMatrix{Float64}, labels=Vector{String})
    out = Vector{Gnuplot.PlotElement}()
    for i in 1:size(Y)[2]
        plotspec = "w l t '$(labels[i])'"
        push!(out, Gnuplot.PlotElement(data=Gnuplot.Dataset([x, Y[:, i]]), plot=plotspec))
    return out

x = 0:0.05:2
y = x.^(1:3)'

@gp "set grid" tit="The Example" xlab="My x" ylab="The y value" xr=[0,1]
@gp :- multiY(x, y, ["y1", "y2", "y3"])

Yea! That is pretty much what I did, but I just fancied it up a bit, so that I can include everything in that single call. Feel free to steal it and improve it lol

1 Like