Plot data and its distribution in one figure with GNUPLOT

data_and_distribution

The above figure is what I want. Left figure gives the data (X versus Y). The right figure demonstrates the distribution of data. I have seen this in one paper of Dr. Akio Kitao (Tokyo University). I think it’s pretty good to gave two different information.

In GNUPLOT, you need “multiplot” and “at screen” command to finish this. It’s easy to understand the code below.

reset
set terminal pngcairo
set output "data_and_distribution.png"
set multiplot layout 1,2 title "Data and distribution"
set tmargin 1
set grid
set xrange [0:110]
set yr [0:50]
set xlabel "X"
set ylabel "Y"
set ytics
set ytics nomirror
set ytics 10
set rmargin at screen 0.7

p '1.dat' w l noti,'' w p noti


set grid
set xr [0:*]
set yrange [0:50]
unset yl
set xlabel "%"
set xtics 5
set format y ""
set lmargin at screen 0.7
set rmargin at screen 0.95

p '2.dat' u 2:1 w l noti, '' u 2:1 w p noti

unset multiplot

set output

1.dat contains data of left figure. 2.dat contains information for right figure. Parts of files are shown as examples.

1.dat
31.30103
33.81782
35.53126
39.5113
39.19146
44.18469
41.01741
47.12503
...

2.dat
0       2
20      1
22      1
23      1
24      1
26      1
29      1
30      3
...

Got help from http://www.gnuplotting.org/multiplot-placing-graphs-next-to-each-other/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s