Initial release of Maemo 5 port of gnuplot
[gnuplot] / demo / histograms.dem
1 #
2 # Example of using histogram modes
3 #
4 reset
5 set title "US immigration from Europe by decade"
6 set datafile missing "-"
7 set xtics nomirror rotate by -45
8 #
9 # First plot using linespoints
10 set style data linespoints
11 set key autotitle columnhead
12 plot 'immigration.dat' using 2:xtic(1), \
13 '' u 3, '' u 4, '' u 5, '' u 6, \
14 '' u 7, '' u 8, '' u 9, '' u 10, \
15 '' u 11, '' u 12, '' u 13, '' u 14, \
16 '' u 15, '' u 16, '' u 17, '' u 18, \
17 '' u 19, '' u 20, '' u 21, '' u 22
18 #
19 pause -1 "<cr> to plot the same data as a histogram"
20 #
21 set title "US immigration from Northern Europe\nPlot selected data columns as histogram of clustered boxes"
22 set auto x
23 set yrange [0:300000]
24 set style data histogram
25 set style histogram cluster gap 1
26 set style fill solid border -1
27 set boxwidth 0.9
28 set xtic rotate by -45
29 #set bmargin 10 
30 plot 'immigration.dat' using 6:xtic(1) ti col, '' u 12 ti col, '' u 13 ti col, '' u 14 ti col
31 #
32 pause -1 "<cr> to change the gap between clusters"
33 #
34 set title "US immigration from Northern Europe\n(same plot with larger gap between clusters)"
35 set style histogram gap 5
36 replot
37 #
38 pause -1 "<cr> to plot the same dataset as stacked histogram"
39 #
40 #
41 # Stacked histograms
42 #
43 set title "US immigration from Europe by decade\nPlot as stacked histogram"
44 set key invert reverse Left outside
45 set key autotitle columnheader
46 set yrange [0:7e6]
47 set auto x
48 unset xtics
49 set xtics nomirror rotate by -45
50 set style data histogram
51 set style histogram rowstacked
52 set style fill solid border -1
53 set boxwidth 0.75
54 #
55 plot 'immigration.dat' using 2:xtic(1), \
56 '' using 3, \
57 '' using 4, \
58 '' using 5, \
59 '' using 6, \
60 '' using 7, \
61 '' using 8, \
62 '' using 9, \
63 '' using 10, \
64 '' using 11, \
65 '' using 12, \
66 '' using 13, \
67 '' using 14, \
68 '' using 15, \
69 '' using 16, \
70 '' using 17, \
71 '' using 18, \
72 '' using 19, \
73 '' using 20, \
74 '' using 21, \
75 '' using 22
76 #
77 pause -1 "<cr> to rescale each stack to % of total"
78 #
79 # Stacked histograms by percent
80 #
81 set title "US immigration from Europe by decade\nFraction of total plotted as stacked histogram"
82 set key invert reverse Left outside
83 set yrange [0:100]
84 set ylabel "% of total"
85 unset ytics
86 set grid y
87 set border 3
88 set style data histograms
89 set style histogram rowstacked
90 set style fill solid border -1
91 set boxwidth 0.75
92 #
93 plot 'immigration.dat' using (100.*$2/$24):xtic(1) title column(2), \
94 '' using (100.*$3/$24) title column(3), \
95 '' using (100.*$4/$24) title column(4), \
96 '' using (100.*$5/$24) title column(5), \
97 '' using (100.*$6/$24) title column(6), \
98 '' using (100.*$7/$24) title column(7), \
99 '' using (100.*$8/$24) title column(8), \
100 '' using (100.*$9/$24) title column(9), \
101 '' using (100.*$10/$24) title column(10), \
102 '' using (100.*$11/$24) title column(11), \
103 '' using (100.*$12/$24) title column(12), \
104 '' using (100.*$13/$24) title column(13), \
105 '' using (100.*$14/$24) title column(14), \
106 '' using (100.*$15/$24) title column(15), \
107 '' using (100.*$16/$24) title column(16), \
108 '' using (100.*$17/$24) title column(17), \
109 '' using (100.*$18/$24) title column(18), \
110 '' using (100.*$19/$24) title column(19), \
111 '' using (100.*$20/$24) title column(20), \
112 '' using (100.*$21/$24) title column(21), \
113 '' using (100.*$22/$24) title column(22), \
114 '' using (100.*$23/$24) title column(23)
115 #
116 pause -1 "Now try histograms stacked by columns"
117 #
118 # Columnstacks
119 #       xtic labels should be picked up from column heads ('title column')
120 #       key titles should be picked up from row heads ('key(1)')
121 #
122 set title "Immigration from Northern Europe\n(columstacked histogram)"
123 set style histogram columnstacked
124 set key noinvert box
125 set yrange [0:*]
126 set ylabel "Immigration by decade"
127 set xlabel "Country of Origin"
128 set tics scale 0.0
129 set ytics
130 unset xtics
131 set xtics norotate nomirror
132 plot 'immigration.dat' using 6 ti col, '' using 12 ti col, \
133      '' using 13 ti col, '' using 14:key(1) ti col
134 #
135 pause -1 "Next we do several sets of parallel histograms"
136 #
137 # 'newhistogram' keyword to plot
138 #
139 set title "Immigration from different regions\n(give each histogram a separate title)"
140 set key under nobox
141 set key autotitle columnhead
142 set style histogram clustered gap 1 title offset 2,0.25
143 set style fill solid noborder
144 set boxwidth 0.95
145 unset xtics
146 set xtics nomirror rotate by -45
147 set xlabel "(note: histogram titles have specified offset relative to X-axis label)" offset 0,-2
148 set ytics
149 set grid y
150 set auto y
151 plot \
152 newhistogram "Northern Europe", \
153 'immigration.dat' using 6:xtic(1), '' u 13, '' u 14, \
154 newhistogram "Southern Europe", \
155 '' u 9:xtic(1), '' u 17, '' u 22, \
156 newhistogram "British Isles", \
157 '' u 10:xtic(1), '' u 21
158 #
159 pause -1 "Same plot using rowstacked histogram"
160 #
161 set style histogram rows
162 set boxwidth 0.8
163 set yrange [0:900000]
164 set xlabel "(Same plot using rowstacked rather than clustered histogram)"
165 replot
166 #
167 pause -1
168