Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
470 views
in Technique[技术] by (71.8m points)

gnuplot: how to set custom non linear scales

is there any possibility for using non linear scales with self defined break of slope points? For example: i want the half of the y-scale shows the range [0:1] and the other half [1:5] and i do not want to use logarithmic scale.

The best thing would be the possibility to provide a mapping function. Sure one could directly map the function results but then the labes will not fit to the actual data.

Is there any possiblilty? I searched a bit but iam not sure if i missed something or if it is not possible.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This can be done with set link, which is available only in the 4.7 development version.

The following script does the mapping, but the labels are on the 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

Result with 4.7:

enter image description here

With some offset, you can move the labels from the y2-axis to the 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

That's quite ugly, but it works. It requires just a little fiddling with the left and right margins and the y2tics offset.

EDIT: I added minor tics, with a higher frequency between 0 and 1. I think it might be useful to add one label for 0.5 to show that the scale is linear, but with a different gradient (in which case you also might want to set y2tics format '%.1f' to have one decimal digit for all labels). However, this tic would also appear as a major tics, because using labels for minor tics is not supported, yet.

The result is: enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...