如何计算或设置gnuplot边距+标签+图例的大小

时间:2014-06-13 16:00:54

标签: gnuplot

我们有一个需要像素完美的大谱图(1行= 100ms数据,1列= 1 fft的1个频率仓)。我使用下面的代码来计算图的大小:

  set terminal unknown
  sedcmd="<(sed -n '1p;" .rowstart. "," .rowend. "p' " .filename. ".csv)"
  plot sedcmd nonuniform matrix using 2:1:3 notitle with image
  xspan = GPVAL_DATA_X_MAX - GPVAL_DATA_X_MIN
  yspan = GPVAL_DATA_Y_MAX - GPVAL_DATA_Y_MIN
  set terminal png size (rowend-rowstart),yspan
  sedcmd="<(sed -n '1p;" .rowstart. "," .rowend. "p' " .filename. ".csv)"
  plot sedcmd nonuniform matrix using 2:1:3 notitle with image

rowstart和rowend是传递给gnuplot的变量,表示频率区间。这样可以正常工作,只有一个例外,它没有考虑图例和标签所需的空间。如何计算或设置像素以便:

[ylabels][                     PLOT             ][LEGEND]
[                      xlabels                          ]

PLOT将是我指定的确切大小(即:1000x1000)

编辑:图表大小和边距的最终计算代码:

# margins and plotsize
rowstart = 2457     # rowstart/end represent the fft bins
rowend = 5734       # plot is actually rotated 90deg (rows are cols)
cols = 6970     # number of ms in plot (plotted rows)
plotwidth = (rowend - rowstart) +1
plotheight = cols
lm = 1200.00
rm = 600
tbmargin = 200.00
width = plotwidth + (lm + rm)
height = plotheight + (tbmargin * 2)
set lmargin at screen lm / width
set rmargin at screen 1 - (rm / width)
set tmargin at screen tbmargin / height
set bmargin at screen 1 - (tbmargin / height)
show margin

1 个答案:

答案 0 :(得分:1)

如果你知道你想要的图的确切大小,它会有很大的帮助。如果你想要1000x1000的情节,你可以从:

开始
s = 1250 # size of plot
set terminal pngcairo size 1250,1250
set output 'spectrogram.png'

# difference between l/r and t/b margins = (0.9-0.1)*1250 = 1000 px
set lmargin at screen 0.1
set rmargin at screen 0.9
set bmargin at screen 0.1
set tmargin at screen 0.9

plot ...

我发现做一些基本的代数并使用*margin命令在摆弄像素完美的绘图形状时非常有用(示例herehere)。

可能有1 px差异左右 - 我不确定轴是否从0到1 px或-1到0绘制,只要涉及绘图边缘。