red-data-tools / unicode_plot.rb

Plot your data by Unicode characters
MIT License
246 stars 12 forks source link

Error when running example #20

Closed schneems closed 4 years ago

schneems commented 4 years ago

Code:

values = [3.101679, 3.113501, 3.123834, 3.125208, 3.129073, 3.140281, 3.142695, 3.144393, 3.144639, 3.145352, 3.146368, 3.149352, 3.150657, 3.15165, 3.158634, 3.15962, 3.162757, 3.163482, 3.169293, 3.178286, 3.18577, 3.194678, 3.19519, 3.201861, 3.204169, 3.208111, 3.20958, 3.219322, 3.220371, 3.225563, 3.228888, 3.233049, 3.244273, 3.247167, 3.24887, 3.253761, 3.296395, 3.336913, 3.354431, 3.358318, 3.37479, 3.375476, 3.415869, 3.420531, 3.492295, 3.500603, 3.618732, 3.639656, 3.663728, 3.686562, 3.689323, 3.704562, 3.712246, 3.715634, 3.765543, 3.776477, 3.78326, 3.784031, 3.798115, 3.812997, 3.82962]

require 'unicode_plot'

plot = UnicodePlot.histogram(values, title: "Histogram")
plot.render($stdout)

IRB:

irb(main):001:0> values = [3.101679, 3.113501, 3.123834, 3.125208, 3.129073, 3.1
40281, 3.142695, 3.144393, 3.144639, 3.145352, 3.146368, 3.149352, 3.150657, 3.1
5165, 3.158634, 3.15962, 3.162757, 3.163482, 3.169293, 3.178286, 3.18577, 3.1946
78, 3.19519, 3.201861, 3.204169, 3.208111, 3.20958, 3.219322, 3.220371, 3.225563
, 3.228888, 3.233049, 3.244273, 3.247167, 3.24887, 3.253761, 3.296395, 3.336913,
 3.354431, 3.358318, 3.37479, 3.375476, 3.415869, 3.420531, 3.492295, 3.500603,
3.618732, 3.639656, 3.663728, 3.686562, 3.689323, 3.704562, 3.712246, 3.715634,
3.765543, 3.776477, 3.78326, 3.784031, 3.798115, 3.812997, 3.82962]
irb(main):002:0>
irb(main):003:0> require 'unicode_plot'
=> true
irb(main):004:0>
irb(main):005:0> plot = UnicodePlot.histogram(values, title: "Histogram")
irb(main):006:0> plot.render($stdout)
Traceback (most recent call last):
       10: from /Users/rschneeman/.rubies/ruby-2.7.0/bin/irb:23:in `<main>'
        9: from /Users/rschneeman/.rubies/ruby-2.7.0/bin/irb:23:in `load'
        8: from /Users/rschneeman/.rubies/ruby-2.7.0/lib/ruby/gems/2.7.0/gems/irb-1.2.1/exe/irb:11:in `<top (required)>'
        7: from (irb):6
        6: from /Users/rschneeman/.gem/ruby/2.7.0/gems/unicode_plot-0.0.3/lib/unicode_plot/plot.rb:106:in `render'
        5: from /Users/rschneeman/.gem/ruby/2.7.0/gems/unicode_plot-0.0.3/lib/unicode_plot/renderer.rb:63:in `render'
        4: from /Users/rschneeman/.gem/ruby/2.7.0/gems/unicode_plot-0.0.3/lib/unicode_plot/renderer.rb:78:in `render'
        3: from /Users/rschneeman/.gem/ruby/2.7.0/gems/unicode_plot-0.0.3/lib/unicode_plot/renderer.rb:87:in `render_top'
        2: from /Users/rschneeman/.gem/ruby/2.7.0/gems/unicode_plot-0.0.3/lib/unicode_plot/renderer.rb:231:in `print_title'
        1: from /Users/rschneeman/.gem/ruby/2.7.0/gems/unicode_plot-0.0.3/lib/unicode_plot/styled_printer.rb:63:in `print_styled'
NameError (uninitialized constant UnicodePlot::StyledPrinter::StringIO)

I'm guessing that StringIO in that context should be ::StringIO

Ruby 2.7.0, latest version of this gem.

schneems commented 4 years ago

Ahh, there needs to be a:

require 'stringio'
schneems commented 4 years ago

First impressions with the library: This is awesome!

                              Histogram
              ┌                                        ┐
   [3.1, 3.2) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 23
   [3.2, 3.3) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 14
   [3.3, 3.4) ┤▇▇▇▇▇▇▇▇ 5
   [3.4, 3.5) ┤▇▇▇▇▇ 3
   [3.5, 3.6) ┤▇▇ 1
   [3.6, 3.7) ┤▇▇▇▇▇▇▇▇ 5
   [3.7, 3.8) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇ 8
   [3.8, 3.9) ┤▇▇▇ 2
              └                                        ┘
                              Frequency=> nil