如何在gnuplot中为xticlabels提供自定义字符串参数? [英] How do I give custom string argument to xticlabels in gnuplot?

查看:121
本文介绍了如何在gnuplot中为xticlabels提供自定义字符串参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有一个包含三列的数据文件.我希望能够更改x轴标签.经过一番谷歌搜索后,我发现了xticlabels(),但问题是它似乎只以列号作为参数.对于使用xticlabels(3)进行绘制,请在第三列标记标签.

Lets say I have a data file with three columns. I want to be able to change the x-axis labels. After a little googling I found xticlabels() but the problem is that it only seems to take a column number as the argument. For ex- plotting with xticlabels(3) marks the labels with the third column.

我希望能够将$1+$2之类的内容用作该函数的参数,即标签应为column1和column2的串联.

I want to be able to put something like $1+$2 as the argument for this function i.e. the label should be a concatenation of column1 and column2.

我该怎么做?

推荐答案

您使用awk ...

You use awk...

plot "<awk '{print $1,$2,$1 $2}' datafile" u 1:2:xticlabels(3) 

当然,这是一个愚蠢的示例,因为我们要串联2个(数字)字段来创建标签-令人怀疑的是您想要的是什么,但是它显示了如何在awk和真的就是您所需要的.

Of course, this is a silly example because we're concatenating 2 (numeric) fields to create the labels -- It's doubtful that is what you want, but it shows how to concatenate two fields (as strings) in awk and that's really all you need.

或者,您也可以哄骗gnuplot来执行此操作(未测试),并具有以下某些变体:

Alternatively, you can probably coax gnuplot to do this (untested) with some variant of the following:

plot 'datafile' u 1:2:( xticlabels( stringcolumn(1).stringcolumn(2) ) )

这篇关于如何在gnuplot中为xticlabels提供自定义字符串参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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