gnuplot — Basic 3D Plot
Previous post covers gnuplot basic 2D plot. This post covers the basics of gnuplot 3D plot.
Most of the 2D plot options apply to 3D plot, one should read the 3D plot post before reading this post.
gnuplot supports splot command for drawing 3D figures and graphs.
There are 3 options specific to 3D plot: isosamples, hidden3d, and surface.
isosamples: controls the number of grid points at which a function will be evaluated when using splot. It is therefore only relevant when plotting functions.
set isosamples {int:xlines} [,{int:ylines}]
hidden3d: use opaque surface rendering. It has the following format:
set hidden3d [offset {int:offset}] [trianglepattern {int:maks}]
- offset: used to control the color and line type used for the bottom side of the surface.
- trianglepattern: control which lines will be drawn to connect neighboring grid points.
surface: by default, the surface is shown. It can be switched off by using the command,
unset surface
or switch on with the command,
set surface
An Example
Below is a sample 3D plot script,
unset title
#unset key
#unset xtics
#unset ytics
#set format y "%.1t";
#set format x "%.1t";
set title "Test 3D" 0,1
set xlabel "X" -4,-2;
set ylabel "Y" 0,-2;
set zlabel "Z" 4,6;
#set border 0
set hidden3d offset 0
set surface
#set the view angle: one can adjust manually to get the proper value first
#and then modify the value here
set view 80,49
#set xrange []
#set yrange []
#set zrange []
#set ticslevel 0
#splot '45050.data' u 1:2:3 with lines
splot '$0' using 1:2:3 title "data1" with linespoints, '$1' using 1:2:3 title "data2" with linespoints
#
set term push
set term png size 800, 600
set output "$2"
replot
set output
set terminal pop
Suppose the file is saved as 3d.pg. And the two data files “3data.dat” and “3data2.dat” are listed below. Note that the data file must follow certain formats, otherwise the plot may not be expected. gnuplot supports two 3D data file formats, we only covers the grid format here. One can refer to reference 1 for more details.
The grid data format supported by gnuplot requires the follows,
- each line must contain x and y coordinates and the z value.
- data are organized into data blocks. And blocks are separated by a single blank line.
- each block must contain all data points for a single row of data points parallel to x axis. Therefore, the x coordinate stays constant at each data block.
- all data blocks must contain same number of data points. If the number is not the same, then gnuplot cannot draw a proper surface.
3data.dat
0 0 29.21
0 160 28.94
0 320 28.87
0 480 28.28
0 640 28.83
0 800 27.94
0 960 27.02
160 0 28.45
160 160 28.48
160 320 27.73
160 480 27.72
160 640 26.98
160 800 26.72
160 960 26.38
320 0 27.30
320 160 26.95
320 320 26.80
320 480 26.85
320 640 26.52
320 800 26.11
320 960 25.95
480 0 25.94
480 160 25.86
480 320 25.84
480 480 26.35
480 640 25.61
480 800 25.13
480 960 24.37
544 0 25.67
544 160 25.49
544 320 25.50
544 480 25.60
544 640 25.27
544 800 25.63
544 960 24.01
And 3data2.dat
0 0 17.67
0 160 17.67
0 320 17.67
0 480 17.67
0 640 17.67
0 800 17.67
0 960 17.67
160 0 17.67
160 160 17.67
160 320 17.67
160 480 17.67
160 640 17.67
160 800 17.67
160 960 17.67
320 0 17.67
320 160 17.67
320 320 17.67
320 480 17.67
320 640 17.67
320 800 17.67
320 960 17.67
480 0 17.67
480 160 17.67
480 320 17.67
480 480 17.67
480 640 17.67
480 800 17.67
480 960 17.67
544 0 17.67
544 160 17.67
544 320 17.67
544 480 17.67
544 640 17.67
544 800 17.67
544 960 17.67
One can execute the script using the command below,
gnuplot> call “./3d.pg” “./3data.dat” “./3data2.dat” “3test.png”
And the plotted figure will be as below,
Figure 1. a 3-D Plot using gnuplot
References:
1. gnuplot In Action
Leave a Reply Cancel reply
40% Discount on My Book — Android NDK Cookbook
Android NDK Cookbook ebook 40% discount with promotion code MREANC40 at Packt Publishing The promotion code is valid until 15th June.Categories
- Android Apps (18)
- Android Audio Editor (1)
- TS 2 (3)
- Video Converter Android (8)
- Video2Gif (1)
- Android Tutorial (27)
- Android Dev Tools (1)
- API illustrated (8)
- Multimedia API (3)
- ffmpeg on Android (4)
- NDK (6)
- UI (6)
- Animation (2)
- Code Snippet (2)
- Coding Beyond Technique (18)
- a word, a world (4)
- Bug Rectified (4)
- Programming Habit (1)
- Software as a Career (1)
- Software as User Experience (1)
- Compilers and Related (2)
- ELF (2)
- Computer Languages (31)
- C/C++ (13)
- Java (9)
- JavaScript (2)
- PHP (1)
- Python (8)
- Data Structure & Algorithms (29)
- Bits (1)
- Data Structure (5)
- Integers (10)
- BigInteger (1)
- Prime (4)
- Search (3)
- Sorting (5)
- Strings (5)
- Database (1)
- SQLite (1)
- Digital Signal Processing (33)
- Distributed Systems (17)
- Apache Cassandra (6)
- Apache Hadoop (8)
- Apache Avro (3)
- Apache Nutch (3)
- Apache Solr (1)
- Linux Study Notes (40)
- crontab (1)
- Linux Kernel Programming (8)
- Linux Programming (12)
- IPC (2)
- Linux Network Programming (5)
- Linux Signals (2)
- Linux Shell Scripting (1)
- ssh (3)
- Machinery (30)
- misc (1)
- My Ideas (1)
- My Project (3)
- Mobile Caching (1)
- Selective Decoding (2)
- My Publication (1)
- My Readings (1)
- Networking (15)
- Program for Performance (8)
- Uncategorized (1)
- Virtual Machine (2)
- Web Dev (8)
- web components (3)
- Android Apps (18)
Recent Comments
Archives
- May 2013 (2)
- April 2013 (1)
- March 2013 (4)
- December 2012 (2)
- November 2012 (6)
- October 2012 (6)
- September 2012 (3)
- August 2012 (13)
- July 2012 (15)
- June 2012 (3)
- May 2012 (8)
- April 2012 (4)
- March 2012 (13)
- February 2012 (19)
- January 2012 (9)
- December 2011 (11)
- November 2011 (12)
- October 2011 (4)
- September 2011 (12)
- August 2011 (16)
- July 2011 (15)
- June 2011 (6)
- May 2011 (10)
- April 2011 (13)
- March 2011 (20)
- February 2011 (4)
- November 2010 (2)
- May 2010 (1)
- April 2010 (1)
- February 2010 (1)




