0

I have a quadtree like structure in my code, which I want to visualise in gnuplot. This means I want to see the rectangular subdivisions. The reason why I would like to have this in gnuplot is because I want to plot a 2d function over this outline to show correlations between the amount of subdivisions and the function value.

Does ayone have an idea on how to do this?

Ben Ruijl
  • 4,973
  • 3
  • 31
  • 44
  • I assume you want something like the background in this? http://bumpslide.com/blog/2009/01/12/quadtree-visualization/ -- In other words, something that looks like the grid of an Adaptive Mesh Refinement simulation? How is your datafile organized? – mgilson Jun 26 '12 at 11:46

1 Answers1

1

There are two solutions that I can think of -- but they both involve a decent amount of work on your part. You basically need to put each line into a text file. There are two ways to do it -- The first way you put each line-segement on a line in the datafile and plot with arrows:

#datafile -- Each row represents a line.
x11 y11 x12 y12
x21 y21 x22 y22
...

Then you plot it with:

set style arrow 1 nohead
plot 'datafile' u 1:2:($3-$1):($4-$2) w vec

The second way you put each point by itself, seperating groups of points by a blank:

#datafile -- each row represents a point
x11 y11
x12 y12

x21 y21
x22 y22

...

Then you plot this one with:

plot 'datafile' u 1:2 w l

Beating your data into this form shouldn't be too difficult -- Just traverse each branch until you reach a leaf and write out the 4 lines associated with that leaf. Some of the lines (or portions thereof) will be duplicated, but that probably won't be too much of an issue...

EDIT

I didn't realize you need to plot a 2d function on top. In this case, we're going to need to use splot to plot the data:

set term push  #save terminal info
set term unknown
set contour
set cntrparam ... #whatever you need to make your contours appear the way you want
set table "junk_temporary_file.dat"
splot f(x,y)  #whatever function you choose goes here.
unset table
unset contour

set term pop  #restore terminal info
set view map
splot 'datafile'                u 1:2:(0.0) w l,\
      'junk_temporary_file.dat' u 1:2:3     w l #optional line specs here.

If you want colors, it's a little (lot) easier:

set view map
splot f(x,y) w pm3d,\
      'datafile' u 1:2:(0.0) w l
mgilson
  • 300,191
  • 65
  • 633
  • 696
  • I've implemented your second suggestion and it's working! Do you also know a way to render a 2d function on top of these rectangles, as if they are the contour of the function? – Ben Ruijl Jun 26 '12 at 17:48
  • @BenRuijl -- Do you mean a 3d plot (as in x,y,value)? Do you want contours (lines) or colors? – mgilson Jun 26 '12 at 17:54
  • I meant a 3d function indeed, so R^2 -> R. I want the function in wireframe, so the quadtree below is visible. Sorry if I was unclear! – Ben Ruijl Jun 26 '12 at 18:00
  • @BenRuijl -- Let me know if my edit works (or doesn't work) for you. – mgilson Jun 26 '12 at 18:01