gcalderone / Gnuplot.jl

Julia interface to gnuplot
Other
119 stars 16 forks source link

How to set title for multiplot with a string generated by a function? #65

Closed Sollovin closed 7 months ago

Sollovin commented 7 months ago

Hi, I'm trying to generate a series of multiplot figures, whose title is determined by a function:

function plotname(x::Int)
    return string("x-", x)
end

In gnuplot, the command to set a title for a multiplot is

set multiplot layout 1,2 title "YOUR_TITLE_HERE"

So what I'm trying to implement is a julia script like this

using Gnuplot

function plotname(x::Int)
    return string("x-", x)
end

@gp "set multiplot layout 1,2 title 'plotname(33)'"
@gp :- 1 1:5 :-
@gp :- 2 2:6

to plot a multiplot with title "x-33", but it do not work.

Maybe there are some julia tricks could help? Any suggestion is appreciated.

Sollovin commented 7 months ago

I think I found a workround as follows

using Gnuplot

function plotname(x::Int)
    return string("x-", x)
end

plottitle = plotname(33)
@gp "set multiplot layout 1,2 title '$plottitle'"
@gp :- 1 1:5 :-
@gp :- 2 2:6

# or
@gp "set multiplot layout 1,2 title '$(plotname(33))'"
@gp :- 1 1:5 :-
@gp :- 2 2:6