条件gnuplot抽象格式

时间:2012-07-12 00:18:40

标签: format gnuplot

有没有办法让图形的x / y tic-labels格式取决于tic的值?我正在设想一种格式

的陈述
set format y ( ( ( <arg> > 1e-3 ) && ( <arg> < 1e2 ) ) ?  "%2.1f" : "10^{%T}" )

以便将对数比例图表示为

10 ^ { - 4},10 ^ { - 3},0.01,0.1,1,10,10 ^ {2}

依此类推,为1附近的数字提供更自然的表示。

我知道这可以通过明确声明格式来完成,即

set xtics ( "10^{-3}" 1e-3, "0.01" 0.01, "0.1" 0.1, "1" 1, "10" 10, "10^{2)" 1e2 )

但我想避免这么具体,因为每次图表的范围发生变化时,这组标签都会发生变化。我希望这个问题的答案是'不',但这里有希望。

1 个答案:

答案 0 :(得分:5)

嗯......这取决于你想要制作这个剧情的努力程度。这是一个做你想要的例子。这是一个有点困难的情节,以自动化的方式制作,(你需要调整标题的边距等)但如果你只是需要一个好看的情节的演示文稿或纸张,并有时间花费使它看起来你想要的,这应该可行。

set termoption enhanced

#for this to work, we need to set ranges explicitly :-(
set xrange [-10:10]
set yrange [1e-4:exp(10)]

#Yippee!!! logscale plots :-)
set logscale y

#We'll make 3 plots.  The first plot is of the data and a piece of the y range tics
# the next two plots have no data, they only add another piece of the range tics.
set multiplot

#for this to work, we have to guarantee that all the plots line up exactly
set lmargin at screen 0.1
set bmargin at screen 0.1
set rmargin at screen 0.9
set tmargin at screen 0.9

set ytics 1e-2,10,90 format "%g"  #center of the range, normal tics.
plot exp(x)+exp(-x)               #looks like a V in logscale.  Neat.
unset xtics                       #already did this once.  don't need to put it on again.
unset border                      #already did this once too...
set ytics 100,10 format "10^{%L}" #Next plot, top end of the tics
plot NaN notitle                  #plots nothing.  Only works if range is set explicitly.
set ytics 1e-5,10,9e-3            #next plot, low end of the tics

#Any additional labels, objects, arrows, the title etc. should go here.  
#Otherwise you'll need to unset them like we did with the xtics and border 
#to prevent them from being plotted twice 
#(objects which are plotted twice sometimes look a little bit darker than they should).

plot NaN notitle
unset multiplot                   #and we're done.