2012-07-12 90 views
3

有沒有辦法讓圖形的x/y tic-labels格式依賴於tic的值?我設想格式的語句有條件的gnuplot 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) 

但我想避免這麼具體,因爲每當圖形的範圍發生變化時,這組標籤都會發生變化。我期望這個問題的答案是'不',但這裏是希望。

回答

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. 
+0

哇。這有些複雜,但它避免了手動重新指定TIC標籤,這正是我所要做的。謝謝! (我會贊成,但我還沒有足夠的聲望。) – KDN 2012-07-12 03:58:05