gnuplot,非数字重复x值

gnuplot,非数字重复x值,gnuplot,Gnuplot,我有这样的数据集(文件名“data”): a 10.1 b 10.1 c 10.2 b 15.56 a 3.20 我想把这些数据画成点。当我尝试时: 使用2:xticlabels(1)绘制“数据” 我得到5个x轴值a、b、c、b、a的绘图,但我希望在所有5个y值的绘图上只得到3个(a、b、c(顺序不重要))。可能吗 我的真实数据文件如下所示: 2-8-16-17-18 962.623408 2-3-4-5-6-97.527840 2-8-9-10-11962.623408 2-8-9-10

我有这样的数据集(文件名“data”):

a 10.1
b 10.1
c 10.2
b 15.56
a 3.20

我想把这些数据画成点。当我尝试时:
使用2:xticlabels(1)绘制“数据”

我得到5个x轴值a、b、c、b、a的绘图,但我希望在所有5个y值的绘图上只得到3个(a、b、c(顺序不重要))。可能吗

我的真实数据文件如下所示:

2-8-16-17-18 962.623408
2-3-4-5-6-97.527840
2-8-9-10-11962.623408
2-8-9-10-11937.101308
2-3-4-5-6 37.101308

并且有大约一千条记录


我不知道如何使用mgilson的代码,但他给了我一个想法。我向数据文件添加附加列(索引):

我怀疑你是否能想出一个只有gnuplot的解决方案。但是,只要您的系统上安装了python2.5或更高版本,这种方法就可以工作。(它适用于您的测试数据)

现在,绘制此图的脚本:

set style line 1 lt 1 pt 1
plot '<python pythonscript.py data' i 0 u 2:xticlabels(1) ls 1,\
     '' i 1 u 1:2 ls 1 notitle
设置样式行1 lt 1 pt 1

绘图‘x轴上的顺序真的重要吗?
#!/usr/bin/perl 
$index_number = 0; 
while (<>) 
{ 
   $line = $_;
   @columns = split(" ",$line);
   $col1 = $columns[0];
   $col2 = $columns[1];
   if( not exists $non_numeric{$col1} )
   {
      $index_number++;
      $non_numeric{$col1} = $index_number;
   }
   print "".$non_numeric{$col1}."\t".$col1."\t".$col2."\n"; 
}
import sys
import collections

data = collections.defaultdict(list)
keys = []

# build a mapping which maps values to xticlabels (hereafter "keys")
# Keep a second keys list so we can figure out the order we put things into
# the mapping (dict)
with open(sys.argv[1]) as f:
    for line in f:
        key,value = line.split()
        data[key.strip()].append( value )
        keys.append(key.strip())

def unique(seq):
    """
    Simple function to make a sequence unique while preserving order.
    Returns a list
    """
    seen = set()
    seen_add = seen.add
    return [ x for x in seq if x not in seen and not seen_add(x) ]

keys = unique(keys) #make keys unique

#write the keys alongside 1 element from the corresponding list.
for k in keys:
    sys.stdout.write( '%s %s\n' % (k, data[k].pop()) )

# Two blank lines tells gnuplot the following is another dataset
sys.stdout.write('\n\n')

# Write the remaining data lists in order assigning x-values
# for each list (starting at 0 and incrementing every time we get
# a new key)
for i,k in enumerate(keys):
    v = data[k]
    for item in v:
       sys.stdout.write( '%d %s\n' % (i, item) )
set style line 1 lt 1 pt 1
plot '<python pythonscript.py data' i 0 u 2:xticlabels(1) ls 1,\
     '' i 1 u 1:2 ls 1 notitle