Vertically stacked multiplot in gnuplot

好久不见. 提交于 2020-01-26 04:34:25

问题


I am trying to plot 5 graph in vertically stacked pattern in gnuplot. There are many horizontally (x axis shared) graphs. I tried to adapt their solution. But somehow not works. Here is code.

set key bottom center
 NX=5; NY=1
 DX=0.01; DY=0.01; SX=0.25; SY=0.85
 set bmargin DX; set tmargin DX; set lmargin DY; set rmargin DY
 set size SX*NX+DX*4,SY*NY+DY*4
 set multiplot layout 1,5 #title 'Distance from inlet boundary' font #'areal,18' 

 #1set title 'sa4(210)'
 set size SX,SY
 set label 1 '50m' at 1.5, 1.5 #font 'areal,15'
 set x2tics (0, 0.01, 0.02)
 set xtics (0, 2, 4)
 set ytics (-15, -10, -5, 0)
 set x2range [-0.001:0.02]
 set xrange [0:4]
 set yrange [-15:0]
 set ylabel 'metre(s) below sea level'
 set key bottom
 set xtics nomirror #smooth bezier w p csplines
 set origin DX,DY;
 plot 'so10.dat' u 2:1 w p pt 7 lc rgb 'red' title 'Salinity' axes x2y1,\
      'so10.dat' u 3:1 w p pt 8 lc rgb 'blue' title 'Sediment' axes x1y1

 #2set title 'sa4(210)'
 set size SX,SY
 set label 1 '250m' at 1.5, 1.5 #font 'areal,15'
 set x2tics (0, 0.01, 0.02)
 set xtics (0, 2, 4)
 set x2tics
 set x2range [-0.001:0.02]
 set xrange [0:4]
 unset ylabel
 unset ytics
 set key bottom
 set xtics nomirror #smooth bezier w p csplines
 set origin DX+SX,DY;
 plot 'so50.dat' u 2:1 w p pt 7 lc rgb 'red' title 'Salinity' axes x2y1,\
      'so50.dat' u 3:1 w p pt 8 lc rgb 'blue' title 'Sediment' axes x1y1

 #3set title 'sa4(210)'
 set size SX,SY
 set label 1 '750m' at 4.0, 1.5 #font ',15'
 set x2tics (0, 0.01, 0.02)
 set xtics (0, 5, 10)
 set x2tics
 set x2range [-0.001:0.02]
 set xrange [0:10]
 unset ylabel
 set key bottom
 set xtics nomirror #smooth bezier w p csplines
 set origin DX+SX*2,DY;
 plot 'so150.dat' u 2:1 w p pt 7 lc rgb 'red' title 'Salinity' axes x2y1,\
      'so150.dat' u 3:1 w p pt 8 lc rgb 'blue' title 'Sediment' axes x1y1

 #4set title 'sa4(210)'
 set size SX,SY
 set label 1 '850m' at 4.0, 1.5 #font ',15'
 set x2tics (0, 0.01, 0.02)
 set xtics (0, 6, 12)
 set x2tics
 set x2range [-0.001:0.02]
 set xrange [0:12]
 unset ylabel
 set key bottom
 set xtics nomirror #smooth bezier w p csplines
 set origin DX+SX*3,DY;
 plot 'so170.dat' u 2:1 w p pt 7 lc rgb 'red' title 'Salinity' axes x2y1,\
      'so170.dat' u 3:1 w p pt 8 lc rgb 'blue' title 'Sediment' axes x1y1

 #5set title 'sa4(210)'
 set size SX,SY
 set label 1 '950m' at 4.0, 1.5 #font ',15'
 set x2tics (0, 0.01, 0.02)
 set xtics (0, 5, 10)
 set x2tics
 set x2range [-0.001:0.02]
 set xrange [0:10]
 unset ylabel
 set key bottom
 set xtics nomirror #smooth bezier w p csplines
 set origin DX+SX*4,DY;
 plot 'so190.dat' u 2:1 w p pt 7 lc rgb 'red' title 'Salinity' axes x2y1,\
      'so190.dat' u 3:1 w p pt 8 lc rgb 'blue' title 'Sediment' axes x1y1

 unset multiplot

Which gives below 4 graph in one. Code must generate 5 graph. Generated image

Original image is below. I want to remove blank space between graphs. Original image


回答1:


Gnuplot is running out of space. You need to fix your set size and set origin commands so that you don't plot outside of the plotting area. Right now, your SX=0.25 means that the horizontal dimension of each subplot takes 25% of the available space, thus only 4 subplots can fit with this setting. The fifth subplot is then required to be placed beyond the plotting area.

Note also that by setting the origin and the size you're overriding your defined multiplot layout.

Usually, when doing this kind of plotting style, it might be a better idea to define the margins rather than the size and origin.



来源:https://stackoverflow.com/questions/35863194/vertically-stacked-multiplot-in-gnuplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!