# 2 problems with Gaston.jl

**URL:** https://discourse.julialang.org/t/2-problems-with-gaston-jl/70907
**Category:** Visualization
**Tags:** gaston
**Created:** [November 3, 2021, 6:51pm UTC](https://discourse.julialang.org/t/2-problems-with-gaston-jl/70907 "2021-11-03T18:51:16Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![trg818](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/trg818/32/219149_2.png) [@trg818](https://discourse.julialang.org/u/trg818)
#### Post date: [November 3, 2021, 6:51pm UTC](https://discourse.julialang.org/t/2-problems-with-gaston-jl/70907/1 "2021-11-03T18:51:16Z")

</div>

As it doesn’t (yet?) seem to be possible to create a plot with two different x-axes _and_ two different y-axes with Plots, I decided to give Gaston a try, because it would give me an interface to my good old Gnuplot, where that is possible. However, I encountered two problems:

1. My .profile and .gnuplot set GNUTERM to qt, but somehow the terminal type gets set to aqua (I’m on a Mac) when Gaston begins to execute the Gnuplot instructions, and that is an unknown terminal type. I don’t see how to get rid of it.
2. With other frontends like gc, it is possible to define the “framework” of a plot first, i.e., specify axes, title etc. before plotting the first curve. Hence, my routine procedure is always to set up the framework with some `plot(title=...)` etc. and then add the actual curves with `plot!()`. Isn’t this also possible with Gaston? When I try to do it my usual way, Gaston complains about the first two arguments being wrong, seemingly because they don’t specify x and y vectors. If it is really necessary to start with the first curve in the way all the examples in the docs do, I _strongly_ suggest to change that so that the framework of the plot can be set up first. It is a routine task to plot several curves in a loop, each being defined by the contents of some list or dict, but this becomes cumbersome if I have to plot the first curve when setting up the layout of the plot.

---

<div class="post-metadata">

### Author: ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)
#### Post date: [November 3, 2021, 9:21pm UTC](https://discourse.julialang.org/t/2-problems-with-gaston-jl/70907/2 "2021-11-03T21:21:18Z")

</div>

1. This is fixed in the development version (soon to be v2.0). In the mean time, a solution is to create a `~/.gnuplot` file and include the command `set term qt` there. You could also add `using Gaston; set(term=qt)` to your `.juliarc` startup file, but this will increase your Julia startup time.

2. This exact approach is not directly supported by Gaston, and not likely to be, because Gnuplot itself does not support plotting without data. However, a similar, simpler approach is possible. Say you want to plot both `x1` and `x2` against `t`. Then, you can do as follows. Note that the first `plot` requires the data for the first curve; support for plotting inside a loop will much better in v2.0, since `plot!()` will be allowed before `plot()`.

```julia
using Gaston

t = range(0, 1, length=11)
x1, x2 = randn(11), randn(11)

# "set up" the plot: all arguments here are
# translated to gnuplot set commands
A = Axes(grid = :on, title = :Test)

# "set up" the plotline for `x1`
p1 = "with lp linecolor 'red'"

# "set up" `x2`
p2 = "w p pt 5"

# plot
plot(t, x1, A, curveconf = p1)
plot!(t, x2, curveconf = p2)

```

which produces  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/6/b60b913b9ac5166d2ed3b30a46cd8a0f5a8c3bfe.png)

---

<div class="post-metadata">

### Author: ![trg818](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/trg818/32/219149_2.png) [@trg818](https://discourse.julialang.org/u/trg818)
#### Post date: [November 3, 2021, 11:09pm UTC](https://discourse.julialang.org/t/2-problems-with-gaston-jl/70907/3 "2021-11-03T23:09:41Z")

</div>

Thanks for clarifying and suggesting a solution. I do have some comments, though.  
It is true that one could edit ~/.gnuplot or ~/.juliarc, but I don’t think that would be a good solution for anybody, because it would interfere with the direct use of Gnuplot or, as you said, cause overhead in the general use of Julia. Luckily, I found with your advice that one can also have `using Gaston; set(term="qt")` in the program itself, and I think that’s the most adequate way.

> This exact approach is not directly supported by Gaston, and not likely to be, because Gnuplot itself does not support plotting without data.

My point is not to plot without data but to prepare the plot in the same manner as it can be done with other backends like, say, gc. This is also perfectly normal in Gnuplot itself, where you also would first set the layout of the plot; the plot command itself comes more or less last, because once it’s executed you cannot change things any more.  
The decision to allow `plot!()` before `plot()` seems odd to me, because to me it looks like modifying something before it has even been created; but I guess more experienced Julia users than me will judge this more knowledgeably.

---

<div class="post-metadata">

### Author: ![mbaz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbaz/32/17295_2.png) [@mbaz](https://discourse.julialang.org/u/mbaz)
#### Post date: [November 4, 2021, 12:46am UTC](https://discourse.julialang.org/t/2-problems-with-gaston-jl/70907/4 "2021-11-04T00:46:05Z")

</div>

> [@trg818](#):
>
> This is also perfectly normal in Gnuplot itself, where you also would first set the layout of the plot

I was confused; I thought that `Plots.jl` allowed you to run, for example, `plot(title="Plot")` and it would produce an empty plot with the specified title. Then, my suggestion is exactly what you need: The `Axes` type allows you to specify any Gnuplot `set` command. For example, `A = Axes(title = "'Plot'"); plot(x, y, A)` gets translated to `set title 'Plot'` followed by a `plot` command.

> [@trg818](#):
>
> The decision to allow `plot!()` before `plot()` seems odd to me

It is indeed a bit odd, and I resisted it for a while, but it’s just too convenient. Say you needed to plot the columns of a matrix `A`. This could be done with

```julia-auto
plot(A[:,1])
for i = 2:size(A)[2]
    plot!(A[:,i])
end

```

or, if `plot!()` is allowed first, the much more convenient

```julia-auto
for c in eachcol(A)
    plot!(c)
end

```

I welcome suggestions, though! `v2.0` is in an unfinished state on my hard drive, so there’s plenty of time to refine the API.
