7

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

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

有没有可能?我搜索了一下,但我不确定我是否错过了某些东西,或者是否不可能。

4

2 回答 2

7

这可以通过set link4.7 开发版本提供。

以下脚本执行映射,但标签位于y2-axis 上:

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

4.7的结果:

在此处输入图像描述

通过一些偏移,您可以将标签从y2-axis 移动到y-axis:

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

这很丑陋,但它有效。它只需要稍微摆弄左右边距和 y2tics 偏移量。

编辑:0我添加了轻微的抽动,在和之间的频率更高1。我认为添加一个标签可能很有用,0.5以显示比例是线性的,但梯度不同(在这种情况下,您可能还希望set y2tics format '%.1f'所有标签都有一个十进制数字)。但是,此抽动也将显示为主要抽动,因为尚不支持使用小抽动的标签。

结果是: 在此处输入图像描述

于 2013-09-20T15:07:33.117 回答
3

你有几个选择来完成这种情节。我将使用这些示例数据:

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

多图法

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

这比下面的映射方法要复杂一些。

#!/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

结果:

在此处输入图像描述

映射方法

在这里,我们创建一个映射函数并操作 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

结果:

在此处输入图像描述

于 2013-09-20T15:12:18.730 回答