Gnuplot: How to plot a 2d colorplot of a 3d function

In summary, the author attempted to plot data points where my_f produced an "ignore" value, but was unsuccessful.
  • #1
DerBaer
4
0
Hello,

I have a data file created by an C++ Programm which creates the lines of the data file by an operation inside an loop
Code:
data3dRnd << gsl_vector_get(x,0) << '    ' << gsl_vector_get(x,1) << '    ' << my_f(x,par) << endl << endl;

where the entries of the gsl_vector x are doubles and my_f(x,par) is a double depending on x.

I would like to produce a colour plot with x1 and x2 on the axes and show my_f(x,par) via the color of plot. There are some points x where my_f(x,par) produces an Ignore value (1e+300 in this case) and I don't want data points to be plotted which lead to my_f = Ignore value.
In a 2D plot of my_f over sqrt(x1^2+x2^2) I achieve this with
Code:
 using 1:($2 < 1e+300 ? $2 : 1/0)
How can I achieve this? At first there was only one << endl in my code, but that gave me the error that i need more then one Isoline. So I entered the second << endl as the Isolines are sperated by a blank line.

My current Gnuplot Scrit is

Code:
set terminal eps enhancedset output "VEffCont.eps"
set view map
set isosamples 100, 100
unset surface
set style data pm3d
set style function pm3d
set ticslevel 0
set title "Random v1 - v2 - Distribution"
set xlabel "v1 [GeV]"
set ylabel "v2 [GeV]"
set pm3d implicit at b
set palette cubehelix
splot "./3dRnd.dat" u 1:2:3 w pm3d

This produces a grid with the correct ranges of x and y axes and a colour scale for my_f but with nothing in the plot window as shown in the attached pdf.

Thanks in advance.
 

Attachments

  • VEffCont.pdf
    12.5 KB · Views: 495
Technology news on Phys.org
  • #2
These commands:set pm3d explicit at b
set pm3d scansautomatic
set pm3d interpolate 1,1 flush begin noftriangles nohidden3d corners2color mean
set palette positive nops_allcF maxcolors 0 gamma 1.5 color model RGB
set palette rgbformulae 7, 5, 15
set colorbox default
set colorbox vertical origin screen 0.9, 0.2, 0 size screen 0.05, 0.6, 0 front bdefault
set loadpath
set fontpath
set fit noerrorvariables
GNUTERM = "wxt"
set title "29aprd1 Spectrogram"
se zra [-5:5]
splot "29aprd1.tfm" using ($3+ 0.01):1:(log10($2))
set out "29aprd1tfm.png"
set term png transparent truecolor enhanced
rep
set out
set term wxt
# EOFProduced the output in Figure 3 here: http://www.btgresearch.org/AcousticReconstruction02042012.pdf
 
  • #3
Thanks Dr. Courtney,

A Member on the Gnuplot Google Help Group suggested this

set dgrid3d # create a regularized grid from your "data"
set view map # 2D projection
splot dataf us 1:2:($3<1e299?$3:NaN) w pm3d # z-coloured

and this worked quite fine for my dataset.
 

1. How can I plot a 2d colorplot of a 3d function using Gnuplot?

To plot a 2d colorplot of a 3d function using Gnuplot, you will need to use the splot command. This command allows you to create a three-dimensional plot from a set of data points. However, to generate a colorplot, you will also need to specify the with pm3d option after the splot command. This will enable the color mapping feature in Gnuplot and create a colorplot of your 3d function.

2. How do I specify the color scheme for my 2d colorplot in Gnuplot?

By default, Gnuplot will use a default color palette for your 2d colorplot. However, if you want to customize the color scheme, you can use the palette command. This command allows you to specify a specific palette or color map for your colorplot. You can also use the set pm3d map command to enable the use of the color map for your plot.

3. Can I add a color scale or legend to my 2d colorplot in Gnuplot?

Yes, you can add a color scale or legend to your 2d colorplot in Gnuplot by using the set colorbox command. This command will add a color scale on the side of your plot, which will help you interpret the colors used in your plot. You can also customize the color scale by specifying the set colorbox options such as label, range, and position.

4. How do I save my 2d colorplot as an image file in Gnuplot?

To save your 2d colorplot as an image file in Gnuplot, you can use the set term and set output commands. First, you will need to specify the type of image format you want to save your plot as, such as set term png or set term jpeg. Then, you can use the set output command to specify the file name and location for your image file. Finally, use the replot command to generate and save your 2d colorplot as an image file.

5. Is it possible to plot a 2d colorplot of a 3d function from a data file in Gnuplot?

Yes, it is possible to plot a 2d colorplot of a 3d function from a data file in Gnuplot. You will need to use the splot command, followed by the with pm3d option, and specify the data file name and columns for the x, y, and z values. Additionally, you can also use the set datafile separator command to specify the delimiter used in your data file.

Similar threads

  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
4
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
Replies
5
Views
12K
  • Programming and Computer Science
Replies
5
Views
10K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
2K
  • Programming and Computer Science
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
5K
Back
Top