gnuplot - 如何在 gnuplot 中的图形旁边打印输入文件?

标签 gnuplot

是否可以使用 gnuplot 打印我在图表旁边绘制的数据?

如果我有一个文本文件input.txt:

#x y
 1 2
 2 5
 3 6
 4 7

我做 plot 'input.txt' 我想像往常一样绘制它,并在图旁边打印表格。这可能吗?

注意:我使用的是 Windows,我想格式化输出。

最佳答案

有点晚了,但是OP要求Windows...所以,简而言之:

data = system('type yourfile.dat')   # Windows

在Windows中,如果给出路径,需要注意\、空格和双引号"

数据: SO22225051.dat

#x y
 1 2
 2 5
 3 6
 4 7

脚本:

适用于 Linux Windows 的解决方案。 gnuplot>=5.2.0 的版本 1,gnuplot>=4.6.0 的版本 2。

### place data as table/text in graph
reset

FILE = 'SO22225051.dat'
set rmargin 15
set label 1 at screen 0.9,0.7 font "Courier New,12"

# Version 1: Windows & Linux using system() command; 
# GPVAL_SYSNAME only available for gnuplot>=5.2.0

getData(f) = GPVAL_SYSNAME[1:7] eq "Windows" ? \
             system(sprintf('type "%s"',f)) : \
             system(sprintf('cat  "%s"',f))     # Linux/MacOS

Data = getData(FILE)
set label 1 Data
plot FILE u 1:2 w lp pt 7 lc rgb "red"

pause -1

# Version 2: gnuplot-only, platform-independent, working at least with gnuplot>=4.6.0

Data = ''
set datafile commentschar ''
set datafile separator "\t"
stats FILE u (Data=Data.strcol(1)."\n") nooutput
set datafile commentschar   # restore default
set datafile separator      # restore default

set label 1 Data
plot FILE u 1:2 w lp pt 7 lc rgb "red"
### end of script

结果:

版本 1 和 2 之间的唯一区别是,在版本 2 中,gnuplot 将删除每个数据行的前导空格。

enter image description here

关于gnuplot - 如何在 gnuplot 中的图形旁边打印输入文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22225051/

相关文章:

使用 gnuplot 绘制多图的 Shell 脚本

utf-8 - 在 gnuplot 中使用自定义 unicode 字体生成 (e)ps 或 pdf 的斜体和粗体拉丁文和希腊字母

gnuplot - 绘制热图时如何跳过 Gnuplot 中的行?

linux - 如何在 GNUPLOT 中绘制实时数据?数据来自不断向其记录新数据的文件

linux - 如何在 linux 中更改 gnuplot 的目录?

使用 'with image' 时 gnuplot 抽动消失

file - Gnuplot : Size of points

pdf - gnuplot - pdf 终端 - 设置 unicode 字符(太阳质量符号/odot)

gnuplot - 如何正确地将透视图添加到代表分子的 Gnuplot 3D 连接点云?

c++ - GNUPlot 的 MPI IO 格式化