【问题标题】:Gnuplot with SI-prefixes: How do I get gnuplot not to display decimal zeros?带有 SI 前缀的 Gnuplot:如何让 gnuplot 不显示十进制零?
【发布时间】:2016-05-24 12:30:26
【问题描述】:

我正在 Gnuplot 中使用 xtics 的自定义格式绘制波长。我想要达到的是xtics 像这样:

200nm、400nm、600nm、800nm、1um、1.2um、1.4um

这段代码我快到了:

set xlabel "Wavelenth"
set format x "%3.1s%cm"
set xrange [1e-8:1.5e-6]

plot x lw 3

但是,由于%3.1s,Gnuplot 会附加一个无用的.0,而这里不需要。所以 Gnuplot 的xtics 在上述范围内是:

200.0nm、400.0nm、600.0nm、800.0nm、1um、1.2um、1.4um

这扩大了tics,这是丑陋的。我不知道如何指定宽度和精度,以便不显示全为零的小数位。有什么办法吗?

【问题讨论】:

  • 您是否尝试过%s%cm?否则,如果不使用 set for [...] xtics add ... 手动设置标签,我认为您无法实现这一目标@

标签: gnuplot


【解决方案1】:

我认为除了手动指定抽动之外这是不可能的:

set xtics ("200nm" 2e-7, "400nm" 4e-7, "600nm" 6e-7, "800nm" 8e-7, "1.2um" 1.2e-6, "1.4um" 1.4e-6)

如果你使用 postscript 终端,你可以用 sed 去掉“.0nm”

set term postscript eps
set out 'plot.eps'
set xlabel "Wavelenth"
set format x "%3.1s%cm"
set xrange [1e-8:1.5e-6]
plot x lw 3
set output
!sed  -i 's/\.0nm/nm/g' plot.eps

【讨论】:

  • 没试过这个,但无论如何你必须在调用sed之前用set output完成输出
  • @Christoph 不知道,脚本之前运行良好(可能并非总是如此),所以我现在在答案中添加了这一行
猜你喜欢
  • 1970-01-01
  • 2023-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-10
  • 1970-01-01
相关资源
最近更新 更多