0% found this document useful (0 votes)
229 views5 pages

Gnuplot Histograms for Immigration Data

The document contains gnuplot script code for creating various histograms and plots from immigration data. It includes scripts for line plots, clustered and stacked histograms, and using the "newhistogram" keyword to give each histogram a separate title. The plots visualize US immigration from Europe by decade using different styles to illustrate different aspects of the data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
229 views5 pages

Gnuplot Histograms for Immigration Data

The document contains gnuplot script code for creating various histograms and plots from immigration data. It includes scripts for line plots, clustered and stacked histograms, and using the "newhistogram" keyword to give each histogram a separate title. The plots visualize US immigration from Europe by decade using different styles to illustrate different aspects of the data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

gnuplot demo script

# # Example of using histogram modes # set title "US immigration from Europe by decade" set datafile missing "-" set xtics nomirror rotate by -45 set key noenhanced # # First plot using linespoints set style data linespoints plot '[Link]' using 2:xtic(1) title columnheader(2), \ for [i=3:22] '' using i title columnheader(i) # Click here for minimal script to generate this plot

# set terminal png transparent nocrop enhanced font arial 8 size 420,320 # set output '[Link]' set datafile missing '-' set style data linespoints set xtics border in scale 1,0.5 nomirror rotate by -45 offset character 0, 0, 0 set xtics ("1891-1900" 0.00000, "1901-1910" 1.00000, "1911-1920" 2.00000, "1921-1930" 3.00000, "1931-1940" 4.00000, "1941-1950" 5.00000, "1951-1960" 6.00000, "1961-1970" 7.00000) set title "US immigration from Europe by decade" plot '[Link]' using 2:xtic(1) t 2, '' u 3 t 3, '' u 4 t 4, '' u 5 t 5, '' u 6 t 6, '' u 7 t 7, '' u 8 t 8, '' u 9 t 9, '' u 10 t 10, '' u 11 t 11, '' u 12 t 12, '' u 13 t 13, '' u 14 t 14, '' u 15 t 15, '' u 16 t 16, '' u 17 t 17, '' u 18 t 18, '' u 19 t 19, '' u 20 t 20, '' u 21 t 21, '' u 22 t 22

# set title "US immigration from Northern Europe\nPlot selected data columns as histogram of clustered boxes" set auto x set yrange [0:300000] set style data histogram set style histogram cluster gap 1 set style fill solid border -1 set boxwidth 0.9 set xtic rotate by -45 scale 0 #set bmargin 10 plot '[Link]' using 6:xtic(1) ti col, '' u 12 ti col, '' u 13 ti col, '' u 14 ti col # Click here for minimal script to generate this plot

# set terminal png transparent nocrop enhanced font arial 8 size 420,320 # set output '[Link]' set boxwidth 0.9 absolute set style fill solid 1.00 border -1 set style histogram clustered gap 1 title offset character 0, 0, 0 set datafile missing '-' set style data histograms set xtics border in scale 1,0.5 nomirror rotate by -45 offset character 0, 0, 0 set xtics ("1891-1900" 0.00000, "1901-1910" 1.00000, "1911-1920" 2.00000, "1921-1930" 3.00000, "1931-1940" 4.00000, "1941-1950" 5.00000, "1951-1960" 6.00000, "1961-1970" 7.00000) set title "US immigration from Northern Europe\nPlot selected data columns as histogram of clustered boxes" set yrange [ 0.00000 : 300000. ] noreverse nowriteback plot '[Link]' using 6:xtic(1) ti col, '' u 12 ti col, '' u 13 ti col, '' u 14 ti col

# set title "US immigration from Northern Europe\n(same plot with larger gap between clusters)" set style histogram gap 5 replot # Click here for minimal script to generate this plot

