【问题标题】:Gnuplot Thick Curve Exceeds Plot BoundaryGnuplot 粗曲线超出绘图边界
【发布时间】:2013-09-07 14:17:51
【问题描述】:

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

为了说明问题,我将紫色曲线弄得异常肥大。不过,蓝色曲线也存在问题。

产生上述情节的代码是:

#!/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

有问题/狡猾的修复...

【问题讨论】:

  • 你可以通过增加边框来作弊,但我认为你不希望这样......
  • 是的,我也想过,但这确实有点糟糕,我最终得到了巨大的边界。我也想过在它上面画一个白色的矩形,但这看起来很荒谬。您是否知道是否至少有一种方法可以将曲线带到最前面的图层以便越过边界?
  • 实际上已经想出了如何做到这一点...set border back
  • 问题是,gnuplot 在核心代码中进行了裁剪,它只能尊重坐标,而不能尊重线条的形状。这将需要对代码进行大量更改。我仍然很好奇对您的功能请求的反馈。
  • 用户有时也会做出奇怪的事情;)。确实需要一个逗号:逗号之前的都是主轴,逗号后面的都是短轴。而ls -1 没有意义,因为linestyle 是用户定义的样式,必须有一个数字> 0。你的意思是lt -1,在你的情况下,gnuplot 会退回到它。所以你的网格选项是set grid mxtics mytics xtics ytics lt -1 lc rgb 'gray70', lt -1 lc rgb 'gray90'

标签: gnuplot


【解决方案1】:

有一种方法可以做到这一点,但它很麻烦。您将使用多图,绘制数据,然后通过明智地使用 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

【讨论】:

  • 好收获。这不适用于所有终端,postscript 终端不允许lw 0,您必须使用fillstyle solid noborder
  • 感谢@Christoph,我会相应地更改我的脚本。
  • 以上代码不适用于cairolatex。知道为什么吗?谢谢。
  • @Andreas 我在 Debian 上使用 4.6.0、4.6.3、4.6.4 和 4.7(2013-08-01 和 2013-09-23)再次对其进行了测试,它适用于所有这些,我运行gnuplot mosfet.gp && pdflatex MosfetClassAbPowerFixed.tex && xpdf MosfetClassAbPowerFixed.pdf
猜你喜欢
  • 1970-01-01
  • 2020-11-29
  • 2012-06-18
  • 1970-01-01
  • 2021-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多