如何为下面给出的数据文件绘制类似于附图的能级图? (在数据文件的能量部分中,连续的行对应于不同的扩散值。)
orbitals = ['1s1/2', '1p3/2', '1p1/2', '1d5/2','1d3/2','2s1/2','1f7/2','1f5/2','2p3/2','2p1/2',
'1g9/2','1g7/2','2d5/2','2d3/2','3s1/2','1h11/2','1h9/2','2f7/2','1i13/2']
neutron_energies = [
[-1.227,-39.078,-38.630,-34.666,-33.512,-32.237,-29.683,-27.441,-25.945,-24.930,-24.211,-20.484,-19.296,-17.191,-17.014,-18.309,-12.704,-12.388,-12.017],
[-1.261,-39.036,-38.583,-34.610,-33.445,-32.184,-29.614,-27.357,-25.890,-24.872,-24.130,-20.385,-19.246,-17.139,-16.977,-18.219,-12.597,-12.348,-11.919],
[-1.295,-38.995,-38.536,-34.554,-33.379,-32.130,-29.544,-27.273,-25.835,-24.815,-24.050,-20.287,-19.196,-17.089,-16.941,-18.129,-12.491,-12.309,-11.821],
[-1.329,-38.953,-38.489,-34.497,-33.312,-32.077,-29.475,-27.188,-25.780,-24.757,-23.969,-20.189,-19.146,-17.038,-16.905,-18.039,-12.385,-12.271,-11.724],
[-1.362,-38.911,-38.441,-34.440,-33.244,-32.023,-29.405,-27.103,-25.725,-24.699,-23.889,-20.091,-19.096,-16.988,-16.869,-17.950,-12.279,-12.233,-11.628]
]
neutron_diffuseness = [0.52, 0.53, 0.54, 0.55, 0.56]
如有任何帮助,我们将不胜感激。
我不知道如何在不完全重组数据文件的情况下处理它。另外,我不知道如何避免标签重叠。
使用您的数据格式,要实现所需的图表,您面临一些“挑战”。您问题中的格式看起来非常特殊并且有点“随机”,例如特别是轨道标签的空线分隔。
因此,我对以下内容的假设是输入数据实际上看起来像这样(如果不是,则必须调整脚本)。
orbitals
、neutron_energies
和neutron_diffuseness
的块由两空行分隔,并且值都在括号内的一行中。有了这个,您可以通过 index
轻松解决这些块(检查 help index
)。
数据:
SO78498280.dat
orbitals = ['1s1/2','1p3/2','1p1/2','1d5/2','1d3/2','2s1/2','1f7/2','1f5/2','2p3/2','2p1/2','1g9/2','1g7/2','2d5/2','2d3/2','3s1/2','1h11/2','1h9/2','2f7/2','1i13/2']
neutron_energies = [
[-1.227,-39.078,-38.630,-34.666,-33.512,-32.237,-29.683,-27.441,-25.945,-24.930,-24.211,-20.484,-19.296,-17.191,-17.014,-18.309,-12.704,-12.388,-12.017],
[-1.261,-39.036,-38.583,-34.610,-33.445,-32.184,-29.614,-27.357,-25.890,-24.872,-24.130,-20.385,-19.246,-17.139,-16.977,-18.219,-12.597,-12.348,-11.919],
[-1.295,-38.995,-38.536,-34.554,-33.379,-32.130,-29.544,-27.273,-25.835,-24.815,-24.050,-20.287,-19.196,-17.089,-16.941,-18.129,-12.491,-12.309,-11.821],
[-1.329,-38.953,-38.489,-34.497,-33.312,-32.077,-29.475,-27.188,-25.780,-24.757,-23.969,-20.189,-19.146,-17.038,-16.905,-18.039,-12.385,-12.271,-11.724],
[-1.362,-38.911,-38.441,-34.440,-33.244,-32.023,-29.405,-27.103,-25.725,-24.699,-23.889,-20.091,-19.096,-16.988,-16.869,-17.950,-12.279,-12.233,-11.628]
]
neutron_diffuseness = [0.52, 0.53, 0.54, 0.55, 0.56]
挑战:
X h1 h2 h3 h4 ...
x0 y01 y02 y03 y04 ...
x1 y11 y12 y13 y14 ...
x2 y21 y22 y23 y24 ...
x3 y31 y32 y33 y34 ...
...
其中
h1,h2,h3,...
是轨道标签,x0,x1,x2,...
是扩散值,y01, y02, ... y11, y12, ...
是能量值。当然,您可以使用外部工具来完成此操作,但通常,如果可能的话,我更喜欢在 gnuplot 中完成这一切。然而,由于 gnuplot 希望成为一个绘图工具,因此它并未针对数据重组进行优化。所以,有时可能会有点麻烦。
$LabelsSorted
。使用宏(检查
help arrays
)将数据引入数组(检查help macros
),以便索引更加灵活。
我想还有一些事情需要解释,但在变得过于冗长之前,请检查以下脚本并询问您是否还有更多问题。 如需进一步阅读,请检查:
help strcol
、help smooth
、help strstrt
等
脚本:(适用于 gnuplot>=5.2.7,2019 年 5 月)
### plotting energy diagram
reset session
FILE = "SO78498280.dat"
getArray(col,m) = (_s=strcol(col), _s[strstrt(_s,"=")+1:strlen(_s)-m])
set datafile separator "\n"
# get first lines of data into arrays
stats FILE index 0 u (orbitals=getArray(1,0)) nooutput
array O = @orbitals
stats FILE index 1 every ::1::1 u (energies=getArray(1,1)) nooutput
array E = @energies
stats FILE index 2 u (diffuseness=getArray(1,0)) nooutput
array D = @diffuseness
# restructure data
arrayToLine(col) = (_s=strcol(col), _s[strstrt(_s,"[")+1:strstrt(_s,"]")-1])
set table $Data
plot FILE index 0 u ("X,".arrayToLine(1)) w table, \
'' index 1 every ::1::5 u (sprintf("%g,%s",D[$0+1],arrayToLine(1))) w table
unset table
print $Data
# sort labels
set table $Labels
plot E u (sprintf("%g %s",E[$0+1],O[$0+1])) w table
set table $Labels2
set datafile separator whitespace
plot $Labels u 1:0 smooth freq
set table $LabelsSorted
plot $Labels2 u (sprintf("%g, %s, %g",E[$2+1], O[$2+1], $2)) w table
unset table
print $LabelsSorted
set datafile separator comma
set xlabel "diffuseness a_0 (fm)" enhanced
set xtics 0.01
set ylabel "E (MeV)
set key noautotitle
set autoscale fix
set offsets graph 0.2, graph 0.1, graph 0.1, graph 0.1
dy = 1.0
y1 = NaN
plot for [i=2:20] $Data u 1:i w lp pt 7 ps 0.5 lc i-2, \
$LabelsSorted u (D[1]):(y0=y1,y1=column(1), \
abs(y1-y0)<dy ? dy0=dy0+dy-abs(y1-y0) : dy0=0, y1=y1+dy0):2:3 \
w labels tc var right offset -1,0
### end of script
结果:
$Data
:
X,'1s1/2','1p3/2','1p1/2','1d5/2','1d3/2','2s1/2','1f7/2','1f5/2','2p3/2','2p1/2','1g9/2','1g7/2','2d5/2','2d3/2','3s1/2','1h11/2','1h9/2','2f7/2','1i13/2'
0.52,-1.227,-39.078,-38.630,-34.666,-33.512,-32.237,-29.683,-27.441,-25.945,-24.930,-24.211,-20.484,-19.296,-17.191,-17.014,-18.309,-12.704,-12.388,-12.017
0.53,-1.261,-39.036,-38.583,-34.610,-33.445,-32.184,-29.614,-27.357,-25.890,-24.872,-24.130,-20.385,-19.246,-17.139,-16.977,-18.219,-12.597,-12.348,-11.919
0.54,-1.295,-38.995,-38.536,-34.554,-33.379,-32.130,-29.544,-27.273,-25.835,-24.815,-24.050,-20.287,-19.196,-17.089,-16.941,-18.129,-12.491,-12.309,-11.821
0.55,-1.329,-38.953,-38.489,-34.497,-33.312,-32.077,-29.475,-27.188,-25.780,-24.757,-23.969,-20.189,-19.146,-17.038,-16.905,-18.039,-12.385,-12.271,-11.724
0.56,-1.362,-38.911,-38.441,-34.440,-33.244,-32.023,-29.405,-27.103,-25.725,-24.699,-23.889,-20.091,-19.096,-16.988,-16.869,-17.950,-12.279,-12.233,-11.628
$LabelSorted
:
-39.078, 1p3/2, 1
-38.63, 1p1/2, 2
-34.666, 1d5/2, 3
-33.512, 1d3/2, 4
-32.237, 2s1/2, 5
-29.683, 1f7/2, 6
-27.441, 1f5/2, 7
-25.945, 2p3/2, 8
-24.93, 2p1/2, 9
-24.211, 1g9/2, 10
-20.484, 1g7/2, 11
-19.296, 2d5/2, 12
-18.309, 1h11/2, 15
-17.191, 2d3/2, 13
-17.014, 3s1/2, 14
-12.704, 1h9/2, 16
-12.388, 2f7/2, 17
-12.017, 1i13/2, 18
-1.227, 1s1/2, 0
终端输出
wxt
:(set term wxt size 640,640
)