GnuPlot 中的 3 维图,其中颜色是我数据文件中的第四列? [英] 3-Dimensional Plot in GnuPlot where color is a fourth column in my data file?

查看:37
本文介绍了GnuPlot 中的 3 维图,其中颜色是我数据文件中的第四列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下所示的数据文件:

I have a datafile that looks like this:

1   2   3   0.5
2   8   9   0.2
3   4   78  0.4
6   5   7   0.01
9   9   9   0.3
10  12  18  0.9
6   8   4   1

我想做这样的图http://2.bp.blogspot.com/-378_rAaSSVU/UzU0gnGcr9I/AAAAAAAABnU/P1GwP9RKBkM/s1600/gnuplot.png其中第 4 列是颜色.

I would like to do a graph like this http://2.bp.blogspot.com/-378_rAaSSVU/UzU0gnGcr9I/AAAAAAAABnU/P1GwP9RKBkM/s1600/gnuplot.png Where the 4th column is the color.

我尝试过 - 显然不正确,因为我没有使用第四列,但我没有在文档中找到任何内容:

I tried - obviously incorrect because I do not use the fourth column but I failed to find anything in the documentation:

set dgrid3d 30,30
set view 60,45
set hidden3d
dataFile='prova.dat'
set palette defined (0 "blue", 0.5 "white", 1 "pink")
set pm3d 
splot dataFile u 1:2:3 with pm3d

这样的事情有可能吗?

推荐答案

仅使用 pm3d 您可以使用第四列来选择独立于 z 值的颜色.与 dgrid3d 一起,这不是直接可能的,因为网格不是在颜色列上执行的.

Using only pm3d you can use a fourth column to select a color independent of the z-value. Together with dgrid3d this is not directly possible, because the gridding is not performed on the color column.

您可以使用一种解决方法:首先将网格 z 值绘制到一个文件中,然后将网格颜色值绘制到第二个文件中,最后一点您禁用 dgrid3d,合并两个临时文件即时并绘制它们的值:

You can use a workaround: First you plot the gridded z-value to one file, then the gridded color values to a second file and as last point you disable dgrid3d, merge the two temporary files on-the-fly and plot their values:

set dgrid3d 30,30
dataFile='prova.dat'

set table dataFile.'.grid'
splot dataFile u 1:2:3
unset table

set table dataFile.'.color'
splot dataFile u 1:2:4
unset table

set view 60,45
set hidden3d
set palette defined (0 "blue", 0.5 "white", 1 "pink")
set autoscale cbfix
set pm3d
unset dgrid3d
set ticslevel 0
splot sprintf('< paste %s.grid %s.color', dataFile, dataFile) u 1:2:3:7 with pm3d notitle

请注意,paste 是用于类 Unix 操作系统的命令行工具.对于 Windows 的类似解决方案,您可以例如编写一个小的 Python 脚本 paste.py(参见我对 从 gnuplot 中的 2 个文件获取比率 可能的实现).然后你必须运行wgnuplot_pipes.exe 二进制文件,splot 命令变成

Note, that paste is a command line tool for Unix-like operation systems. For a similar solution for windows, you can e.g. write a small Python script paste.py (see my answer to Get ratio from 2 files in gnuplot for a possible implementation). Then you must run the wgnuplot_pipes.exe binary file and the splot command becomes

splot sprintf('< python paste.py %s.grid %s.color', dataFile, dataFile) u 1:2:3:7 with pm3d notitle

当然,为此您必须安装 python,并且必须通过 PATH 环境变量提供 python 二进制文件.

Of course, for this you must have python installed and the python binary must be available via the PATH environment variable.

这篇关于GnuPlot 中的 3 维图,其中颜色是我数据文件中的第四列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