Gnuplot粗曲线超过绘图边界

时间:2013-09-07 14:17:51

标签: gnuplot

我在Gnuplot中绘制了以下内容。我的问题是曲线超出了边界(所以我们可以看到紫色和蓝色曲线超出了y轴)。有什么方法可以解决这个问题?我希望有一些东西可以限制绘图范围内的绘图。当然,我可以只绘制较少的曲线,但那看起来很奇怪。理想情况下,我希望Gnuplot绕过曲线的框架并移除那里的任何曲线。

为了说明这个问题,我让紫色曲线异常变胖了。问题也在于蓝色曲线。

Graph

产生上述情节的代码是:

#!/usr/bin/env gnuplot

### n: change this parameter to equal the number of data sets to be plotted
n = 2
# t: top margin in pixels
t = 25.0
# b: key height in pixels (bottom margin)
b = 25.0
# h: height of output in pixels
h = 150.0*n + t + b

### define functions to help set top/bottom margins
top(i,n,h,t,b) = 1.0 - (t+(h-t-b)*(i-1)/n)/h
bot(i,n,h,t,b) = 1.0 - (t+(h-t-b)*i/n)/h

### first set up some basic plot parameters
#set term cairolatex size 15cm,15cm
#set output 'DifferentialAmplifierPlot.tex'

set term pdfcairo size 15cm,15cm
set output 'DifferentialAmplifierPlot.pdf'

set border lw 4

set grid mxtics mytics xtics ytics ls '-1' ls '-1' lc rgb 'gray70', lc rgb 'gray90'

set mxtics
set mytics

# Make yrange > ytics > function to get padding.
set yrange [-1.5:1.5]
set ytics ("" -1.5, -1.25 1, -1.0, -0.75 1, -0.5, -0.25 1, 0.0, 0.25 1, 0.5, 0.75 1, 1.0, 1.25 1, "" -1.5)

set xtics 0,1,5
set xrange [0:5]

set xtics
set mxtics
set mytics

set format x ""
set grid xtics ytics mxtics mytics ls -1 ls -1 lc rgb 'gray60', lc rgb '#C0E5E5E5''

set multiplot layout (n+1),1 #font ",14" title 'Input And Output Voltages Of Differential Amplifier'

### First plot
# change only plot command here
currentplot = 1
set tmargin at screen top(currentplot,n,h,t,b)
set bmargin at screen bot(currentplot,n,h,t,b)
unset key
unset xlabel
set title 'Input (Bottom) And Output (Top) Voltages Of The Differential Amplifier'
set ylabel 'Voltage [V]'
plot 'DifferentialAmplfier.dat' using (1000*$1):2 with lines lw 20 lc rgb 'dark-magenta'

### Last plot
# change only plot command here
currentplot = currentplot + 1
set tmargin at screen top(currentplot,n,h,t,b)
set bmargin at screen bot(currentplot,n,h,t,b)
set format x
unset title
set xlabel 'Time [ms]'
set ylabel 'Voltage [mV]'
plot 'DifferentialAmplfier.dat' using (1000*$1):(1000*$3) with lines lw 10 lc rgb 'navy'

unset multiplot

set term x11

可疑/狡猾的修复......

GraphDodgyFix

1 个答案:

答案 0 :(得分:2)

有一种方法可以做到这一点,但它很麻烦。您将使用多重绘图,绘制数据,然后通过明智地使用graphscreen坐标系绘制绘图周围的白色矩形,然后重新绘制空图以重绘边框(因为矩形将覆盖了你的标签和边框线厚度的一半)。这是一个MWE:

#!/usr/bin/gnuplot -persist

reset
f(x) = sin(x)

xl=0; xh=20; yl=-1; yh=1;
set xrange [xl:xh]
set yrange [yl:yh]

set multiplot

plot f(x) not w l lt 3 lw 12

## overdraw borders on left, right, top, bottom
set object 1 rectangle from screen 0, screen 0 to graph 0, screen 1 behind \
  fillstyle solid noborder
set object 2 rectangle from graph 1, screen 0 to screen 1, screen 1 behind \
  fillstyle solid noborder
set object 3 rectangle from screen 0, graph 1 to screen 1, screen 1 behind \
  fillstyle solid noborder
set object 4 rectangle from screen 0, screen 0 to screen 1, graph 0 behind \
  fillstyle solid noborder

plot NaN not

unset multiplot

Edge overdraw example