Home > Back-end >  How to contour 2d plot in gnuplot, move from MATLAB
How to contour 2d plot in gnuplot, move from MATLAB

Time:12-01

I am porting some scripts from MATLAB to C and using GNUPLOT for plotting, in MATLAB I use the following command to plot:

contourf(nU, 200,'linecolor','non');

nU contains the matrix to plot, I already have the C code that gets the data and puts them in the same matrix format, from GNUPLOT documentation, splot uses the following format, so I also have the code to pass the data to a file 'data.txt' with the following format:

# x, y, z

0.000000 0.000000 0.000000 
0.094248 0.000000 0.000000 
0.188496 0.000000 0.000000 
0.282743 0.000000 0.000000 

I tried

splot 'data.txt'

and it seems like its plotting the data correctly, but is plotting like so:

enter image description here

However I need a 2d filled contour plot, this is the output from MATLAB:

enter image description here

Once plotted, what commands can I use to modify the GNUPLOT output?

CodePudding user response:

The figure you show is what I would call a heat map rather than a contour plot. Gnuplot can do either.

To get a heat map, something like this:

set view map                 # 2D projection of 3D surface
splot 'data.txt' with pm3d   #

There are choices to be made in creating a contour map. How many contours? All the same? Colors? If you get that far and need more help, ask again. For now I show a minimal command that uses all default values:

set view map
set contour
splot 'data.txt' with lines nosurface
  • Related