# set terminal png transparent nocrop enhanced font arial 8 size 420,320 # set output '[Link]' set boxwidth 0.9 absolute set style fill solid 1.00 border -1 set style histogram clustered gap 5 title offset character 0, 0, 0 set datafile missing '-' set style data histograms set xtics border in scale 1,0.5 nomirror rotate by -45 offset character 0, 0, 0 set xtics ("1891-1900" 0.00000, "1901-1910" 1.00000, "1911-1920" 2.00000, "1921-1930" 3.00000, "1931-1940" 4.00000, "1941-1950" 5.00000, "1951-1960" 6.00000, "1961-1970" 7.00000) set title "US immigration from Northern Europe\n(same plot with larger gap between clusters)" set yrange [ 0.00000 : 300000. ] noreverse nowriteback plot '[Link]' using 6:xtic(1) ti col, '' u 12 ti col, '' u 13 ti col, '' u 14 ti col

# # # Stacked histograms # set title "US immigration from Europe by decade\nPlot as stacked histogram" set key invert reverse Left outside set key autotitle columnheader set yrange [0:7e6] set auto x unset xtics set xtics nomirror rotate by -45 scale 0 set style data histogram set style histogram rowstacked set style fill solid border -1 set boxwidth 0.75 # plot '[Link]' using 2:xtic(1), for [i=3:22] '' using i # Click here for minimal script to generate this plot

# set terminal png transparent nocrop enhanced font arial 8 size 420,320 # set output '[Link]' set boxwidth 0.75 absolute set style fill solid 1.00 border -1 set key outside right top vertical Left reverse enhanced autotitles columnhead nobox set key invert samplen 4 spacing 1 width 0 height 0 set style histogram rowstacked title offset character 0, 0, 0 set datafile missing '-' set style data histograms set xtics border in scale 1,0.5 nomirror rotate by -45 offset character 0, 0, 0 set xtics ("1891-1900" 0.00000, "1901-1910" 1.00000, "1911-1920" 2.00000, "1921-1930" 3.00000, "1931-1940" 4.00000, "1941-1950" 5.00000, "1951-1960" 6.00000, "1961-1970" 7.00000) set title "US immigration from Europe by decade\nPlot as stacked histogram" set yrange [ 0.00000 : 7.00000e+06 ] noreverse nowriteback i = 23 plot '[Link]' using 2:xtic(1), for [i=3:22] '' using i

# # Stacked histograms by percent # set title "US immigration from Europe by decade\nFraction of total plotted as stacked histogram" set key invert reverse Left outside set yrange [0:100] set ylabel "% of total" unset ytics set grid y set border 3 set style data histograms set style histogram rowstacked set style fill solid border -1 set boxwidth 0.75 # plot '[Link]' using (100.*$2/$24):xtic(1) t column(2), \ for [i=3:23] '' using (100.*column(i)/column(24)) title column(i) # Click here for minimal script to generate this plot

# set terminal png transparent nocrop enhanced font arial 8 size 420,320 # set output '[Link]' set border 3 front linetype -1 linewidth 1.000 set boxwidth 0.75 absolute set style fill solid 1.00 border -1 set grid nopolar set grid noxtics nomxtics ytics nomytics noztics nomztics \ nox2tics nomx2tics noy2tics nomy2tics nocbtics nomcbtics set grid layerdefault linetype 0 linewidth 1.000, linetype 0 linewidth 1.000 set key outside right top vertical Left reverse enhanced autotitles columnhead nobox set key invert samplen 4 spacing 1 width 0 height 0 set style histogram rowstacked title offset character 0, 0, 0 set datafile missing '-' set style data histograms set xtics border in scale 1,0.5 nomirror rotate by -45 offset character 0, 0, 0 set xtics ("1891-1900" 0.00000, "1901-1910" 1.00000, "1911-1920" 2.00000, "1921-1930" 3.00000, "1931-1940" 4.00000, "1941-1950" 5.00000, "1951-1960" 6.00000, "1961-1970" 7.00000) set noytics set title "US immigration from Europe by decade\nFraction of total plotted as stacked histogram" set ylabel "% of total" set yrange [ 0.00000 : 100.000 ] noreverse nowriteback i = 24 plot '[Link]' using (100.*$2/$24):xtic(1) t 2, for [i=3:23] '' using (100.*column(i)/column(24)) title column(i)

