Enhancement: a `gnuplot>` REPL mode
favba opened this issue · 8 comments
Thank you for this amazing package!
What do you think of providing a gnuplot>
REPL mode where one could interact with gnuplot 'directly', similarly to the shell mode.
The ReplMaker package could be used for that.
Nice suggestion! I'll include it in the next version.
A tentative implementation is as follows:
using REPL, ReplMaker, Gnuplot
function gnuplot_repl(start_key='>')
function repl_exec(s)
restore = Gnuplot.options.verbose
Gnuplot.options.verbose = true
gpexec(s)
Gnuplot.options.verbose = restore
nothing
end
function repl_isvalid(s)
input = strip(String(take!(copy(REPL.LineEdit.buffer(s)))))
input[end] != '\\'
end
initrepl(repl_exec,
prompt_text="gnuplot> ",
prompt_color = :blue,
start_key=start_key,
mode_name="Gnuplot",
valid_input_checker=repl_isvalid)
end
Comments / issue with the above approach?
Tested with julia 1.3.1, Gnuplot.jl 1.1.0 and gnuplot 5.2 - it works.
Before I forget to mention: I LOVE THIS PACKAGE!
I've just tested it and it works really well!
The only thing missing that I think would be useful is a way of interpolating julia data to the gnuplot repl.
If we use $
for that, then one could do things like:
julia> x = -1:0.1:1;
julia> y = my_complex_func.(x)
# start gnuplot repl
gnuplot> set logscale y
gnuplot> set xtics $x
gnuplot> plot $(zip(x,y)) w l
This probably makes the implementation much more complex, but a lot seems to be already coded for the @gp
macro...
OK, I added the code in the master branch:
Line 1822 in 44a7ea2
It will be available in the next release (hopefully next week...).
gnuplot> plot $(zip(x,y)) w l
This is definitely not an easy task. I'll think about it, but it would hardly be in the next release....
Don't forget to call repl_init() to actually make the mode available :) Or do you want to leave it optional?
I don't think the REPL mode should be enabled by default:
it is definitely useful to familiarize with the package, or during data exploration to issue commands directly on gnuplot.
On the other hand, it is not an essential feature once plotting become just a step in a more complex workflow. In this case one is arguably concerned with results shown on the plots, and may even ignore there is an underlying gnuplot process running.
So its usefulness depends on how you use it, but if we enable it by default we will occupy one of the few available keys (>
, }
, )
) of a global resource (the REPL itself), and this may seems too "intrusive"...
I implemented the REPL mode and drafted a new release candidate.
Install with:
]add Gnuplot#v1.2.0-rc
The relevant section in the new documentation is here.
Please file an issue if you find any problem.
Implemented in v1.2.0