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 +4 -4
- data/README.md +24 -0
- data/lib/gr/plot/histogram.rb +34 -0
- data/lib/gr/plot/version.rb +1 -1
- data/lib/gr/plot.rb +619 -280
- metadata +5 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 03bfb61ea67da3615f7084fc079c8f61e260e84349d657969b9abf1703ff5c74
|
|
4
|
+
data.tar.gz: d92fb9571dffce0dfa1ba3091413845bd750cd17327e10dc2f3dd4a56b7661d2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b2a14854e39d7c4071b9a26f1bb5066b69a84ec48b2fe8c040e9cd65b038c88af27ce687bcf5fd98b6ebddf2c25aed637ddaacf3d64411defe61fdae1879cace
|
|
7
|
+
data.tar.gz: 56be1f06410b14413129cb4eacd4dd9ee0db1ce403a845324ef63c22c17193c1b4020fa870996f95af9aeb9fd61b4c02d1bc8ac4c048c450a8634484fd9c2e7a
|
data/README.md
CHANGED
|
@@ -1,2 +1,26 @@
|
|
|
1
1
|
# GR::Plot
|
|
2
2
|
|
|
3
|
+
[](https://badge.fury.io/rb/gr-plot)
|
|
4
|
+
[](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
|