是否可以将索引用作直方图中的Xtic值? [英] Is it possible to use indices as xtic values in a histogram?

查看:83
本文介绍了是否可以将索引用作直方图中的Xtic值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在具有以下结构的数据的文件中:

In a file with the data in the following structure:

# [year]
"Town A" population
"Town B" population
"Town C" population

# [year2]
"Town A" population
"Town B" population
"Town C" population

# [year3]
"Town A" population
"Town B" population
"Town C" population

我设法使用以下方法创建了直方图:

I have managed to create a histogram using the following:

set style data histogram
set style histogram columnstacked
p 'file.dat' index '[year]' u 2:key(1) ,\
'' index '[year2]' u 2,\
'' index '[year3]' u 2;

以前的设置几乎按照我需要的方式生成图形,但是,我希望能够将索引名称(标记?)用作xtic值,目前,xtic值为0、1和2代替year,year2和year3. gnuplot可以将索引值用作具有这种数据结构的直方图中的xtics吗?

The previous settings produce the graph almost the way I need it, however, I would like to be able to use the index names (tags?) as xtic values, as of this moment, the xtic values are 0, 1, and 2 instead of year, year2 and year3. Can gnuplot use index values as xtics in a histogram with such data structure?

推荐答案

我看不到在plot命令本身中进行设置的方法.这是一个好主意,我将其作为gnuplot的功能要求进行推广.我可以建议的最好方法是,假设您事先知道索引字符串集. 我将其显示为对N的迭代,因为我认为您可能确实有3个以上,而对于较大的数字,该迭代的键入要少得多.

I cannot see a way to set this up inside the plot command itself. It's a great idea and I'll push it on as a feature request for gnuplot. The best I can suggest is this, which assumes you know the set of index strings in advance. I show it as an iteration over N because I assume you may really have more than 3 and for larger numbers the iteration is far less typing.

N = 3
array INDEX[N] = [ "[year1]", "[year2]", "[year3]" ]
set xtics 1
set for [i=1:N] xtics add (INDEX[i] i-1)

plot 'file.dat' index INDEX[1] u 2:key(1) ,\
     for [i=2:N] '' index INDEX[i] u 2

这篇关于是否可以将索引用作直方图中的Xtic值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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