Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gnuplot: 4d color plot using matrix format

I know that for a 4d color plot (3d surface, and the color is given by a 4th field), I can use a datafile of the format

# X Y Z C
  1 1 0 4
  1 2 1 3

  2 1 4 2
  2 2 4 5
  ...

and then use

set pm3d
splot "datafile.dat" u 1:2:3:4 with pm3d

On the other hand, I know how to make a simple surface plot where the X and Y values are implicit while the Z value is in matrix format:

#Z DATA ONLY
0 1
4 4

splot "datafile.dat" matrix 

Is there a way to make 4d color plots using this matrix format? For example, taking the Z data from one file and the corresponding color data from another file, or combining both the Z value and the color into a single file in matrix format?

like image 561
Lagerbaer Avatar asked Jun 29 '11 16:06

Lagerbaer


1 Answers

If I'm understanding the question correctly, this does appear possible. See the examples below.

  1. http://www.gnuplotting.org/tag/matrix/

    All we need to create such a plot is the image plot style, and of course the data have to be in a proper format. Suppose the following matrix which represents z-values of a measurement.

    0 1 2 3 4 3 2 1 0
    0 1 2 3 4 3 2 1 0
    0 1 2 3 4 3 2 1 0
    0 1 2 3 4 3 2 1 0
    0 1 2 3 4 3 2 1 0
    0 1 2 3 4 3 2 1 0
    0 1 2 3 4 3 2 1 0
    0 1 2 3 4 3 2 1 0
    0 1 2 3 4 3 2 1 0
    

    In order to plot these values in different gray color tones, we specify the corresponding palette. In addition we apply the above mentioned image plot style and the matrix format option. The result is shown in Fig. 2.

    set palette grey
    plot 'color_map.dat' matrix with image
    

    z values with color

  2. http://gnuplot.sourceforge.net/demo/heatmaps.html

    #
    # Two ways of generating a 2D heat map from ascii data
    #
    
    set title "Heat Map generated from a file containing Z values only"
    unset key
    set tic scale 0
    
    # Color runs from white to green
    set palette rgbformula -7,2,-7
    set cbrange [0:5]
    set cblabel "Score"
    unset cbtics
    
    set xrange [-0.5:4.5]
    set yrange [-0.5:4.5]
    
    set view map
    splot '-' matrix with image
    5 4 3 1 0
    2 2 0 0 1
    0 0 0 1 0
    0 0 0 2 3
    0 1 2 4 3
    e
    e
    

    Heat map generated from a file only containing z values

like image 131
JSuar Avatar answered Sep 29 '22 01:09

JSuar