風来坊@真幸福知

出雲市 福知寺 行事ご案内 坐禅会 日記 テクノロジー English Zazen session Korean 한국어 참선 뮥조선

Gnuplot: a patch to enable "pointnumber" function

The world famous 2D/3D plotting software Gnuplot has a function that you can plot a data with a line and some of the points on the line (after version 4 or so).

 

plot "data.txt" using 1:2 w lp pi 20

 

This plots column 1 and 2 data for x and y axes with lines and points, while the points appear once in every 20 data points.

However, ususally you do not know total number of the data contained in a file and just want 20 points appearing on the line drawn from the left end to the right end of the plot.

For this purpose, I wrote a patch (many years ago :-) containing a function called "pointnumber" that specifies the total number of points appearing on a line.

This works like this:

 

plot "data.txt" using 1:2 with linespoints pointnumber 20

 

or,

 

plot "data.txt" using 1:2 w lp pn 20

 

Then, the line is drawn using all the data points, while only 20 points appear along the line.

The patch is available for download at the following link.

=> Gnuplot "pointnumber" patch [DOWNLOAD] (patch, Linux (*.deb) and Windows binaries are available)

Enjoy plotting :-)

--------

- Correction: Nov. 19, 2016: "set pointnumber .." does not work. "pointnumber" option is applicable only in the "plot ..." command as same as the "pointinterval".

- Patched and compiled binaries (executables) are also available for Linux Mint (*.deb) and Windows (*.zip) at the download link above. The windows version is not an installer. Extract in any place and add the path of "gnuplot/bin" to the $PATH environmental variable, or put the link of wgnuplot.exe to the start menu.

- Correction of the patch: Jan. 28, 2017: now it does not use random number to fluctuate the offset of the first drawn point.

- Correction of the patch: Jan. 30, 2017: I changed the algorithm for the shifting of the starting offset of the points; now, it looks much better, while the number of points actually drawn can change by missing a point the the edge; it should be no problem; also, fixes were made for consistency in lines/points style handling. (Thanks to comments by Ethan!)

f:id:cheonghongsa:20170130150816p:plain

adding an image to make this page look a bit better :-)

-------

Finally, this "pointnumber" function was added in the new version 5.2! Now, the first release candidate RC1 is available. (as of June 1, 2017)

=> gnuplot homepage (The source code & Windows binary are available.)

A Linux binary (*.deb package) is available [HERE]  (...5.2rc1...)

Bug in 5.2 RC1: When your initialization file .gnuplot includes "set style ..." before definition of terminal (e.g. "set term unknown"), it dies with "Segmentation fault". If it happens, just add "set terminal unknown" at the beginning of .gnuplot.

------

Gnuplot 5.2.0 including the "pointnumber" is finally released as an official version (Sep. 4, 2017)

=> gnuplot homepage (The source code & Windows binary are available.)

A Linux binary (*.deb) is available [HERE] (...5.2.0-1) (compiled on Ubuntu 16.04)

------

5.2.0 has a bug in the inline range handling.

Try this:

> set logscale xy

> plot [20:200][20:200] x

Then, you will find that the yrange is not drawn as specified in the inline range [20:200]. It happens for log scaled y-axis made by "set logscale" in stead of newly introduced "set nonlinear". So, it is related to the "nonlinear", and seems to have relation also to other newly implemented functions and the fix is not easy. A fix is proposed in the developmental version 5.3 and the patch seems to work for a while, at least for this specific problem. It is said a fix may affect other issues.

Anyway, the patch (privided for 5.3, fixed for 5.2 source) and the *.deb binary with the patch is available [HERE] (...5.2.0-km1) (compiled on Ubuntu 16.04)

To work around with the normal 5.2.0, using yrange [ : ] or specifying log scale by "set nonlinear" will do.

> set nonlinear x via log10(x) inv 10**x
> set nonlinear y via log10(y) inv 10**y
> set mytics 10
> set mxtics 10
> plo [][20:200] x