我的目标是在对数刻度上显示0值,略低于1。
我设法用对数Y标度绘制我自己的简单直方图(with boxes
)。我的Y值是非负整数,最高可达25000.我无法区分0和1的值,因为Y标度从1开始。这在数学上是正确的,但我想在一个下面破解零。
如果我要编写一个绘制图形的程序,我会在所有数据中加1,并从Y标签中删除1。是否有任何技巧可以为我做这样的事情?
答案 0 :(得分:3)
gnuplot> set xrange [0:2]
gnuplot> set log y
gnuplot> set yrange [0.1:100]
gnuplot> set ytics ("0" 0.1, "1" 1, "10" 10)
gnuplot> plot cosh(x)
gnuplot>
答案 1 :(得分:3)
我认为最好的选择是使用修改后的函数绘制直方图:
plot 'data' using 1:($2 < 1 ? $2 : log10($2)+1) with boxes
如果数据大于或等于1,则上面的命令会绘制log10()+ 1,否则只会绘制数据。然后,您可以修改y轴,使其在0和1之间呈线性,在1和最高值之间以对数为单位:
ymax = 10000
set yrange [0:log10(ymax)]
unset ytics
set ytics 1 add ("0" 0, "1" 1)
set for [i=2:log10(ymax)] ytics add (sprintf("%g",10**(i-1)) i) # Add major tics
set for [i=1:log10(ymax)] for [j=2:9] ytics add ("" log10(10**i*j) 1) # Add minor tics
set for [j=1:9] ytics add ("" j/10. 1) # Add minor tics between 0 and 1
plot 'data' using 1:($2 < 1 ? $2 : log10($2)+1) with boxes
tic位置后的1是调整次要抽搐的长度(感谢@Christoph)。无论如何,对于测试用例x ^ 2,这看起来像下图,在这里您可以看到y轴如何线性上升到1并且对数超出:
答案 2 :(得分:1)
我希望这可以帮到你。这不只是一个“黑客”,而是一个在gnuplot上有一个线性对数y轴的真正方法:
reset
set terminal wxt 0 enhanced font 'Sans,13'
#%%% SIZE SETTINGS (whole figure)
tm = 0.90; bm = 0.2
lm = 0.12; rm = 0.885
size = 0.8
#%%% RANGE SETTINGS
y1 = 0.; y2 = 1.; #(lin interval)
y3 = 1.; y4 = 1000.; #(log interval)
x1 = -8.0; x2 = 8.0
set xrange [x1:x2];
#%%% SIZE SETTINGS (single plots)
I_1 = abs(y2-y1)
I_2 = abs(log10(y4)-log10(y3))
denom = I_1 + I_2
T_m_1 = lm + size * (I_1/denom)
T_m_2 = lm + size * ((I_1+I_2))/denom)
f(x) = (15.*sin(x)/x)**2
#%%% BEGIN MULTIPLOT
set multiplot
# Left and Right margins
set lmargin at screen lm
set rmargin at screen rm
# X-axis settings:
set xlabel "X [ux]"; set format x "%2.1f";
set xtics 2 nomirror; set mxtics 4
do for [i=(x1+1):(x2-1):2] {
set xtics add ("" i) }
set samples 10000;
# Y-axis label
set label 'Y [uy]' \
at screen 0.03,bm + 0.5*size \
offset 0,-strlen("X [ux]")/4.0 \
rotate by 90
#%% First plot, first interval
set border 1+2+8
set bmargin at screen bm
set tmargin at screen T_m_1
set yrange [y1:y2]
set format y "%1.0f";
set ytics 1; set mytics 5;
plot f(x) lw 2 \
lc rgb "navy" notitle
#%% End first plot
unset xlabel; unset xtics
#%% Second (and last) plot
set border 2+4+8
set bmargin at screen T_m_1
set tmargin at screen T_m_2
# showing mirror xtics via a x2 axis
set link x via x inverse x
set format x2 "";
set x2tics nomirror; set mx2tics 4;
do for [i=(x1+1):(x2-1):2] {
set x2tics add ("" i) }
set logscale y;
set ytics autofreq; set mytics autofreq;
set format y "10^{%L}";
set ytics add ("" 1.0);
set yrange [y3:y4]
plot f(x) lw 2 \
lc rgb "navy" notitle
#%% End second plot
unset multiplot
#%%% END MULTIPLOT
结果: image
代码实用指南:
修改“第二”绘图命令以绘制(在y3和y4之间)你的函数/数据文件
查看结果并修复次要细节,例如标签,格式,抽搐,徽章等。