gnuplot:如何设置自定义非线性比例

时间:2013-09-20 14:20:49

标签: gnuplot

是否有可能使用具有自定义斜率点断点的非线性标度? 例如:我希望y标度的一半显示范围[0:1],另一半显示[1:5],我不想使用对数标度。

最好的事情是提供映射功能的可能性。 当然可以直接映射功能结果,但实验室不适合实际数据。

有可能吗?我搜索了一下,但我不确定我是否错过了什么或者是否有可能。

2 个答案:

答案 0 :(得分:5)

这可以使用set link来完成,y2仅在4.7开发版本中可用。

以下脚本执行映射,但标签位于reset f(x) = x <= 1 ? x : 1 + (x-1)*4 i(x) = x <= 1 ? x : (x-1)/4.0 + 1 set link y2 via f(y) inverse i(y) unset ytics set y2tics mirror set xrange[0:5] set yrange[0:2] plot x axes x1y2 - 轴:

y2

4.7的结果:

enter image description here

通过一些偏移,您可以将标签从y - 轴移动到reset set terminal pngcairo size 800,500 set output 'output.png' f(x) = x <= 1 ? x : 1 + (x-1)*4 i(x) = x <= 1 ? x : (x-1)/4.0 + 1 set link y2 via f(y) inverse i(y) unset ytics set lmargin at screen 0.1 set rmargin at screen 0.95 set y2tics mirror offset graph -1.04 right # set y2tics add (0.5) set my2tics 2 set y2tics add ('' 0.25 1, '' 0.75 1) set ylabel 'ylabel' offset -4 set xrange[0:5] set yrange[0:2] plot x axes x1y2 - 轴:

0

这很难看,但它确实有效。它需要稍微摆弄左右边距和y2tics偏移。

编辑:我添加了次要抽搐,频率介于10.5之间。我认为为set y2tics format '%.1f'添加一个标签以显示比例是线性的,但是使用不同的渐变可能很有用(在这种情况下,您也可能希望{{1}}为所有人设置一个十进制数字标签)。然而,这个抽搐也会出现一个主要的抽搐,因为不支持使用标签进行次要抽搐。

结果是: enter image description here

答案 1 :(得分:1)

你有几种方法可以完成这种情节。我将使用这些示例数据:

0 0
1 0.5
2 0.6
3 1
4 1.5
5 0.5
6 2.5
7 5
8 2

Multiplot方法

在这里,您只需将两个相同数据的图表叠加在一起。请注意,如果数据越过图表的边界,则该行中有一个关节(如果您绘制一条线)。

这比下面的映射方法稍微复杂一点。

#!/usr/bin/env gnuplot

reset

set terminal pdfcairo enhanced color lw 3 size 3,2 font 'Arial,14'
set output 'output.pdf'

set style data linespoints

set title 'my plot'
set key top left

set multiplot layout 2,1

### first (top) plot
# play with margins to ensure top and bottom plots are same size
set bmargin 0
set tmargin 2.5
# also that left margin is same with/without y label
set lmargin 6

set yrange [1:5]

unset xtics
set ytics 1 out scale 0.5 nomirror

# remove bottom line of border
set border 14

plot 'data.dat' pt 7 title 'my data'

### second (bottom) plot
unset title

# set margins to match first plot
set bmargin 2.5
set tmargin 0

set yrange [0:1]

# this offset along with the label offset compresses the bottom whitespace
set xtics out scale 0.5 nomirror offset 0,0.4

# create and place labels where they will be visible
set xlabel 'x label' offset 0,0.8
set ylabel 'y label' offset 1,3

# remove top line of border
set border 11
plot 'data.dat' pt 7 notitle

unset multiplot

reset

结果:

enter image description here

映射方法

这里我们创建一个映射函数并操纵y标签来匹配。请注意,该行中没有关节,可能是您想要的也可能不是。

#!/usr/bin/env gnuplot

reset

set terminal pdfcairo enhanced color lw 3 size 3,2 font 'Arial,14'
set output 'output2.pdf'

set style data linespoints

set key top left

set title 'my plot'
set xlabel 'x label'
set ylabel 'y label'

# mapping function
map(x) = x <= 1.0 ? x : (x-1.0)/4.0 + 1.0

# upper y bound is set by (5-1.0)/4.0 + 1.0
set yrange [0:2]
# y labels create illusion
set ytics out scale 0.5 nomirror \
  ("0" 0, "1" 1, "2" 1.25, "3" 1.5, "4" 1.75, "5" 2)
set xtics out scale 0.5 nomirror

plot 'data.dat' u 1:(map($2)) pt 7 title 'my data'

reset

结果:

enter image description here

相关问题