Search code examples
plotgnuplot

Using gnuplot to plot points with color and x-marks


I have been trying this for a few hours but I am not getting anywhere. What I am trying to do is this:

I have a solution from a simulation with x and y values and a value for each point.

I am trying to plot the data using gnuplot. I want the values in between my data points to be interpolated using color and the points themself shall be marked with a dot, a "x" or sth. like that similar to this (except for the round border and those labels inside):

enter image description here

I have been trying to get a very basic example going. My data file looks like this:

1   1   0.1
1   2   0.3
1   3   0.6
2   1   0.5
2   2   0.7
2   3   0.9
3   1   0.2
3   2   0.8
3   3   0.7

and my gnuplot input like this:



set terminal postscript eps enhanced color font 'Helvetica,10'
set output './production/image1.eps'

set palette gray

set title "Titel" 

#set xrange [1:4]
#set yrange [0:10]

set format y "%.1f"
set format x "%.1f"

set xlabel "x-Achse [Einheit]" 
set ylabel "y-Achse [Einheit]" rotate by 90


set view map
set pm3d at b map
set pm3d interpolate 2,2
set dgrid3d 50,50,2
splot "inputDatei.dat" u 1:2:3 linecolor palette

The result looks like this:

enter image description here

There are a few issues with this which i cannot resolve:

  1. there is a label in the rip right "inputDatai.dat" u 1:2:3". I tried splot ... label "" but this didnt solve the issue
  2. the interpolation doesnt seem to work. this is visible with a smaller grid
  3. the data points are not highlighted. I tried using splot ... with points but this would only display points at EVERY grid corner which is obviously way too much. Also the input data might not be "regular" but points can be anywhere.

I am very happy if someone could help me with this.

Greetings, Finn


Solution

  • To your questions:

    1. use unset key before the plot command or splot ... notitle within the plot command
    2. what "does not work" mean? Please explain.
    3. I guess that's similar to here (Superimposing vectors, dgrid3d and pm3d in gnuplot for 3D plot). You have to switch off interpolating for the highlighted points. I'm not sure whether this can be done within a plot command, so you have to plot the interpolated data into a separate datablock via set table and then switch off interpolation.

    Code:

    ### interpolate data with highlighted datapoints
    reset session
    
    $Data <<EOD
    1   1   0.1
    1   2   0.3
    1   3   0.6
    2   1   0.5
    2   2   0.7
    2   3   0.9
    2.5 2.5 0.1
    3   1   0.2
    3   2   0.8
    3   3   0.7
    EOD
    
    set size square
    set view map
    set pm3d at b
    set pm3d interpolate 2,2
    set dgrid3d 50,50,2
    
    set table $DataInterpolated
        splot $Data u 1:2:3 
    unset table
    unset dgrid3d
    
    set palette grey
    set xrange [0.9:3.1]
    set yrange [0.9:3.1]
    
    splot $DataInterpolated u 1:2:3 w pm3d palette notitle, \
          $Data u 1:2:3 w p pt 1 lw 2 lc rgb "red" notitle
    ### end of code
    

    Result:

    enter image description here