【问题标题】:How to ignore one column for autoscaling in gnuplot?如何在gnuplot中忽略一列进行自动缩放?
【发布时间】:2015-02-12 21:49:59
【问题描述】:

初始情况:

我有一个包含六个空格分隔列的文本文件 [ x, F_{1}(x), ... ,F_{5}(x) ]

我正在使用 pngcairo 将图形 F_{1} 到 F_{5} 绘制成单个 .png 图形:

set terminal pngcairo dashed size 1920,1080
set title "Title"
set output 'test.png'
set autoscale
plot 'test.txt' using 1:2 title "F_{1}" with lines, '' using 1:3 title "F_{2}" with     lines, '' using 1:4 title "F_{3}" with lines, '' using 1:5 title "F_{4}" with lines, '' using 1:6 title "F_{5}" with lines

F_{4}(x) 不幸的是很快就超出了规模,因此我需要忽略该单列以进行自动缩放。

如何忽略单个列进行自动缩放?

我正在考虑类似“设置自动缩放不使用 5”之类的命令。

注意:在这种情况下我不想要 logscale。

【问题讨论】:

标签: gnuplot scaling


【解决方案1】:

就像更新和记录一样,显然从 gnuplot 5.0.3 开始,您可以选择在绘图命令中设置 noautoscale 以便将其排除在自动缩放中。 在下面第二个图中的示例中,第 4 个函数 exp(x) 被排除在自动缩放之外。

代码:

### exclude data for autoscaling (gnuplot>=5.0.3)
reset session

# create some test data
set table $Data
    f1(x) = x
    f2(x) = x**2
    f3(x) = 0.2*x**3
    f4(x) = exp(x)
    f5(x) = 50*sin(x)
    plot '+' u (x):(f1(x)):(f2(x)):(f3(x)):(f4(x)):(f5(x)) w table
unset table

set multiplot layout 2,1
    plot for [i=1:5] $Data u 1:i+1 w l ti sprintf("f%d",i)

    plot for [i=1:3] $Data u 1:i+1 w l ti sprintf("f%d",i), \
         for [i=4:4] $Data u 1:i+1 w l ti sprintf("f%d",i) noautoscale, \
         for [i=5:5] $Data u 1:i+1 w l ti sprintf("f%d",i)
unset multiplot
### end of code

结果:

【讨论】:

    【解决方案2】:

    一种解决方案是从图中排除此列,将自动缩放 x 和 y 范围保存到变量,将此范围设置为用户定义并重新绘制(replot 命令对我来说与pngcairo 一起工作不好,所以只需将输出设置为原始文件并重写它):

    set terminal pngcairo dashed size 1920,1080
    set title "Title"
    set output 'test.png'
    set autoscale
    plot 'test.txt' using 1:2 title "F_{1}" with lines, '' using 1:3 title "F_{2}" with lines, '' using 1:4 title "F_{3}" with lines, '' using 1:6 title "F_{5}" with lines
    MAXY=GPVAL_Y_MAX
    MINY=GPVAL_Y_MIN
    MAXX=GPVAL_X_MAX
    MINX=GPVAL_X_MIN
    unset autoscale
    set yrange [MINY:MAXY]
    set xrange [MINX:MAXX]
    set output 'test.png'
    plot 'test.txt' using 1:2 title "F_{1}" with lines, '' using 1:3 title "F_{2}" with lines, '' using 1:4 title "F_{3}" with lines, '' using 1:5 title "F_{4}" with lines, '' using 1:6 title "F_{5}" with lines
    

    【讨论】:

    • 嗨,John,感谢您的快速回复,您的解决方案完美运行,您在保存 MINX、MAXX(您在此处再次分配 Y 值)时遇到了一点复制和过去错误,导致绘图中断。你能解决这个问题,所以我可以将你的答案标记为正确。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-19
    相关资源
    最近更新 更多