format - 条件 gnuplot tic 格式化

标签 format gnuplot

有没有办法使图形的 x/y 坐标标签的格式取决于坐标的值?我正在设想格式声明

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 )

但我不想说得太具体,因为每次图表范围发生变化时,这组标签都会发生变化。我希望这个问题的答案是“否”,但希望如此。

最佳答案

嗯……这取决于你想为制作这个情节付出多少努力。这是一个做你想做的事的例子。以自动化方式制作有点困难,(您需要调整标题的边距等)但是如果您只需要一个漂亮的演示文稿或论文图并且有时间让它看起来像您想要的那样,这应该可以正常工作。

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.

关于format - 条件 gnuplot tic 格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11443431/

相关文章:

gnuplot - 使用接近零的三次函数绘制参数函数会产生垃圾

gnuplot - 使用gnuplot中的多个记录绘制一维二进制数组(uint8)

linux - Gnuplot 条形图对齐

ios - 为什么我的字符串格式化程序使参数 0.00 而不是它的实际值

c++ - 将具有多个空终止字符的字符数组解析为不同的字符串 - C++

java - 如何在 Java 中格式化时间间隔?

gnuplot - gnuplot 中的粗体增强文本

GNUPLOT:带绘图和调色板的对数颜色框

字符串格式化过程与writeln类似

xcode - 等同于 %@ 的 Swift 字符串格式说明符