visualisation-utils 0.4 → 0.5
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.
- data/README.md +35 -10
- data/bin/heat-map +125 -0
- data/doc/heat-map.png +0 -0
- data/visualisation-utils.gemspec +1 -1
- data/world.dat +1320 -0
- metadata +6 -2
data/README.md
CHANGED
@@ -14,7 +14,7 @@ scatter-plot
|
|
14
14
|
============
|
15
15
|
|
16
16
|
Prints scatter plots of one or more columns of whitespace separated data using
|
17
|
-
gnuplot as a backend
|
17
|
+
gnuplot as a backend.
|
18
18
|
|
19
19
|
|
20
20
|
~~~ .bash
|
@@ -31,16 +31,41 @@ This incantation will bring up the gnuplot gui with the following graph:
|
|
31
31
|
|
32
32
|

|
33
33
|
|
34
|
+
heat-map
|
35
|
+
=====-==
|
36
|
+
|
37
|
+
Prints a heat map visualising the distribution of
|
38
|
+
geo coordinate samples.
|
39
|
+
|
40
|
+
~~~ .bash
|
41
|
+
cat | < | heat-map <<'END'
|
42
|
+
38.6,-90.5
|
43
|
+
38.6,-90.5
|
44
|
+
40.5,-74.3
|
45
|
+
34.4,-92.2
|
46
|
+
42.5,-83.0
|
47
|
+
34.1,-92.0
|
48
|
+
33.3,-111.9
|
49
|
+
34.1,-91.8
|
50
|
+
34.2,-86.8
|
51
|
+
END
|
52
|
+
~~~
|
53
|
+
|
54
|
+
This will render to the following visualisation:
|
55
|
+
|
56
|
+

