gr-plot 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4985f7320e33de0ca629e0499528e34867cbd0f28356d65ed086306a436f2bbd
4
- data.tar.gz: bf708f02d24453cf8243918bcb6d2481f78ca6f65017ccd0afad5bc762e0bb6d
3
+ metadata.gz: 03bfb61ea67da3615f7084fc079c8f61e260e84349d657969b9abf1703ff5c74
4
+ data.tar.gz: d92fb9571dffce0dfa1ba3091413845bd750cd17327e10dc2f3dd4a56b7661d2
5
5
  SHA512:
6
- metadata.gz: 1e147a5477db68f7037c76028c8b1bf05d2e421ac886056731053e3657ff03fd9d81330f157e4cab7ed8c378a16a6c7d1a878fe3bb0a03f5045ec30aa548eee0
7
- data.tar.gz: 57a0e0757aeabadeca8ca42da72035682710013627a28c89878e6ec17c00a1aa0f00167a3e54166b3f786d238ef4b55a6beae8df7467fc016700e49fd792b321
6
+ metadata.gz: b2a14854e39d7c4071b9a26f1bb5066b69a84ec48b2fe8c040e9cd65b038c88af27ce687bcf5fd98b6ebddf2c25aed637ddaacf3d64411defe61fdae1879cace
7
+ data.tar.gz: 56be1f06410b14413129cb4eacd4dd9ee0db1ce403a845324ef63c22c17193c1b4020fa870996f95af9aeb9fd61b4c02d1bc8ac4c048c450a8634484fd9c2e7a
data/README.md CHANGED
@@ -1,2 +1,26 @@
1
1
  # GR::Plot
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/gr-plot.svg)](https://badge.fury.io/rb/gr-plot)
4
+ [![Lines of Code](https://img.shields.io/endpoint?url=https%3A%2F%2Ftokei.kojix2.net%2Fbadge%2Fgithub%2Fred-data-tools%2Fgr-plot%2Flines)](https://tokei.kojix2.net/github/red-data-tools/gr-plot)
5
+
6
+ A simple, matlab-style API for [GR.rb](https://github.com/red-data-tools/GR.rb)
7
+
8
+ * GR::Plot is intended to be an equivalent implementation to [jlgr.jl](https://github.com/jheinen/GR.jl/blob/master/src/jlgr.jl).
9
+ * This module was originally part of GR.rb. GR::Plot has been separated from GR.rb to make GR.rb easier to maintain.
10
+
11
+ ## Installation
12
+
13
+ ```
14
+ gem install gr-plot
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ * [wiki](https://github.com/red-data-tools/GR.rb/wiki/Plotting-functions)
20
+ * [doc](https://red-data-tools.github.io/gr-plot/)
21
+
22
+
23
+ ## Contributing
24
+
25
+ * Pull requests are welcome.
26
+ * Please post [issues to GR.rb](https://github.com/red-data-tools/GR.rb/issues).
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GR
4
+ class Plot
5
+ module Histogram
6
+ module_function
7
+
8
+ def hist(data, nbins = 0)
9
+ x = data.to_a.map(&:to_f)
10
+ raise ArgumentError, 'histogram data must not be empty' if x.empty?
11
+
12
+ nbins = (3.3 * Math.log10(x.length)).round + 1 if nbins <= 1
13
+
14
+ xmin, xmax = x.minmax
15
+ if xmin == xmax
16
+ half_width = xmin.zero? ? 0.5 : xmin.abs * 0.5
17
+ xmin -= half_width
18
+ xmax += half_width
19
+ end
20
+
21
+ edges = (0..nbins).map { |i| xmin + i.to_f * (xmax - xmin) / nbins }
22
+ counts = Array.new(nbins, 0)
23
+ width = (xmax - xmin).to_f / nbins
24
+ x.each do |value|
25
+ bucket = ((value - xmin) / width).ceil - 1
26
+ bucket = 0 if bucket < 0
27
+ bucket = nbins - 1 if bucket >= nbins
28
+ counts[bucket] += 1
29
+ end
30
+ [edges, counts]
31
+ end
32
+ end
33
+ end
34
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GR
4
4
  class Plot
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.2'
6
6
  end
7
7
  end