# # Columnstacks # xtic labels should be picked up from column heads ('title column') # key titles should be picked up from row heads ('key(1)') # set title "Immigration from Northern Europe\n(columstacked histogram)" set style histogram columnstacked set key noinvert box set yrange [0:*] set ylabel "Immigration by decade" set xlabel "Country of Origin" set tics scale 0.0 set ytics unset xtics set xtics norotate nomirror plot '[Link]' using 6 ti col, '' using 12 ti col, \ '' using 13 ti col, '' using 14:key(1) ti col # Click here for minimal script to generate this plot

# set terminal png transparent nocrop enhanced font arial 8 size 420,320 # set output '[Link]' set border 3 front linetype -1 linewidth 1.000 set boxwidth 0.75 absolute set style fill solid 1.00 border -1 set grid nopolar set grid noxtics nomxtics ytics nomytics noztics nomztics \ nox2tics nomx2tics noy2tics nomy2tics nocbtics nomcbtics set grid layerdefault linetype 0 linewidth 1.000, linetype 0 linewidth 1.000 set key outside right top vertical Left reverse enhanced autotitles columnhead box linetype -1 linewidth 1.000 set style histogram columnstacked title offset character 0, 0, 0 set datafile missing '-' set style data histograms set xtics border in scale 1,0.5 nomirror norotate offset character 0, 0, 0 set xtics ("Denmark" 0.500000, "Netherlands" 1.50000, "Norway" 2.50000, "Sweden" 3.50000) set ytics border in scale 0,0 mirror norotate offset character 0, 0, 0 autofreq set ztics border in scale 0,0 nomirror norotate offset character 0, 0, 0 autofreq set cbtics border in scale 0,0 mirror norotate offset character 0, 0, 0 autofreq set title "Immigration from Northern Europe\n(columstacked histogram)" set xlabel "Country of Origin" set ylabel "Immigration by decade" set yrange [ 0.00000 : * ] noreverse nowriteback # (currently [:100.000] ) i = 24 plot '[Link]' using 6 ti col, '' using 12 ti col, '' using 13 ti col, '' using 14:key(1) ti col

# # 'newhistogram' keyword to plot # set title "Immigration from different regions\n(give each histogram a separate title)" set key under nobox set style histogram clustered gap 1 title offset 2,0.25 set style fill solid noborder set boxwidth 0.95 unset xtics set xtics nomirror rotate by -45 scale 0 set xlabel "(note: histogram titles have specified offset relative to X-axis label)" offset 0,-2 set ytics set grid y set auto y plot \ newhistogram "Northern Europe", \ '[Link]' using 6:xtic(1) t col, '' u 13 t col, '' u 14 t col, \ newhistogram "Southern Europe", \ '' u 9:xtic(1) t col, '' u 17 t col, '' u 22 t col, \ newhistogram "British Isles", \ '' u 10:xtic(1) t col, '' u 21 t col # Click here for minimal script to generate this plot

# set terminal png transparent nocrop enhanced font arial 8 size 420,320 # set output '[Link]' set border 3 front linetype -1 linewidth 1.000 set boxwidth 0.95 absolute set style fill solid 1.00 noborder set grid nopolar set grid noxtics nomxtics ytics nomytics noztics nomztics \ nox2tics nomx2tics noy2tics nomy2tics nocbtics nomcbtics set grid layerdefault linetype 0 linewidth 1.000, linetype 0 linewidth 1.000 set key bmargin center horizontal Left reverse enhanced autotitles columnhead nobox set style histogram clustered gap 1 title offset character 2, 0.25, 0 set datafile missing '-' set style data histograms set xtics border in scale 1,0.5 nomirror rotate by -45 offset character 0, 0, 0 set xtics ("1891-1900" 0.00000, "1901-1910" 1.00000, "1911-1920" 2.00000, "1921-1930" 3.00000, "1931-1940" 4.00000, "1941-1950" 5.00000, "1951-1960" 6.00000, "1961-1970" 7.00000, "1891-1900" 9.00000, "1901-1910" 10.0000, "1911-1920" 11.0000, "1921-1930" 12.0000, "1931-1940" 13.0000, "1941-1950" 14.0000, "1951-1960" 15.0000, "1961-1970" 16.0000, "1891-1900" 18.0000, "1901-1910" 19.0000, "1911-1920" 20.0000, "1921-1930" 21.0000, "1931-1940" 22.0000, "1941-1950" 23.0000, "1951-1960" 24.0000, "1961-1970" 25.0000) set ytics border in scale 0,0 mirror norotate offset character 0, 0, 0 autofreq set ztics border in scale 0,0 nomirror norotate offset character 0, 0, 0 autofreq set cbtics border in scale 0,0 mirror norotate offset character 0, 0, 0 autofreq set title "Immigration from different regions\n(give each histogram a separate title)" set xlabel "(note: histogram titles have specified offset relative to X-axis label)" set xlabel offset character 0, -2, 0 font "" textcolor lt -1 norotate set ylabel "Immigration by decade" set yrange [ * : * ] noreverse nowriteback # (currently [0.00000:100.000] ) i = 24

