Allow nil in data passed to graphs
v0dro opened this issue · 5 comments
v0dro commented
Currently when I pass a nil
in an Array for plotting, nyaplot returns an error.
It would be great if it could handle nils properly by not plotting the points where they appear, like GNU plot.
Here's some example code:
require 'nyaplot'
p = Nyaplot::Plot.new
p.add(:scatter, [10,nil,30], [0,1,2])
p.show
#ArgumentError: comparison of NilClass with 10 failed
tansaku commented
I seem to get this error even when I don't have a nil in the data - trying to do a boxplot, with more than one set of data ...
puts dec2014
puts '----'
puts mar2015
plot.add(:box, dec2014.compact, mar2015.compact)
gives
157.0
298
157.0
134.0
298
298
298
298
298
135.0
298
298
206.0
240.0
298
177.0
184.0
151.0
228.0
140.0
298
277.0
140.0
134.0
204.0
162.0
298
----
207.0
123.0
120.0
298
298
298
123.0
149.0
78.0
298
200.0
298
108.0
298
298
298
298
298
123.0
192.0
171.0
298
/Users/tansaku/.rvm/gems/ruby-2.2.3/gems/nyaplot-0.1.6/lib/nyaplot/diagram.rb:285:in `each': comparison of NilClass with 78.0 failed (ArgumentError)
from /Users/tansaku/.rvm/gems/ruby-2.2.3/gems/nyaplot-0.1.6/lib/nyaplot/diagram.rb:285:in `min'
from /Users/tansaku/.rvm/gems/ruby-2.2.3/gems/nyaplot-0.1.6/lib/nyaplot/diagram.rb:285:in `block in process_data'
from /Users/tansaku/.rvm/gems/ruby-2.2.3/gems/nyaplot-0.1.6/lib/nyaplot/diagram.rb:290:in `call'
from /Users/tansaku/.rvm/gems/ruby-2.2.3/gems/nyaplot-0.1.6/lib/nyaplot/diagram.rb:290:in `block in process_data'
from /Users/tansaku/.rvm/gems/ruby-2.2.3/gems/nyaplot-0.1.6/lib/nyaplot/diagram.rb:290:in `each'
from /Users/tansaku/.rvm/gems/ruby-2.2.3/gems/nyaplot-0.1.6/lib/nyaplot/diagram.rb:290:in `process_data'
from /Users/tansaku/.rvm/gems/ruby-2.2.3/gems/nyaplot-0.1.6/lib/nyaplot/diagram.rb:16:in `initialize'
from /Users/tansaku/.rvm/gems/ruby-2.2.3/gems/nyaplot-0.1.6/lib/nyaplot/plot.rb:75:in `new'
from /Users/tansaku/.rvm/gems/ruby-2.2.3/gems/nyaplot-0.1.6/lib/nyaplot/plot.rb:75:in `add_with_df'
from /Users/tansaku/.rvm/gems/ruby-2.2.3/gems/nyaplot-0.1.6/lib/nyaplot/plot.rb:64:in `add'
from lib/correlation.rb:127:in `block in <main>'
from /Users/tansaku/.rvm/gems/ruby-2.2.3/gems/statsample-2.0.1/lib/statsample/analysis/suite.rb:20:in `instance_eval'
from /Users/tansaku/.rvm/gems/ruby-2.2.3/gems/statsample-2.0.1/lib/statsample/analysis/suite.rb:20:in `run'
from /Users/tansaku/.rvm/gems/ruby-2.2.3/gems/statsample-2.0.1/lib/statsample/analysis.rb:73:in `block in add_to_reportbuilder'
from /Users/tansaku/.rvm/gems/ruby-2.2.3/gems/statsample-2.0.1/lib/statsample/analysis.rb:69:in `each'
from /Users/tansaku/.rvm/gems/ruby-2.2.3/gems/statsample-2.0.1/lib/statsample/analysis.rb:69:in `add_to_reportbuilder'
from /Users/tansaku/.rvm/gems/ruby-2.2.3/gems/statsample-2.0.1/lib/statsample/analysis.rb:91:in `to_text'
from /Users/tansaku/.rvm/gems/ruby-2.2.3/gems/statsample-2.0.1/lib/statsample/analysis.rb:97:in `run_batch'
from lib/correlation.rb:163:in `<main>'
tansaku commented
ah, because I have arrays of different lengths?
domitry commented
Oops that's true.. but it's bug.