Gnuplot交换轴

Gnuplot交换轴,gnuplot,Gnuplot,我想用gnuplot复制这个图: 我的数据具有以下格式: 数据 1:时间 2:价格 3:卷 我试过这个: plot file using 1:2 with lines, '' using 1:3 axes x1y2 with impulses 它给出了一个正常的时间序列图,y1作为价格,y2作为体积。 接下来,我尝试: plot file using 2:1 with lines, '' using 2:3 axes x1y2 with impulses 它给出的价格序列中,y1表示时间

我想用gnuplot复制这个图:

我的数据具有以下格式:

数据
1:时间
2:价格
3:卷

我试过这个:

plot file using 1:2 with lines, '' using 1:3 axes x1y2 with impulses
它给出了一个正常的时间序列图,
y1
作为价格,
y2
作为体积。
接下来,我尝试:

plot file using 2:1 with lines, '' using 2:3 axes x1y2 with impulses 
它给出的价格序列中,
y1
表示时间,
y2
表示体积。 但是,我需要价格保持在
y1
,数量保持在
x2

可能是这样的:

plot file using 1:2 with lines,' ' using 2:3 axes y1x2 with impulses

然而,这并没有给出我想要的。

Gnuplot
没有官方方法来绘制这种水平箱线图。但是,您可以使用
boxyErrorBars
(缩写
boxxy
)来实现这一点

由于我没有您的实际示例的任何测试数据,所以我从高斯随机游走生成了一个数据文件。要生成数据,请运行以下
python
脚本:

from numpy import zeros, savetxt, random

N = 500
g = zeros(N)
for i in range(1, N):
    g[i] = g[i-1] + random.normal()

savetxt('randomwalk.dat', g, delimiter='\t', fmt='%.3f')
接下来,我将对“位置数据”(在您的情况下是体积数据)进行装箱。为此,可以使用平滑频率。这将计算相同
x
-值的
y
值之和。因此,首先我使用一个适当的binning函数,它为某个范围返回相同的值(
x
+-
binwidth/2
)。输出数据保存在文件中,因为对于绘图,我们必须交换
x
y
值:

binwidth = 2
hist(x) = floor(x+0.5)/binwidth

set output "| head -n -2 > randomwalk.hist"
set table
plot 'randomwalk.dat' using (hist($1)):(1) smooth frequency
unset table
unset output
通常情况下,应该能够使用
设置表格“randomwalk.hist”
,但由于存在错误,需要此解决方法来过滤掉表格输出的最后一个条目,请参阅我的答案

现在,实际打印部分是:

unset key
set x2tics
set xtics nomirror

set xlabel 'time step'
set ylabel 'position value'
set x2label 'frequency'

set style fill solid 1.0 border lt -1

set terminal pngcairo
set output 'randwomwalk.png'

plot 'randomwalk.hist' using ($2/2.0):($1*binwidth):($2/2.0):(binwidth/2.0) with boxxy lc rgb '#00cc00' axes x2y1,\
     'randomwalk.dat' with lines lc rgb 'black'
给出结果(使用4.6.3,当然取决于您的随机数据):

因此,对于您的数据结构,以下脚本应该可以工作:

reset
binwidth = 2
hist(x) = floor(x+0.5)/binwidth
file = 'data.txt'
histfile = 'pricevolume.hist'

set table histfile
plot file using (hist($2)):($3) smooth unique
unset table

# get the number of records to skip the last one
stats histfile using 1 nooutput

unset key
set x2tics
set xtics nomirror

set xlabel 'time'
set ylabel 'price'
set x2label 'volume'

set style fill solid 1.0 border lt -1

plot histfile using ($2/2.0):($1*binwidth):($2/2.0):(binwidth/2.0) every ::::(STATS_records-2) with boxxy lc rgb '#00cc00' axes x2y1,\
     file with lines using 1:2 lc rgb 'black'
请注意,这次跳过最后一个
条目是通过使用
stats
命令对所有条目进行计数来完成的,并使用
每个
跳过最后一个条目(是的,
stats\u records-2
是正确的,因为点编号从
0
开始)。此变体不需要任何外部工具


我还使用了计算平均值的
smooth unique
,而不是求和(使用
smooth frequency
)。

是否使用2:1绘制“文件”?否则,请提供示例输入文件和有关所需内容的更多详细信息。是,它在第二个命令中执行