1

I'm trying to create something similar to these plots:

Goal plots depicting a joint pdf of two multivariate gaussian distributions and a bayesian decision boundary between them.

I have the surface plot and what I would like to put under it being plotted separately for now:

Surface plot depicting the joint pdf 2D Scatter plot

I've tried plotting the 2D image as a binary plot in the surface plot, but each pixel is interpreted as a whole unit in the coordinate system, which is incorrect, and it ends up duplicating the coordinate axes and plot title, etc. As well, gnuplot's xyplane isn't necessarily at z=0, so just plotting using splot normally with a z value of 0 also doesn't do what I want.

These are my plotting files so far:

2D Scatterplot:

set terminal png enhanced size 8000, 4800 truecolor font "arial,60"
set encoding utf8
set output outfile

set autoscale fix

set border lw 3
set style fill transparent solid 0.075 noborder
set style circle radius 0.03

set title plotTitle

plot sample1 u 1:2 w circles notitle,\
     sample2 u 1:2 w circles notitle,\
     $ContourTable w lines lw 6 lc rgb 'black' notitle,\
     keyentry w circles fill solid 1.0 noborder lc 1 title "ω_1",\
     keyentry w circles fill solid 1.0 noborder lc 2 title "ω_2"

Surface Plot:

set terminal png enhanced size 8000, 4800 truecolor font "arial,60"
set encoding utf8
set output outfile

set autoscale fix
set border lw 3
set title plotTitle
set isosamples 100
set pm3d at s explicit hidden3d
unset hidden3d
set palette model RGB define (1 "dark-violet", 2 "#009e73")

splot pdfFile u 1:2:3:4 w pm3d lc rgb "black"
2
  • I'm confused. Where do you get the surface data from, i.e. what is the pdfFile? How does this data look like? Is this a density plot of the 2D scatter data? Can you give an example? Commented Mar 6, 2021 at 19:37
  • @theozh Yeah sure. The surface plot is a plot of the joint density that the samples in the scatter plot were pulled from - I'm generating both from a C++ program. The surface is colored based on which class's marginal density is larger at that point. This is what an example pdfFile looks like: pastebin.com/XMhBLeW5. Commented Mar 6, 2021 at 19:50

2 Answers 2

1

Maybe something like this? Maybe needs to be adapted to your data and further fine tuned.

Code:

### surface plot with contour
reset session

GaussW3D(x,y,x0,y0,A,FWHM) = A * exp(-(x-x0)**2/(2*(FWHM/(2*sqrt(2*log(2))))**2)) *\
                                 exp(-(y-y0)**2/(2*(FWHM/(2*sqrt(2*log(2))))**2))
                                 
set samples 40
set isosamples 40

f(x,y) = GaussW3D(x,y,4,4,1,5) + GaussW3D(x,y,0,0,1.5,3)
set contour base
set cntrparam levels 10
set hidden3d
set xyplane at -2
set ztics 0.5

splot sample [-4:10][-7:10] '++' u 1:2:(f(x,y)) w l

### end of code

Result:

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

I know I can plot contours on the xyplane, but I'd like to know if I can plot arbitrary 2d plots, like scatter plots. In the original plots, the line graphs aren't contours - they are ellipses showing the principal axes of a distribution and a decision boundary found via an external program.
@OttovonBisquick ok, then how does the data look like for these ellipses? Please give some example data. Maybe simple x,y values in two columns? Then, as Ethan showed, simply add a fixed z-coordinate in parentheses, e.g. splot 'YourFile' u 1:2:(YourZLevel) w l ... .
0

Although the base plane chosen automatically by gnuplot may be non-obvious, it is quite possible to set it wherever you like using the command set xyplane at <z-value>. Here is an example adapted from the on-line demo set (3rd plot in random.dem)

Not all plot styles used by 2D plots are also supported in 3D, but many of them are.

#
# The surface plot shows a two variable multivariate probability"
# density function.  On the x-y plane are some samples of the random"
# vector and a contour plot illustrating the correlation, which in"
# this case is zero, i.e. a circle.  (Easier to view in map mode.)"
#
nsamp = 50

# Generate N random data points.
set print $random
do for [i=1:nsamp] {
    print sprintf("%8.5g %8.5g", invnorm(rand(0)), invnorm(rand(0)))
}
unset print
#
unset xlabel
unset ylabel
unset zlabel
set parametric
tstring(n) = sprintf("%d random samples from a 2D Gaussian PDF with\nunit variance, zero mean and no dependence", n)
set title tstring(nsamp)
unset key
set hidden3d
set contour
set view 68, 28, 1, 1
set cntrparam levels discrete 0.1
unset clabel
set xrange [-3:3]
set yrange [-3:3]
set zrange [-0.2:0.2]
set ztics 0,0.05
set urange [-3:3]
set vrange [-3:3]
set isosamples 30

BASE = -0.2
set xyplane at BASE
splot u,v,( 1/(2*pi) * exp(-0.5 * (u**2 + v**2)) ) with line lc rgb "black", \
   $random using 1:2:(BASE) with points pointtype 7 lc rgb "slategray" nocontour

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.