Repository navigation
GnuplotRB loops undefinitely when trying to generate a histogram #10
Description
Activity
Hi!
Yeah, unfortunately there is a problem in this particular case because of difference in columns which should be used for lines and histogram plots. When you initialize the plot with
Daru::DataFrameGnuplotRB is building the query for simplest case that is not enough for histogram. However you can control this by hand and in this case use something likerequire 'daru' require 'gnuplotrb' include GnuplotRB days = %w(Monday Tuesday Wednesday Thursday Friday Saturday Sunday) mean = [121.2, 95.6, 91.06, 133.037, 81.88, 82.33, 200.45] std = [206.05, 94.35, 108.15, 208.53, 114.27, 104.77, 320.66] cdata = Daru::DataFrame.new({ mean: mean, sd: std }, name: "test", index: days) datasets = cdata.map { |df| Dataset.new(df, using: '2:xticlabels(1)') } plot = Plot.new(*datasets, style_data: 'histograms', style_fill: 'pattern', title: "Test") plot.to_png 'test.png', size: [800, 420]
Sorry for such a late answer, had problems with github`s 2FA since last summer.
Thanks for the reply! Unfortunately, that visualization doesn't suit my needs. Good workaround, tough.
@dread-uo, here's the error message I got from running your script.
~/.rvm/gems/ruby-2.4.0/gems/gnuplotrb-0.3.4/lib/gnuplotrb/mixins/error_handling.rb:28:in `check_errors': Error in previous command ("line 27: warning: Skipping data file with no valid points"): "gnuplot> plot $DATA1 using 1:2 title "day" , $DATA2 using 1:2 title "mean" , $DATA3 using 1:2 title "sd"; line 27: Too many columns in using specification" (GnuplotRB::GnuplotError) from ~/.rvm/gems/ruby-2.4.0/gems/gnuplotrb-0.3.4/lib/gnuplotrb/staff/terminal.rb:187:in `close' from ~/.rvm/gems/ruby-2.4.0/gems/gnuplotrb-0.3.4/lib/gnuplotrb/plot.rb:87:in `plot' from ~/.rvm/gems/ruby-2.4.0/gems/gnuplotrb-0.3.4/lib/gnuplotrb/mixins/plottable.rb:111:in `to_specific_term' from ~/.rvm/gems/ruby-2.4.0/gems/gnuplotrb-0.3.4/lib/gnuplotrb/mixins/plottable.rb:53:in `method_missing' from test.rb:16:in `<main>'This is what's getting sent to
gnuplot.unset output $DATA1 << EOD 0 Monday 1 Tuesday 2 Wednesday 3 Thursday 4 Friday 5 Saturday 6 Sunday EOD $DATA2 << EOD 0 121.2 1 95.6 2 91.06 3 133.037 4 81.88 5 82.33 6 200.45 EOD $DATA3 << EOD 0 206.05 1 94.35 2 108.15 3 208.53 4 114.27 5 104.77 6 320.66 EOD set style data histograms set style fill pattern set title "Test" set term png set output "test.png" plot $DATA1 using 1:2 title "day" , $DATA2 using 1:2 title "mean" , $DATA3 using 1:2 title "sd" unset style data unset style fill unset title unset term unset outputI'm not sure how to fix it, but it's probably getting unexpected options or the options are in the wrong order.
Hello! Thanks for looking at it again!
Running the test script above doesn't raise errors; it just hangs indefinitely. When I kill the job with ctrl-c, the error I get is
/home/Rei/.rvm/gems/ruby-2.4.1/gems/gnuplotrb-0.3.4/lib/gnuplotrb/plot.rb:87:in `sleep': Interrupt from /home/Rei/.rvm/gems/ruby-2.4.1/gems/gnuplotrb-0.3.4/lib/gnuplotrb/plot.rb:87:in `plot' from /home/Rei/.rvm/gems/ruby-2.4.1/gems/gnuplotrb-0.3.4/lib/gnuplotrb/mixins/plottable.rb:111:in `to_specific_term' from /home/Rei/.rvm/gems/ruby-2.4.1/gems/gnuplotrb-0.3.4/lib/gnuplotrb/mixins/plottable.rb:53:in `method_missing' from script.rb:16:in `<main>'I'm using ruby 2.4.1, gnuplotrb 0.3.4, on Fedora 25.
@dread-uo, I think you misunderstand or I wasn't completely clear.
The hanging you're seeing and the
Interrupterror when you press Ctrl-C is due to a bug (IMO) in GnuplotRB. See the linked issue #14 for more info. By hacking it, I was able to see the true error message of your script, and that's what I showed in my previous comment. Hopefully you can use this real error message to help fix the problem.Another thing that I've found helpful when debugging is to run
gnuplotfrom the command-line. This will bring up a kind of REPL. You can paste in what's getting sent to gnuplot to see error messages more clearly and try to fix your error.

I got some issues when trying to generate a histogram. I had no problems with points and lines, just with histograms. Below is a minimal example that recreates the behavior - at least on my machine.
If I change
style_datatolines, it works as expected.I'm using Ruby 2.3.0, with gnuplotrb 0.3.4 and daru 0.1.4.1. Gnuplot is version 5.0 patchlevel 3.
Thanks for your work with this :)