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

**URL:** <https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341>\
**Category:** Package Announcements\
**Tags:** visualization, gnuplot\
**Created:** [April 10, 2020, 1:52pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341 "2020-04-10T13:52:55Z")\
**Posts on this page:** 18\
**Page:** 3

<div class="post-metadata">

**Author:** ![lyonsquark](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lyonsquark/32/4483_2.png) [@lyonsquark](https://discourse.julialang.org/u/lyonsquark)\
**Post date:** [May 2, 2020, 4:29pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/41 "2020-05-02T16:29:19Z")

</div>

Thanks! That works great!

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [May 21, 2020, 9:28pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/42 "2020-05-21T21:28:22Z")

</div>

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

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

```

for the really basic functionality?

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

---

<div class="post-metadata">

**Author:** ![gcalderone](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gcalderone/32/1539_2.png) [@gcalderone](https://discourse.julialang.org/u/gcalderone)\
**Post date:** [May 21, 2020, 9:54pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/43 "2020-05-21T21:54:13Z")

</div>

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.:

```julia
@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…

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [May 21, 2020, 10:06pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/44 "2020-05-21T22:06:38Z")

</div>

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

```julia
# 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.

---

<div class="post-metadata">

**Author:** ![gcalderone](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gcalderone/32/1539_2.png) [@gcalderone](https://discourse.julialang.org/u/gcalderone)\
**Post date:** [May 21, 2020, 10:23pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/45 "2020-05-21T22:23:28Z")

</div>

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

```julia
@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:

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

```

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [May 21, 2020, 10:32pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/46 "2020-05-21T22:32:44Z")

</div>

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

I think I’ll probably just write it up myself

---

<div class="post-metadata">

**Author:** ![gcalderone](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gcalderone/32/1539_2.png) [@gcalderone](https://discourse.julialang.org/u/gcalderone)\
**Post date:** [May 21, 2020, 10:35pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/47 "2020-05-21T22:35:25Z")

</div>

Yes, of course!

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

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [May 22, 2020, 5:48am UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/48 "2020-05-22T05:48:41Z")

</div>

I started it here: [GitHub - tbeason/GnuplotSimple.jl: A simple plotting recipe for using Gnuplot.jl](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.

---

<div class="post-metadata">

**Author:** ![gcalderone](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gcalderone/32/1539_2.png) [@gcalderone](https://discourse.julialang.org/u/gcalderone)\
**Post date:** [May 23, 2020, 4:39pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/49 "2020-05-23T16:39:30Z")

</div>

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:

```julia
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))
    end
    return out
end

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"])

```

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [May 23, 2020, 5:03pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/50 "2020-05-23T17:03:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [July 12, 2020, 9:47am UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/52 "2020-07-12T09:47:36Z")

</div>

Hello,  
I did some recipes and uploaded some examples at [Plotting Market Data from AlphaVantage.jl with Gnuplot.jl - Nextjournal](https://nextjournal.com/lazarus/plotting-market-data-from-alphavantagejl-with-gnuplotjl). Take a look.

 ![Screenshot 2020-07-12 at 11.35.58](https://global.discourse-cdn.com/julialang/original/3X/d/2/d2130677e1c5f82cb4addac8f1433875a49fb780.png) ![Screenshot 2020-07-12 at 11.34.20](https://global.discourse-cdn.com/julialang/original/3X/f/a/fac4877281dc6285e03cb9db48a462fd49ef2e3a.png) ![Screenshot 2020-07-12 at 11.34.13](https://global.discourse-cdn.com/julialang/original/3X/2/a/2af81f26b7b2f11cd26972216a5e4780d2e20171.png) ![Screenshot 2020-07-12 at 11.34.01](https://global.discourse-cdn.com/julialang/original/3X/d/4/d475d1098ad33b5e73d1a34d4bb9c447bf28bd31.png)

---

<div class="post-metadata">

**Author:** ![Alois](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alois/32/22558_2.png) [@Alois](https://discourse.julialang.org/u/Alois)\
**Post date:** [March 5, 2021, 1:39pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/53 "2021-03-05T13:39:18Z")

</div>

Dear gcalderone,  
I am struggling with gnuplot.jl and dates. Copying your example code throws:  
ERROR: LoadError: AssertionError: Invalid argument at position 1.  
Are there any changes I am not aware of? (I am on windows, if this matters at all).  
Thank you in advance

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [March 5, 2021, 1:43pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/54 "2021-03-05T13:43:59Z")

</div>

which example? Could you copy paste here? or a link…

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [March 5, 2021, 1:56pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/55 "2021-03-05T13:56:28Z")

</div>

He means the example of @gcalderone which he replied to:

```julia
using Gnuplot, Dates

