# \[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:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [April 12, 2020, 4:26pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/21 "2020-04-12T16:26:04Z")

</div>

I’d like to mention also the [not so Frequently Asked Questions](http://folk.uio.no/inf3330/scripting/doc/gnuplot/Kawano/index-e.html), it’s a great resource about gnuplot.

---

<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:** [April 13, 2020, 12:50am UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/22 "2020-04-13T00:50:27Z")

</div>

No, it can’t. And the reason is that there would be many details in the plot (such as the individual color lines, point symbols, etc… ) which would hardly be customizable, while **Gnuplot.jl** aims to provide fine control over all the details of a plot.

Still, you may implement a simple quicklook function, in the form of a _plot recipe_.  
**NOTE** : these are not yet available in the released version!  
But if you download the `master` branch (`]dev Gnuplot`) you may try the following code:

```julia
using RDatasets, DataFrames, Gnuplot
import Gnuplot: PlotRecipe, DataSetText

function plotdf(df::DataFrame, colx::Symbol, coly::Symbol; group=nothing)
    if isnothing(group)
        return PlotRecipe(data=DataSetText(df[:, colx], df[:, coly]),
                          plot="w p notit",
                          xlab=string(colx), ylab=string(coly))
    end

    data = Vector{Gnuplot.DataSet}()
    plot = Vector{String}()
    for g in sort(unique(df[:, group]))
        i = findall(df[:, group] .== g)
        if length(i) > 0
            push!(data, DataSetText(df[i, colx], df[i, coly]))
            push!(plot, "w p t '$g'")
        end
    end
    return PlotRecipe(data=data, plot=plot,
                      xlab=string(colx), ylab=string(coly))
end

```

The recipe can be used as follows:

```julia
iris = dataset("datasets", "iris")
@gp plotdf(iris, :SepalLength, :SepalWidth)
@gp plotdf(iris, :SepalLength, :SepalWidth, group=:Species)

```

And the output is:  
 ![plotdf](https://global.discourse-cdn.com/julialang/original/3X/a/6/a6ac08c3b338df7c3797c80fcb2f6f104bec7810.png)

---

<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:** [April 13, 2020, 1:01am UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/23 "2020-04-13T01:01:27Z")

</div>

Wow - That’s very cool! Thanks - will try it!

---

<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:** [April 13, 2020, 1:53pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/24 "2020-04-13T13:53:42Z")

</div>

Although a solution with a recipe is elegant and clean, it’s not hard to do it without one. I added 4 examples in the gallery page.

- [Iris data set](https://lazarusa.github.io/gnuplot-examples/menu1/#iris_data_set)
- [cars](https://lazarusa.github.io/gnuplot-examples/menu1/#cars)
- [gapminder](https://lazarusa.github.io/gnuplot-examples/menu1/#gapminder)
- [flights](https://lazarusa.github.io/gnuplot-examples/menu1/#flights) [the one you asked for]

```julia
using HTTP, CSV, DataFrames, Gnuplot, Random
using ColorSchemes, Colors, DataFramesMeta
url = "https://raw.githubusercontent.com/alstat/Julia-Data-Query/master/data-raw/flights.csv"
data = HTTP.download(url)
flights = CSV.read(data)
# @df flights plot(:Day, :NumFlights, group=:City)
#this is all the help you need
daily = groupby(flights, [:day, :dest]) # :origin, only 3 (boring)
per_day = @based_on(daily, flights = length(:day))
byCat = per_day.dest
categ = unique(byCat)
# aesthetics
@gp xlab ="day" ylab = "number of flights" "set auto fix"
@gp :- title = "Flights" :-
@gp :- "set offsets graph .05, graph .05, graph .05, graph .05" :-
@gp :- "set key outside font ',8' title 'destination'" :-
@gp :- "set logscale y 2" yrange = (0.8,700)
cmap = get(colorschemes[:rainbow1], LinRange(0,1,length(categ)))
# the actual plot
Random.seed!(213)
for (i,c) in enumerate(categ)
    indc = findall(x->x == c, byCat)
    x, y = per_day.day[indc], per_day.flights[indc]
    @gp :- x y "w linespoints tit '$(c)' lc '#B3$(hex(cmap[i]))' pt $(rand(5:2:13)) ps 0.5"
    lx = length(x)
    rlx = rand(1:lx)
    @gp :- "set label '$(c)' at $(x[rlx]-0.4),$(y[rlx]) font ',5' front"
end
save(term ="pdf size 4,5", output ="flights_ptslines.pdf")

```

 ![flights_ptslines](https://global.discourse-cdn.com/julialang/original/3X/e/4/e4f087412eed56f404205fe2c81123a07f1bb758.png)

All the best, and looking forward for the recipe proposal from @gcalderone.

---

<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:** [April 13, 2020, 3:50pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/25 "2020-04-13T15:50:46Z")

</div>

Thanks! Those are fantastic examples! – Adam

---

<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:** [April 14, 2020, 4:24pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/26 "2020-04-14T16:24:12Z")

</div>

Thanks again for the all the examples! I was trying to get plots to appear in a Jupyter Notebook. I wrote a very yucky way to do it. The issue is that `@gp`, `@gps` don’t return anything. An object needs to be returned and `Base.show` overloaded to display it. Here’s what I did,

```julia
# We don't want the qt terminal, as it steals the window focus after displaying a plot
@gp "set term unknown"

# We need an object that will represent a plot
struct AGnuPlot
    fileName::String
end

# IJulia will call this function to display AGnuPlot
import Base.show
function Base.show(io::IO, ::MIME"image/svg+xml", x::AGnuPlot)
    # Read in the file
    write(io, read(x.fileName, String))
end

# Function to trigger IJulia into showing the plot
# We'll write the current plot to a svg file. Once AGnuPlot is returned, IJulia will run Base.show on it
# and the plot should appear
const gnuplotout_file = "/tmp/gnuplotout"
function p()
    save(term="svg", output=gnuplotout_file) # Writing to a file is yucky, but it works
    return AGnuPlot(gnuplotout_file)
end

@gp "p sin(x)" ; p()

```

Maybe that’s helpful. Perhaps integration with IJulia, Juno, VSCode is on your roadmap.

Thanks again for this great package!

---

<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:** [April 15, 2020, 9:34am UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/27 "2020-04-15T09:34:17Z")

</div>

Thanks for working this out!  
I’ll think about it and try to found a nice way to include it in the next version.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [April 15, 2020, 12:08pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/28 "2020-04-15T12:08:55Z")

</div>

I made a PR for it: [https://github.com/gcalderone/Gnuplot.jl/pull/17](https://github.com/gcalderone/Gnuplot.jl/pull/17)

---

<div class="post-metadata">

**Author:** ![Zhong\_Pan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zhong_pan/32/19872_2.png) [@Zhong\_Pan](https://discourse.julialang.org/u/Zhong_Pan)\
**Post date:** [April 19, 2020, 6:48pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/29 "2020-04-19T18:48:05Z")

</div>

Thanks!!! This allows me to send plot with data to my colleague, who does not need Julia to view and/or post-process the plot, which is a nice feature.

One minor question: is there a way to easily suppress the printout of messages from Gnuplot process unless there is a critical error, while not affecting other printing (i.e. not a workaround of redirecting the stdout)?

If I make a package that uses Gnuplot for plotting, I prefer not to show a lot of messages unless it is necessary (e.g. when something did go wrong and the plot wouldn’t work). Is this achievable by changing a setting somewhere, either in Gnuplot.jl or Gnuplot software itself?

Thanks!

---

<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:** [April 19, 2020, 8:27pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/30 "2020-04-19T20:27:27Z")

</div>

No message should be displayed on stdout unless:

- gnuplot raised an error;
- you set `Gnuplot.options.verbose = true`.

If you still see messages please open an issue on the [repo](https://github.com/gcalderone/Gnuplot.jl) describing how to replicate, and the messages you get.

---

<div class="post-metadata">

**Author:** ![Zhong\_Pan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zhong_pan/32/19872_2.png) [@Zhong\_Pan](https://discourse.julialang.org/u/Zhong_Pan)\
**Post date:** [April 19, 2020, 9:33pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/31 "2020-04-19T21:33:59Z")

</div>

Thanks! It works.

---

<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:** [April 20, 2020, 5:34pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/32 "2020-04-20T17:34:01Z")

</div>

Dear all,  
this is a small update to announce that a new version of [Gnuplot.jl](https://github.com/gcalderone/Gnuplot.jl) (v1.2.0) is now available, introducing the following functionalities:

- A gnuplot [REPL](https://gcalderone.github.io/Gnuplot.jl/v1.2.0/advanced/#The-gnuplot-REPL-1) is now available ([#14](https://github.com/gcalderone/Gnuplot.jl/issues/14));
- Plots are now automatically displayed in Jupyter and Juno ([#17](https://github.com/gcalderone/Gnuplot.jl/pull/17));
- The [plot recipe](https://gcalderone.github.io/Gnuplot.jl/v1.2.0/recipes/) mechanism has been implemented;

Full list of changes is available in the [ChangeLog](https://github.com/gcalderone/Gnuplot.jl/blob/master/ChangeLog.md).

Enjoy!

---

<div class="post-metadata">

**Author:** ![j2b2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j2b2/32/3387_2.png) [@j2b2](https://discourse.julialang.org/u/j2b2)\
**Post date:** [April 21, 2020, 9:35am UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/33 "2020-04-21T09:35:50Z")

</div>

Could someone post a _simple_ example showing fundamental differences between packages `Gnuplot` and `Plots` ?

---

<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:** [April 21, 2020, 11:06am UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/34 "2020-04-21T11:06:12Z")

</div>

I’m afraid _simple_ examples don’t tell much, i.e.:

```julia
using Gnuplot, Plots
x = 1:10; y = rand(10);
@gp x y
plot(x, y)

```

On the other hand, it is very difficult to envisage _complex_ examples of sufficiently general interest, able to discriminate against one or the other.

IMHO, the best approach is to try to solve a specific problem (e.g. [here](https://discourse.julialang.org/t/fill-a-curve-in-3d/37890/3)).  
Or have a look at the example galleries

Specific resources for Gnuplot.jl are [here](https://gcalderone.github.io/Gnuplot.jl/v1.2.0/) and [here](https://lazarusa.github.io/gnuplot-examples/), but consider that any other gnuplot example (e.g. the official [demos](http://gnuplot.sourceforge.net/demo_5.2/)) can be reproduced from Julia.

---

<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:** [April 21, 2020, 11:56am UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/35 "2020-04-21T11:56:06Z")

</div>

The most fundamental difference is: gnuplot is old, hence mature. The oldest reference I found with a quick search is from 1992 ([gnuplot for Windows : Free Download, Borrow, and Streaming : Internet Archive](https://archive.org/details/WGNUPLOT_ZIP))  
😃

Julia is young, Plots.jl is even younger and even most (or none? didn’t check.) of the backends of Plots.jl didn’t exist when gnuplot was already old 😉 And I remember using it as a student on a silicon graphics machine (hmmm, must find what it was later) in between some time not playing mtrek (online) by Chuck L. Peterson .

I know, that wasn’t the question, but I like to mention it anyways.

---

<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:** [April 21, 2020, 12:01pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/36 "2020-04-21T12:01:48Z")

</div>

> [@oheil](#):
>
> gnuplot is old, hence mature.

Correct, but is also actively maintained (current [stable version](http://gnuplot.info/download.html) released on Dec. 2019).

---

<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:** [April 21, 2020, 12:05pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/37 "2020-04-21T12:05:42Z")

</div>

Right. This is an important note I forgot to mention!

---

<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, 12:10am UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/38 "2020-05-02T00:10:06Z")

</div>

In case someone else runs into this annoying problem… When I `save(term="pngcairo", output="out.png")` or with `term="pdfcairo"`, I get a mangled output with all text kinda printed on top of each other. Looks very ugly. This is apparently a “feature” in `pango` (the library that `cairo` uses for text). The latest version v1.44 no longer supports Freetype fonts (see [Pango future directions | Goings on](https://blogs.gnome.org/mclasen/2019/05/25/pango-future-directions/)). You can repair this by downgrading your version of `pango` to v1.43. For the Mac, see [macos - Gnuplot PDF Terminal Exhibits Font Issues on Mac - Stack Overflow](https://stackoverflow.com/questions/57698204/gnuplot-pdf-terminal-exhibits-font-issues-on-mac) for instructions.

---

<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, 12:24am UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/39 "2020-05-02T00:24:55Z")

</div>

Does anyone know a good way to deal with plotting things against dates? They only way I’ve figured out how to do it is with a named dataset. For example,

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

name = "\$thedata"
@gp name => ( string.(df.Date), df.val)
@gp :- "set xdata time" :-
@gp :- "set format x '%Y-%m-%d'" "set xtics rotate by -45" :-
@gp :- "set rmargin 7" :-
@gp :- "p $name u (strptime('%Y-%m-%d', strcol(1))):2 w p notitl"

```

![date](https://global.discourse-cdn.com/julialang/original/3X/3/5/357ddf7468088df5a2761ddd24f3a2f096a5f927.png)

Is there a way to do this without having to make a named dataset? Thanks! – Adam

---

<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 2, 2020, 12:35pm UTC](https://discourse.julialang.org/t/ann-gnuplot-v1-1-0-a-julia-interface-to-gnuplot/37341/40 "2020-05-02T12:35:56Z")

</div>

Yes, simply use the data in the `@gp` call, e.g.:

```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"

```

Note that you can specify a global time format for reading with `set timefmt`. Also, **Gnuplot.jl** writes string within double quotes, hence you need to specify those as well in `timefmt` Finally, note that when plotting time/data the `using` clause is mandatory, although in this case it simply amounts to `using 1:2`.

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

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