|
57
|
+
|
58
|
+
|
34
59
|
TODO
|
35
60
|
====
|
36
61
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
62
|
+
[X] Overriding of autoscale
|
63
|
+
[X] Create nice PNGs
|
64
|
+
[X] Line plots
|
65
|
+
[ ] Changing changing the size of the dots
|
66
|
+
[X] Secondary y-axis
|
67
|
+
[ ] Bar chart single series
|
68
|
+
[ ] Bar chart multiple series
|
69
|
+
[ ] Discrete y-values, e.g. to visualise events over time
|
70
|
+
[ ] Histogram plotting
|
46
71
|
|
data/bin/heat-map
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'trollop'
|
3
|
+
|
4
|
+
DATA_FILE_NAME="/tmp/plot-"+`date "+%s"`.strip+".dat"
|
5
|
+
PLOT_FILE_NAME="/tmp/plot-"+`date "+%s"`.strip+".plt"
|
6
|
+
|
7
|
+
|
8
|
+
@opts = Trollop::options do
|
9
|
+
banner "heat-map takes comma and newline separated table of coordinate from stdin and renders them using gnuplot"
|
10
|
+
opt :outfile, "Output file name", :type => String, :short => 'o'
|
11
|
+
opt :debug, "debug"
|
12
|
+
opt :title, "Title", :type=> String, :short => 't'
|
13
|
+
opt :font, "Font", :type => String, :short => 'f'
|
14
|
+
opt :extra_header, "Extra commands to be put in the header of the gnuplot file", :type => String
|
15
|
+
end
|
16
|
+
|
17
|
+
title = @opts[:title] || ""
|
18
|
+
|
19
|
+
# TODO I do want to be streamed!
|
20
|
+
input = `cat`
|
21
|
+
|
22
|
+
freqs = input.split("\n").map{|line|
|
23
|
+
line.split(",").map{|number | number.to_f.round(0)}.join(",")
|
24
|
+
}
|
25
|
+
.group_by{|coords| coords}
|
26
|
+
.map{|pair| [pair[0], pair[1].length]}
|
27
|
+
.inject({}) { |memo, obj|
|
28
|
+
memo[obj.first] = obj.last
|
29
|
+
memo
|
30
|
+
}
|
31
|
+
|
32
|
+
freq_values = freqs.values
|
33
|
+
max_val = freq_values.max
|
34
|
+
min_val = freq_values.min
|
35
|
+
mid_val = (min_val + (max_val - min_val)/2).round(1)
|
36
|
+
|
37
|
+
puts "Min. value: #{min_val}, max value: #{max_val}"
|
38
|
+
|
39
|
+
full_map = (-179..179).map{|lon|
|
40
|
+
(-89..89).map{|lat|
|
41
|
+
key = "#{lat},#{lon}"
|
42
|
+
"#{lat} #{lon} #{freqs[key]||0}"
|
43
|
+
}
|
44
|
+
}.join("\n")
|
45
|
+
|
46
|
+
|
47
|
+
File.open(DATA_FILE_NAME, "w"){|f| f.write(full_map)}
|
48
|
+
|
49
|
+
font = @opts[:font] || "Futura"
|
50
|
+
font_size = "12"
|
51
|
+
|
52
|
+
extra_header = @opts[:extra_header] || ""
|
53
|
+
|
54
|
+
if (@opts[:outfile])
|
55
|
+
filename = @opts[:outfile]
|
56
|
+
extension = filename.gsub(/[^.]*\./,"")
|
57
|
+
if (extension == "png")
|
58
|
+
terminal=<<EOF
|
59
|
+
set term pngcairo font '#{font},#{font_size}' transparent size 1200,800
|
60
|
+
set output '#{filename}'
|
61
|
+
|
62
|
+
EOF
|
63
|
+
elsif (extension == "eps")
|
64
|
+
terminal=<<EOF
|
65
|
+
set term epscairo size 1200,800 font '#{font},#{font_size}'
|
66
|
+
set output '#{filename}'
|
67
|
+
EOF
|
68
|
+
elsif (extension == "pdf")
|
69
|
+
terminal=<<EOF
|
70
|
+
set term pdfcairo size 22cm,14cm font '#{font},#{font_size}'
|
71
|
+
set output '#{filename}'
|
72
|
+
EOF
|
73
|
+
elsif (extension == "svg")
|
74
|
+
terminal=<<EOF
|
75
|
+
set term svg size 1200,800 font '#{font},#{font_size}'
|
76
|
+
set output '#{filename}'
|
77
|
+
EOF
|
78
|
+
else
|
79
|
+
throw "Unknown output format '.#{extension}'."
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
world_dat=File.join(File.dirname(File.expand_path(__FILE__)), '/../world.dat')
|
87
|
+
|
88
|
+
|
89
|
+
script = <<EOF
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
#{terminal}
|
94
|
+
|
95
|
+
|
96
|
+
set title "#{title}"
|
97
|
+
|
98
|
+
# color definitions
|
99
|
+
set border lw 1.5
|
100
|
+
set style line 1 lc rgb 'black' lt 1 lw 2
|
101
|
+
|
102
|
+
set rmargin screen 0.85
|
103
|
+
|
104
|
+
unset key
|
105
|
+
set tics scale 0.5
|
106
|
+
unset xtics
|
107
|
+
unset ytics
|
108
|
+
set xrange[-179:179]
|
109
|
+
set yrange[-89:89]
|
110
|
+
#set format '%g'
|
111
|
+
set palette defined (0 "white",#{min_val} "#00ffff",#{mid_val} "yellow",#{max_val} "red")
|
112
|
+
plot '#{DATA_FILE_NAME}' u 2:1:3 w image, \
|
113
|
+
'#{world_dat}' with lines linestyle 1
|
114
|
+
EOF
|
115
|
+
|
116
|
+
|
117
|
+
puts "data file " + DATA_FILE_NAME
|
118
|
+
puts "plot file " + PLOT_FILE_NAME
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
File.open(PLOT_FILE_NAME, "w"){|f| f.write(script)}
|
123
|
+
|
124
|
+
`gnuplot #{PLOT_FILE_NAME}`
|
125
|
+
|
data/doc/heat-map.png
ADDED
Binary file
|
data/visualisation-utils.gemspec
CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.summary = 'utilities for quick visualisation'
|
4
4
|
s.description = 'visualisation-utils provides a number of utilities
|
5
5
|
for visualising data from the command line.'
|
6
|
-
s.version = '0.
|
6
|
+
s.version = '0.5'
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
8
|
|
9
9
|
s.files = ['bin/scatter-plot']
|