dates = [Date(2020, 4, floor.(Int, x .* 30 .+ 1)) for x in rand(10)]
val=rand(10)

@gp "set xdata time" "set timefmt '\"%Y-%m-%d\"'" :-
@gp :- "set format x '%Y-%m-%d'" "set xtics rotate by -45" :-
@gp :- "set rmargin 7" :-
@gp :- string.(dates) val "u 1:2 w p notitl"

```

I can confirm, i get the same error.

The @gp makro here doesn’t accept an array of strings. This is the code, which leads to the error:

```julia
       d = args[iarg]

        ok = false
        if typeof(d) <: Number
            ok = true
        elseif typeof(d) <: AbstractArray
            if typeof(d[1]) <: Number
                ok = true
            end
            if typeof(d[1]) <: ColorTypes.RGB
                ok = true
            end
        end
        if ndims(d) > maxDim
            maxDim = ndims(d)
        end

        @assert ok "Invalid argument at position $iarg"

```

in src\Gnuplot.jl line 294.

---

<div class="post-metadata">

**Author:** ![Alois](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alois/32/22558_2.png) [@Alois](https://discourse.julialang.org/u/Alois)\
**Post date:** [March 5, 2021, 2:15pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/56 "2021-03-05T14:15:24Z")

</div>

Yes, this example.  
It would be a smart idea to add a working example involving dates to your list of examples here, [https://lazarusa.github.io/gnuplot-examples/](https://lazarusa.github.io/gnuplot-examples/),  
which is a perfect reference for gp.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [March 5, 2021, 2:21pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/57 "2021-03-05T14:21:04Z")

</div>

In the mean time I was trying to produce a plot (Windows 10, J v1.5.3, GP v1.0.0) but it doesn’t work.

I stop now because after reading  
[https://gcalderone.github.io/Gnuplot.jl/v1.3.0/options/#Display-options-1](https://gcalderone.github.io/Gnuplot.jl/v1.3.0/options/#Display-options-1)

and finding that `Gnuplot.options` doesn’t exist, I give up.

There is either something trivial missing, which one needs to know, or there is a major issue with v1.0.0 and Windows. Let’s see if @gcalderone can give us a hint.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [March 5, 2021, 2:50pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/58 "2021-03-05T14:50:13Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/8/b/8bcdd351c8f1100ffa06ba1c5ff0e76f30dedd48.png)  
Works with

```julia
using Gnuplot, Dates

dates = [Date(2020, 4, floor.(Int, x .* 30 .+ 1)) for x in rand(10)]
val=rand(10)

@gp "set xdata time" :-
@gp "set timefmt '\"%Y-%m-%d\"'" :-
@gp :- "set format x '%Y-%m-%d'" "set xtics rotate by -45" :-
@gp :- "set rmargin 7" :-
@gp :- string.(dates) val "u 1:2 w p notitl"

```

Julia 1.6 on Windows 10.

Edit: better esthetics.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/2/5/25d89645de14ebab78cf300785ef0eae2f60c794.png)

```julia
using Gnuplot, Dates

dates = [Date(2020, 4, floor.(Int, x .* 30 .+ 1)) for x in rand(10)]
val=rand(10)

@gp "set xdata time" :-
@gp :- "set timefmt '\"%Y-%m-%d\"'" :-
@gp :- "set format x '%Y-%m-%d'" "set xtics rotate by -45" :-
@gp :- "set rmargin 7" :-
@gp :- "set style line 1 lc rgb 'blue' lt 1 lw 8 pt 7 ps 2.0" :-
@gp :- string.(dates) val "u 1:2 ls 1 notitl"

```

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [March 5, 2021, 2:50pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/59 "2021-03-05T14:50:23Z")

</div>

ok, It’s not easy to give up, so I tried further.

My conclusion is, install Gnuplot.jl v1.3.0:

```julia
(@v1.6) pkg> add Gnuplot@1.3.0

```

I had issues with Julia 1.5.3, so I tried with 1.6 and voila, it works now as in the example.

(Ninja’d by @PetrKryslUCSD ) 🙂

[Previous page](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341.md?page=2)