plot newhistogram "Northern Europe", '[Link]' using 6:xtic(1) t 6, '' u 13 t 13, '' u 14 t 14, newhistogram "Southern Europe", '' u 9:xtic(1) t 9, '' u 17 t 17, '' u 22 t 22, newhistogram "British Isles", '' u 10:xtic(1) t 10, '' u 21 t 21

# set style histogram rows set boxwidth 0.8 set yrange [0:900000] set xlabel "(Same plot using rowstacked rather than clustered histogram)" replot # Click here for minimal script to generate this plot

# set terminal png transparent nocrop enhanced font arial 8 size 420,320 # set output '[Link]' set border 3 front linetype -1 linewidth 1.000 set boxwidth 0.8 absolute set style fill solid 1.00 noborder set grid nopolar set grid noxtics nomxtics ytics nomytics noztics nomztics \ nox2tics nomx2tics noy2tics nomy2tics nocbtics nomcbtics set grid layerdefault linetype 0 linewidth 1.000, linetype 0 linewidth 1.000 set key bmargin center horizontal Left reverse enhanced autotitles columnhead nobox set style histogram rowstacked title offset character 2, 0.25, 0 set datafile missing '-' set style data histograms set xtics border in scale 1,0.5 nomirror rotate by -45 offset character 0, 0, 0 set xtics ("1891-1900" 0.00000, "1901-1910" 1.00000, "1911-1920" 2.00000, "1921-1930" 3.00000, "1931-1940" 4.00000, "1941-1950" 5.00000, "1951-1960" 6.00000, "1961-1970" 7.00000, "1891-1900" 9.00000, "1901-1910" 10.0000, "1911-1920" 11.0000, "1921-1930" 12.0000, "1931-1940" 13.0000, "1941-1950" 14.0000, "1951-1960" 15.0000, "1961-1970" 16.0000, "1891-1900" 18.0000, "1901-1910" 19.0000, "1911-1920" 20.0000, "1921-1930" 21.0000, "1931-1940" 22.0000, "1941-1950" 23.0000, "1951-1960" 24.0000, "1961-1970" 25.0000) set ytics border in scale 0,0 mirror norotate offset character 0, 0, 0 autofreq set ztics border in scale 0,0 nomirror norotate offset character 0, 0, 0 autofreq set cbtics border in scale 0,0 mirror norotate offset character 0, 0, 0 autofreq set title "Immigration from different regions\n(give each histogram a separate title)" set xlabel "(Same plot using rowstacked rather than clustered histogram)" set xlabel offset character 0, -2, 0 font "" textcolor lt -1 norotate set ylabel "Immigration by decade" set yrange [ 0.00000 : 900000. ] noreverse nowriteback i = 24 plot newhistogram "Northern Europe", '[Link]' using 6:xtic(1) t 6, '' u 13 t 13, '' u 14 t 14, newhistogram "Southern Europe", '' u 9:xtic(1) t 9, '' u 17 t 17, '' u 22 t 22, newhistogram "British Isles", '' u 10:xtic(1) t 10, '' u 21 t 21

You might also like