Gnuplot Examples (1): Plotting With Double-yaxis

Gnuplot is one of the most useful tool for plotting all kinds of figures in Linux system. Here, we give an simple example to plot distribution function with gnuplot. We will plot the function of two kind of molecules A and B in a liquid, along the normal direction (z-axis),ie., as a function of z coordinate. The distribution file are dist_A.dat and dist_B.dat. The value is too different to each other, we plot them with different scale. The details can be found in the script scr_doubleaxis.gnuplot.

To plot, just run
$gnuplot scr_doubleaxis.gnuplot

The script is as follows.


#========================
# scr_doubleaxis.gnuplot
#========================
# Set terminal type, here is "postscript eps"
set terminal postscript eps color solid linewidth 2 "Sans" 30 enhanced
# Other fonts can be Times-Roman, Helvetica, Arial, etc
# The "enhanced" parameter make superscript and subsrcipt available
#------------------
# Set the output
set output "prob_double_axis.eps"
# Encoding method for some characters
set encoding iso_8859_1
#--------------
# Set line type
set style line 1 lt 1 lw 2 lc rgb '#000000' # Black solid
set style line 2 lt 0 lw 2 lc rgb '#000000' # Black dotted
set style line 3 lt 1 lw 2 lc rgb '#ff0000' # Red solid
set style line 4 lt 0 lw 2 lc rgb '#ff0000' # Red dotted
set style line 5 lt 1 lw 3 lc rgb '#008000' # Green
set style line 6 lt 0 lw 4 lc rgb '#008000' # Green
set style line 7 lt 1 lw 3 lc rgb '#0000ff' # Blue
set style line 8 lt 0 lw 4 lc rgb '#0000ff' # Blue
set style line 9 lt 1 lw 3 lc rgb '#FFA500' # Orange - #FFA500
set style line 10 lt 0 lw 4 lc rgb '#FFA500' # Orange - #FFA500
set style line 11 lt 1 lw 3 lc rgb '#40E0D0' # Turquoise - #40E0D0
set style line 12 lt 0 lw 4 lc rgb '#40E0D0' # Turquoise - #40E0D0
set style line 13 lt 1 lw 3 lc rgb '#EE82EE' # Violet - #EE82EE
set style line 14 lt 0 lw 4 lc rgb '#EE82EE' # Violet - #EE82EE
set style line 15 lt 1 lw 3 lc rgb '#800000' # Maroon - #800000
set style line 16 lt 0 lw 4 lc rgb '#800000' # Maroon - #800000
set style line 17 lt 1 lw 2 lc rgb '#00aaff' # Cyan solid
set style line 18 lt 0 lw 2 lc rgb '#00aaff' # Cyan dotted
#====
#plot
#====
#set the size of the figure
set size square 1.2, 1.5
# Control the x and y range
set xrange [0 : 40]
set yrange [0.: 0.16]
set y2range [0.: 0.008]
# Control the x and y labels
set xlabel "z (\305)"
set ylabel "P_{A}(z)" textcolor ls 7
set y2label "P_{B}(z) (10^3)"
#-------------------
# Control the tics
set xtics 10
set mxtics 2
set ytics 0.04 nomirror # The first ytics setting
set y2tics 0.002 # The second ytics setting
set ytics textcolor ls 7 # set ytics textcolor to blue
#----------------------------------------------
# Control the ytics labels (Can skip this step)
set ytics ("0.00" 0, "0.04" 0.04, "0.08" 0.08, "0.12" 0.12, "0.16" 0.16)
set y2tics ("0.0" 0, "2.0" 0.002, "4.0" 0.004, "6.0" 0.006, "8.0" 0.008)
#-------------------------------------------------------------
# plot with data, one can choose any line style (ls) they like
plot "dist_A.dat" u 1:2 axes x1y1 w l ls 1 title "A",\
"dist_B.dat" u 1:2 axes x1y1 w l ls 7 title "B",
#====
# End
#====
set terminal wxt

The result is in Figure 1.
prob_double_aixs
Figure 1. prob_double_axis

Attachments:
1) dist_A.dat

1.58317 0
3.18637 0
4.78958 1.62784e-05
6.39279 8.03836e-05
7.99599 0.000860041
9.5992 0.00118625
11.2024 0.00428501
12.8056 0.00305274
14.4088 0.00449976
16.012 0.00389357
17.6152 0.00261631
19.2184 0.00337749
20.8216 0.00461041
22.4248 0.00292054
24.0281 0.00317337
25.6313 0.00320737
27.2345 0.00358452
28.8377 0.00426682
30.4409 0.00301801
32.0441 0.00155134
33.6473 0.00068888
35.2505 9.01727e-05
36.8537 0
38.4569 0

2) dist_B.dat

1.58317 0
3.18637 0
4.78958 0
6.39279 0
7.99599 0
9.5992 0
11.2024 0
12.8056 0
14.4088 0
16.012 0
17.6152 0
19.2184 0
20.8216 0
22.4248 0
24.0281 0
25.6313 0
27.2345 0
28.8377 0.00564425
30.4409 0.035557
32.0441 0.00121325
33.6473 0
35.2505 0
36.8537 0
38.4569 0

打赏作者
喜欢这篇文章,打赏犒劳下作者,以此激励作者创作更多!

您的支持将鼓励我们继续创作!

[微信] 扫描二维码打赏

[支付宝] 扫描二维码打赏

发表评论

电子邮件地址不会被公开。