gnutemplate 0.1.8.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gnutemplate/version.rb +1 -1
- data/lib/gnutemplate.rb +223 -104
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5faac0acbe5d64d0e9cf6aec58ffed06004f62e0c372ef4a551881de916e2c64
|
4
|
+
data.tar.gz: b2676c4052f26536e59c5e34379e67fb7f7013f3ca40479088342aa0ae71e7c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28dd05eeaa1cda84b9fcca9d0eb537af4e884e103e7b2b9e80314350dbe32c97a0504902af8d9e4f3f1555579afee54947bf404955d05b62fa82b47717591bcb
|
7
|
+
data.tar.gz: a7413b695ff3273cd126c1beb0b477b4f81e53a0ad573b89008566401e2408f161bd3f62151cc8ec1037efd798ae074865e52a3e90f9958bf058472480b51114
|
data/lib/gnutemplate/version.rb
CHANGED
data/lib/gnutemplate.rb
CHANGED
@@ -4,9 +4,32 @@ require_relative "gnutemplate/version"
|
|
4
4
|
require "numo/gnuplot"
|
5
5
|
require "histogram/array"
|
6
6
|
|
7
|
+
module ExtendNP
|
8
|
+
def new_to_iruby
|
9
|
+
require 'tempfile'
|
10
|
+
tempfile_svg = Tempfile.open(['plot','.svg'])
|
11
|
+
# output SVG to tmpfile
|
12
|
+
gp = Numo::Gnuplot.default
|
13
|
+
gp.reset
|
14
|
+
gp.unset :multiplot # added
|
15
|
+
gp.set terminal:'svg'
|
16
|
+
gp.set output:tempfile_svg.path
|
17
|
+
gp.instance_eval(&@block)
|
18
|
+
### gp.unset 'output' # commented out
|
19
|
+
svg = File.read(tempfile_svg.path)
|
20
|
+
tempfile_svg.close
|
21
|
+
["image/svg+xml",svg]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Numo::Gnuplot::NotePlot
|
26
|
+
include ExtendNP
|
27
|
+
alias_method :old_to_iruby, :to_iruby
|
28
|
+
alias_method :to_iruby, :new_to_iruby
|
29
|
+
end
|
30
|
+
|
7
31
|
module Gnutemplate
|
8
32
|
class Error < StandardError; end
|
9
|
-
|
10
33
|
|
11
34
|
def note_line(data)
|
12
35
|
Numo.noteplot do
|
@@ -112,11 +135,13 @@ module Gnutemplate
|
|
112
135
|
end
|
113
136
|
end
|
114
137
|
|
115
|
-
|
138
|
+
# いずれかはここからargsを返せるようにする
|
139
|
+
# set terminal部の扱いは考えなければならない(多分、_drow, _noteにif...set...end だけ残せばいい)
|
140
|
+
def histogram(data, labels: nil, pileup: true,
|
116
141
|
xmin: nil, xmax: nil, ymin: 0, ymax: nil, bins: 10,
|
117
142
|
figsize: 1.0, rotate_xtics: 45,
|
118
143
|
fill: true, alpha: 33, background: nil,
|
119
|
-
file: nil
|
144
|
+
file: nil)
|
120
145
|
|
121
146
|
data = [data] if data[0].kind_of?(Numeric) || data[0].nil?
|
122
147
|
|
@@ -128,73 +153,160 @@ module Gnutemplate
|
|
128
153
|
freqs = data.map {|d| d.to_a.compact.histogram(bins, min: xmin, max: xmax) }
|
129
154
|
ymax ||= freqs.map{ _1[1] }.flatten.max * 1.1
|
130
155
|
|
156
|
+
if pileup
|
157
|
+
###########
|
158
|
+
###
|
159
|
+
###########
|
160
|
+
|
161
|
+
set size: "#{figsize},#{figsize}"
|
162
|
+
set style: "fill solid" if fill
|
163
|
+
|
164
|
+
xticinterval = (xmax-xmin).to_f / bins
|
165
|
+
set xtics: "#{xmin-xticinterval}, #{xticinterval}, #{xmax+xticinterval}"
|
166
|
+
set(:xtics, "rotate by #{rotate_xtics}") if rotate_xtics
|
167
|
+
|
168
|
+
set xrange: (xmin-xticinterval)..(xmax+xticinterval)
|
169
|
+
set yrange: ymin..ymax
|
170
|
+
|
171
|
+
args = background ? ["[#{xmin}:#{xmax}] #{ymax} with filledc above y=#{ymin} fc \"##{background}\" notitle", {}] : []
|
172
|
+
|
173
|
+
freqs.each_with_index do |f, i|
|
174
|
+
args.push f[0], f[1]
|
175
|
+
|
176
|
+
if labels
|
177
|
+
args.push({:with => :boxes, :title => labels[i], :fillcolor => "rgb \"#{colors[i % 4]}\""})
|
178
|
+
else
|
179
|
+
args.push({:with => :boxes, :fillcolor => "rgb \"#{colors[i % 4]}\""})
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
return args
|
184
|
+
|
185
|
+
else
|
186
|
+
|
187
|
+
###########
|
188
|
+
###
|
189
|
+
###########
|
190
|
+
# set title:"Temperature"
|
191
|
+
set auto:"x"
|
192
|
+
set :style, :data, :histogram
|
193
|
+
set :style, :histogram, :cluster, gap:1
|
194
|
+
set :style, :fill, solid: 1.0 - (alpha/100.0), border:-1
|
195
|
+
set boxwidth:0.9
|
196
|
+
set :xtic, :rotate, by: rotate_xtics, scale: 0
|
197
|
+
|
198
|
+
xticinterval = (xmax-xmin).to_f / bins
|
199
|
+
set xrange: 0..((xmax-xmin) / xticinterval).to_i
|
200
|
+
|
201
|
+
xtics = freqs[0][0]
|
202
|
+
.each.with_index
|
203
|
+
.inject("(") { |result, (x, i)| result += "'#{x-xticinterval/2}-#{x+xticinterval/2}' #{i}," }
|
204
|
+
.gsub(/,$/, ")")
|
205
|
+
set xtics: xtics
|
206
|
+
|
207
|
+
labels ||= (0...(freqs.length)).map(&:to_s)
|
208
|
+
|
209
|
+
args = freqs.zip(labels).each_with_index.map do |(f, l), i|
|
210
|
+
[*f, using: 2, w: :histogram, t: labels[i], fillcolor: "rgb \"#{colors[i % 4]}\""]
|
211
|
+
end
|
212
|
+
|
213
|
+
return args
|
214
|
+
|
215
|
+
end # Of if pileup..else
|
216
|
+
end
|
217
|
+
|
218
|
+
def note_histogram(data, labels: nil, pileup: true,
|
219
|
+
xmin: nil, xmax: nil, ymin: 0, ymax: nil, bins: 10,
|
220
|
+
figsize: 1.0, rotate_xtics: 45,
|
221
|
+
fill: true, alpha: 33, background: nil,
|
222
|
+
file: nil)
|
223
|
+
|
131
224
|
Numo.noteplot do
|
132
225
|
|
133
226
|
if !file.nil?
|
134
227
|
set terminal: "gif"
|
135
228
|
set output: file
|
136
229
|
end
|
230
|
+
|
231
|
+
args = histogram(data, labels: labels, pileup: pileup,
|
232
|
+
xmin: xmin, xmax: xmax, ymin: ymin, ymax: ymax, bins: bins,
|
233
|
+
figsize: figsize, rotate_xtics: rotate_xtics,
|
234
|
+
fill: fill, alpha: alpha, background: background)
|
235
|
+
|
236
|
+
plot *args
|
137
237
|
|
138
|
-
if
|
139
|
-
###########
|
140
|
-
###
|
141
|
-
###########
|
238
|
+
# data = [data] if data[0].kind_of?(Numeric) || data[0].nil?
|
142
239
|
|
143
|
-
|
144
|
-
|
240
|
+
# alpha_hex = (alpha * 256 / 100).to_s(16).upcase
|
241
|
+
# colors = ["##{alpha_hex}CC0000", "##{alpha_hex}00CC00", "##{alpha_hex}0000CC", "##{alpha_hex}888800"]
|
242
|
+
|
243
|
+
# xmax ||= data.map(&:to_a).flatten.compact.max
|
244
|
+
# xmin ||= data.map(&:to_a).flatten.compact.min
|
245
|
+
# freqs = data.map {|d| d.to_a.compact.histogram(bins, min: xmin, max: xmax) }
|
246
|
+
# ymax ||= freqs.map{ _1[1] }.flatten.max * 1.1
|
145
247
|
|
146
|
-
xticinterval = (xmax-xmin).to_f / bins
|
147
|
-
set xtics: "#{xmin-xticinterval}, #{xticinterval}, #{xmax+xticinterval}"
|
148
|
-
set(:xtics, "rotate by #{rotate_xtics}") if rotate_xtics
|
149
248
|
|
150
|
-
|
151
|
-
|
249
|
+
# if pileup
|
250
|
+
# ###########
|
251
|
+
# ###
|
252
|
+
# ###########
|
152
253
|
|
153
|
-
|
254
|
+
# set size: "#{figsize},#{figsize}"
|
255
|
+
# set style: "fill solid" if fill
|
154
256
|
|
155
|
-
|
156
|
-
|
257
|
+
# xticinterval = (xmax-xmin).to_f / bins
|
258
|
+
# set xtics: "#{xmin-xticinterval}, #{xticinterval}, #{xmax+xticinterval}"
|
259
|
+
# set(:xtics, "rotate by #{rotate_xtics}") if rotate_xtics
|
157
260
|
|
158
|
-
|
159
|
-
|
160
|
-
else
|
161
|
-
args.push({:with => :boxes, :fillcolor => "rgb \"#{colors[i % 4]}\""})
|
162
|
-
end
|
163
|
-
end
|
261
|
+
# set xrange: (xmin-xticinterval)..(xmax+xticinterval)
|
262
|
+
# set yrange: ymin..ymax
|
164
263
|
|
165
|
-
|
264
|
+
# args = background ? ["[#{xmin}:#{xmax}] #{ymax} with filledc above y=#{ymin} fc \"##{background}\" notitle", {}] : []
|
166
265
|
|
167
|
-
|
266
|
+
# freqs.each_with_index do |f, i|
|
267
|
+
# args.push f[0], f[1]
|
168
268
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
set :style, :histogram, :cluster, gap:1
|
176
|
-
set :style, :fill, solid: 1.0 - (alpha/100.0), border:-1
|
177
|
-
set boxwidth:0.9
|
178
|
-
set :xtic, :rotate, by: rotate_xtics, scale: 0
|
269
|
+
# if labels
|
270
|
+
# args.push({:with => :boxes, :title => labels[i], :fillcolor => "rgb \"#{colors[i % 4]}\""})
|
271
|
+
# else
|
272
|
+
# args.push({:with => :boxes, :fillcolor => "rgb \"#{colors[i % 4]}\""})
|
273
|
+
# end
|
274
|
+
# end
|
179
275
|
|
180
|
-
|
181
|
-
set xrange: 0..((xmax-xmin) / xticinterval).to_i
|
276
|
+
# plot *args
|
182
277
|
|
183
|
-
|
184
|
-
.each.with_index
|
185
|
-
.inject("(") { |result, (x, i)| result += "'#{x-xticinterval/2}-#{x+xticinterval/2}' #{i}," }
|
186
|
-
.gsub(/,$/, ")")
|
187
|
-
set xtics: xtics
|
278
|
+
# else
|
188
279
|
|
189
|
-
|
280
|
+
# ###########
|
281
|
+
# ###
|
282
|
+
# ###########
|
283
|
+
# # set title:"Temperature"
|
284
|
+
# set auto:"x"
|
285
|
+
# set :style, :data, :histogram
|
286
|
+
# set :style, :histogram, :cluster, gap:1
|
287
|
+
# set :style, :fill, solid: 1.0 - (alpha/100.0), border:-1
|
288
|
+
# set boxwidth:0.9
|
289
|
+
# set :xtic, :rotate, by: rotate_xtics, scale: 0
|
190
290
|
|
191
|
-
|
192
|
-
|
193
|
-
|
291
|
+
# xticinterval = (xmax-xmin).to_f / bins
|
292
|
+
# set xrange: 0..((xmax-xmin) / xticinterval).to_i
|
293
|
+
|
294
|
+
# xtics = freqs[0][0]
|
295
|
+
# .each.with_index
|
296
|
+
# .inject("(") { |result, (x, i)| result += "'#{x-xticinterval/2}-#{x+xticinterval/2}' #{i}," }
|
297
|
+
# .gsub(/,$/, ")")
|
298
|
+
# set xtics: xtics
|
194
299
|
|
195
|
-
|
300
|
+
# labels ||= (0...(freqs.length)).map(&:to_s)
|
301
|
+
|
302
|
+
# args = freqs.zip(labels).each_with_index.map do |(f, l), i|
|
303
|
+
# [*f, using: 2, w: :histogram, t: labels[i], fillcolor: "rgb \"#{colors[i % 4]}\""]
|
304
|
+
# end
|
305
|
+
|
306
|
+
# plot *args
|
307
|
+
|
308
|
+
# end # Of if pileup..else
|
196
309
|
|
197
|
-
end # Of if pileup..else
|
198
310
|
end # Of Numo.noteplot do
|
199
311
|
|
200
312
|
end # Of def function
|
@@ -203,17 +315,7 @@ module Gnutemplate
|
|
203
315
|
xmin: nil, xmax: nil, ymin: 0, ymax: nil, bins: 10,
|
204
316
|
figsize: 1.0, rotate_xtics: 45,
|
205
317
|
fill: true, alpha: 33, background: nil,
|
206
|
-
file: nil
|
207
|
-
|
208
|
-
data = [data] if data[0].kind_of?(Numeric) || data[0].nil?
|
209
|
-
|
210
|
-
alpha_hex = (alpha * 256 / 100).to_s(16).upcase
|
211
|
-
colors = ["##{alpha_hex}CC0000", "##{alpha_hex}00CC00", "##{alpha_hex}0000CC", "##{alpha_hex}888800"]
|
212
|
-
|
213
|
-
xmax ||= data.map(&:to_a).flatten.compact.max
|
214
|
-
xmin ||= data.map(&:to_a).flatten.compact.min
|
215
|
-
freqs = data.map {|d| d.to_a.compact.histogram(bins, min: xmin, max: xmax) }
|
216
|
-
ymax ||= freqs.map{ _1[1] }.flatten.max * 1.1
|
318
|
+
file: nil)
|
217
319
|
|
218
320
|
Numo.gnuplot do
|
219
321
|
|
@@ -221,67 +323,84 @@ module Gnutemplate
|
|
221
323
|
set terminal: "gif"
|
222
324
|
set output: file
|
223
325
|
end
|
326
|
+
|
327
|
+
args = histogram(data, labels: labels, pileup: pileup,
|
328
|
+
xmin: xmin, xmax: xmax, ymin: ymin, ymax: ymax, bins: bins,
|
329
|
+
figsize: figsize, rotate_xtics: rotate_xtics,
|
330
|
+
fill: fill, alpha: alpha, background: background)
|
224
331
|
|
225
|
-
|
226
|
-
###########
|
227
|
-
###
|
228
|
-
###########
|
332
|
+
plot *args
|
229
333
|
|
230
|
-
|
231
|
-
set style: "fill solid" if fill
|
334
|
+
# data = [data] if data[0].kind_of?(Numeric) || data[0].nil?
|
232
335
|
|
233
|
-
|
234
|
-
|
235
|
-
|
336
|
+
# alpha_hex = (alpha * 256 / 100).to_s(16).upcase
|
337
|
+
# colors = ["##{alpha_hex}CC0000", "##{alpha_hex}00CC00", "##{alpha_hex}0000CC", "##{alpha_hex}888800"]
|
338
|
+
|
339
|
+
# xmax ||= data.map(&:to_a).flatten.compact.max
|
340
|
+
# xmin ||= data.map(&:to_a).flatten.compact.min
|
341
|
+
# freqs = data.map {|d| d.to_a.compact.histogram(bins, min: xmin, max: xmax) }
|
342
|
+
# ymax ||= freqs.map{ _1[1] }.flatten.max * 1.1
|
236
343
|
|
237
|
-
|
238
|
-
|
344
|
+
# if pileup
|
345
|
+
# ###########
|
346
|
+
# ###
|
347
|
+
# ###########
|
239
348
|
|
240
|
-
|
349
|
+
# set size: "#{figsize},#{figsize}"
|
350
|
+
# set style: "fill solid" if fill
|
241
351
|
|
242
|
-
|
243
|
-
|
352
|
+
# xticinterval = (xmax-xmin).to_f / bins
|
353
|
+
# set xtics: "#{xmin-xticinterval}, #{xticinterval}, #{xmax+xticinterval}"
|
354
|
+
# set(:xtics, "rotate by #{rotate_xtics}") if rotate_xtics
|
244
355
|
|
245
|
-
|
246
|
-
|
247
|
-
else
|
248
|
-
args.push({:with => :boxes, :fillcolor => "rgb \"#{colors[i % 4]}\""})
|
249
|
-
end
|
250
|
-
end
|
356
|
+
# set xrange: (xmin-xticinterval)..(xmax+xticinterval)
|
357
|
+
# set yrange: ymin..ymax
|
251
358
|
|
252
|
-
|
359
|
+
# args = background ? ["[#{xmin}:#{xmax}] #{ymax} with filledc above y=#{ymin} fc \"##{background}\" notitle", {}] : []
|
253
360
|
|
254
|
-
|
361
|
+
# freqs.each_with_index do |f, i|
|
362
|
+
# args.push f[0], f[1]
|
255
363
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
set :style, :fill, solid: 1.0 - (alpha/100.0), border:-1
|
263
|
-
set boxwidth:0.9
|
264
|
-
set :xtic, :rotate, by: rotate_xtics, scale: 0
|
364
|
+
# if labels
|
365
|
+
# args.push({:with => :boxes, :title => labels[i], :fillcolor => "rgb \"#{colors[i % 4]}\""})
|
366
|
+
# else
|
367
|
+
# args.push({:with => :boxes, :fillcolor => "rgb \"#{colors[i % 4]}\""})
|
368
|
+
# end
|
369
|
+
# end
|
265
370
|
|
266
|
-
|
267
|
-
set xrange: 0..((xmax-xmin) / xticinterval).to_i
|
371
|
+
# plot *args # ,xs, ys, { with: :lines , title: "STD"}
|
268
372
|
|
269
|
-
|
270
|
-
.each.with_index
|
271
|
-
.inject("(") { |result, (x, i)| result += "'#{x-xticinterval/2}-#{x+xticinterval/2}' #{i}," }
|
272
|
-
.gsub(/,$/, ")")
|
273
|
-
set xtics: xtics
|
373
|
+
# else
|
274
374
|
|
275
|
-
|
375
|
+
# ###########
|
376
|
+
# ###
|
377
|
+
# ###########
|
378
|
+
# set auto:"x"
|
379
|
+
# set :style, :data, :histogram
|
380
|
+
# set :style, :histogram, :cluster, gap:1
|
381
|
+
# set :style, :fill, solid: 1.0 - (alpha/100.0), border:-1
|
382
|
+
# set boxwidth:0.9
|
383
|
+
# set :xtic, :rotate, by: rotate_xtics, scale: 0
|
276
384
|
|
277
|
-
|
278
|
-
|
279
|
-
|
385
|
+
# xticinterval = (xmax-xmin).to_f / bins
|
386
|
+
# set xrange: 0..((xmax-xmin) / xticinterval).to_i
|
387
|
+
|
388
|
+
# xtics = freqs[0][0]
|
389
|
+
# .each.with_index
|
390
|
+
# .inject("(") { |result, (x, i)| result += "'#{x-xticinterval/2}-#{x+xticinterval/2}' #{i}," }
|
391
|
+
# .gsub(/,$/, ")")
|
392
|
+
# set xtics: xtics
|
280
393
|
|
281
|
-
|
394
|
+
# labels ||= (0...(freqs.length)).map(&:to_s)
|
395
|
+
|
396
|
+
# args = freqs.zip(labels).each_with_index.map do |(f, l), i|
|
397
|
+
# [*f, using: 2, w: :histogram, t: labels[i], fillcolor: "rgb \"#{colors[i % 4]}\""]
|
398
|
+
# end
|
399
|
+
|
400
|
+
# plot *args
|
282
401
|
|
283
|
-
end # Of if pileup..else
|
284
|
-
end # Of Numo.
|
402
|
+
# end # Of if pileup..else
|
403
|
+
end # Of Numo.gnuplot do
|
285
404
|
|
286
405
|
end # Of def function
|
287
406
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gnutemplate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- showata
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-10-
|
11
|
+
date: 2023-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-gnuplot
|