gnuplot 命令行绘图工具命令

gnuplot命令行绘图工具命令

绘图示例预览

gnuplot工具非常强大,可以在命令行进行曲线绘图,当然也可以在UI界面绘图。

绘图命令:

gnuplot> plot 'test.csv' u ($0):1 w lp t 'c1', 'test.csv' u ($0):2 w lp t 'c2'

绘图效果:

gnuplot绘图示例

数据文件:

123 145
143 156
156 178
165 189
168 199
176 203

gnuplot常用命令

准备

安装gnuplot

$ brew install gnuplot
==> Installing dependencies for gnuplot: libpng, freetype, fontconfig, jpeg-turbo, brotli, giflib, imath, openexr, libtiff, webp, jpeg-xl, libvmaf, aom, libavif, gd, libcerf, lua, gettext, pcre2, glib, libpthread-stubs, xorgproto, libxau, libxdmcp, libxcb, libx11, libxext, libxrender, lzo, pixman, cairo, fribidi, graphite2, harfbuzz, pango and qt@5
==> Installing gnuplot dependency: libpng
==> Pouring libpng--1.6.38.arm64_monterey.bottle.tar.gz
...
==> Running `brew cleanup gnuplot`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

启动

$ gnuplot

        G N U P L O T
        Version 5.4 patchlevel 4    last modified 2022-07-10 

        Copyright (C) 1986-1993, 1998, 2004, 2007-2022
        Thomas Williams, Colin Kelley and many others

        gnuplot home:     http://www.gnuplot.info
        faq, bugs, etc:   type "help FAQ"
        immediate help:   type "help"  (plot window: hit 'h')

Terminal type is now 'qt'
gnuplot>

退出绘图模式

gnuplot> q

直接执行命令

gnuplot -e "set term dumb; plot 'test.csv';"
gnuplot -e 'set term dumb; plot "test.csv" u ($0):1 w lp t "c1", "test.csv" u ($0):2 w lp t "c2";'

查看帮助文档

 gnuplot --help
 gnuplot> h plot
 Syntax:
       plot {<ranges>} <plot-element> {, <plot-element>, <plot-element>}
 <press enter to exit>

切换输出模式

gnuplot> set term qt
gnuplot> set term dumb

执行shell命令

gnuplot> !cat text2.csv

采用缩写形式

u using
w with
lp linespoints
h help
绘图

设置图例名称

gnuplot> plot 'test.csv' title 'c1'

选取数据列绘图

gnuplot> plot 'test.csv' using 1:2
gnuplot> plot 'test.csv' using 1:2, 'test.csv' using 1:3

选择线条风格

gnuplot> plot 'test.csv' with lines
gnuplot> plot 'test.csv' with linespoints
gnuplot> plot 'test.csv' with points

使用行号作为横轴

gnuplot> plot 'test.csv' using ($0):1, 'test.csv' using ($0):2
设置

设置标题

gnuplot> set title 'Test Title'
gnuplot> set xlabel 'Times'
gnuplot> set ylabel 'Cost/ms'

设置注释箭头

gnuplot> set arrow 1 from 1,200 to 0.2,208
gnuplot> show arrow

        arrow 1, head nofilled back linewidth 1.000 dashtype solid
          from (1.00000, 200.000, 0.00000) to (0.00000, 208.000, 0.00000)

设置注释图例

set key at 2, 0.5

设置注释文本

set label "y=x" at 0, 208

参考文档

gnuplot使用文档
• http://www.gnuplot.info/
• https://alvinalexander.com/technology/gnuplot-charts-graphs-examples/
• https://stackoverflow.com/questions/50309923/plot-a-single-column-data-with-different-scale-on-the-horizontal-axis-in-gnuplot
• https://blog.csdn.net/qq_33523925/article/details/88219854
• https://www.cnblogs.com/xueqiuqiu/articles/12919148.html

matplotlib/pyplot使用文档
• https://stackoverflow.com/questions/911655/gnuplot-vs-matplotlib
• https://blog.csdn.net/pipisorry/article/details/37742423

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
gnuplot是一个强大的开源绘图工具,用于生成各种类型的图形,包括二维和三维图形。它支持多种操作系统,并提供了丰富的绘图选项和功能。 以下是gnuplot的一些基本教程和用法: 1. 安装gnuplot:首先,你需要下载并安装gnuplot。你可以从gnuplot官方网站(https://www.gnuplot.info/)上找到适合你操作系统的安装包,并按照指示进行安装。 2. 启动gnuplot:安装完成后,你可以在命令行中输入“gnuplot”来启动gnuplot。启动后,你将看到一个gnuplot命令提示符。 3. 绘制简单的二维图形:使用gnuplot可以绘制各种类型的二维图形,如折线图、散点图、柱状图等。你可以使用gnuplot命令来指定数据文件、设置坐标轴、选择绘图样式等。例如,使用命令“plot 'data.txt' with lines”可以将名为"data.txt"的数据文件以折线图的形式绘制出来。 4. 绘制三维图形:gnuplot还支持绘制三维图形,如曲面图、散点云图等。你可以使用类似于二维图形的命令来指定数据文件、设置坐标轴、选择绘图样式等。例如,使用命令“splot 'data.txt' with lines”可以将名为"data.txt"的数据文件以曲面图的形式绘制出来。 5. 自定义图形样式:gnuplot提供了丰富的选项和功能来自定义图形样式。你可以设置线条颜色、线型、点型、标签等。你还可以添加标题、坐标轴标签、图例等来增强图形的可读性。 6. 脚本文件:为了方便重复使用和批量处理,你可以将gnuplot命令保存在一个脚本文件中,并通过命令“load 'script.gp'”来执行脚本文件。 希望以上简要介绍对你有帮助!如果你有更具体的问题或需要进一步了解,请告诉我。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值