2 problems with Gaston.jl

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.
1 Like
  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().

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

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.

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.

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

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

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

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.

2 Likes