Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Samples, isosamples, and how they affect contour lines

147 views
Skip to first unread message

nawr...@gmail.com

unread,
Jul 11, 2018, 3:02:20 AM7/11/18
to
Contour lines generated by gnuplot can look pretty strange (unexpected) if you do not set both `samples` and `isosamples` to appropriate values. I struggled for hours to find out how exactly `set samples` and `set isosamples` affect the appearance of contour lines, however, all I observed is that setting both to sufficiently large values will generate good-looking contours. Still, I want to understand how exactly this works.

1. What is the difference between `set samples` and `set isosamples` in the context of contour lines?
2. How does `set samples` affect the generation of contour lines?
3. How does `set isosamples` affect the generation of contour lines?

For example, consider the following simple case:

unset surface
set contour
set cntrparam levels discrete 10, 20
set samples 250, 2
set isosamples 2, 250
set view map
splot x**2 + y**2

To generate correct contour lines, it appears you need to set the first parameter of `samples` and the second parameter of `isosamples` to sufficiently large values. However, setting the second parameter of `samples` and the first parameter of `isosamples` to the smallest possible value does no harm. This is not exactly intuitive. So how does this work?

I note that I asked this question before on Stack Overflow, but got no answers.

Karl Ratzsch

unread,
Jul 11, 2018, 5:26:42 AM7/11/18
to
Am 11.07.2018 um 09:02 schrieb nawr...@gmail.com:
> Contour lines generated by gnuplot can look pretty strange (unexpected) if you do not set both `samples` and `isosamples` to appropriate values. I struggled for hours to find out how exactly `set samples` and `set isosamples` affect the appearance of contour lines, however, all I observed is that setting both to sufficiently large values will generate good-looking contours.. Still, I want to understand how exactly this works.
>
> 1. What is the difference between `set samples` and `set isosamples` in the context of contour lines?
> 2. How does `set samples` affect the generation of contour lines?
> 3. How does `set isosamples` affect the generation of contour lines?
>
> For example, consider the following simple case:
>
> unset surface
> set contour
> set cntrparam levels discrete 10, 20
> set samples 250, 2
> set isosamples 2, 250
> set view map
> splot x**2 + y**2
>
> To generate correct contour lines, it appears you need to set the first parameter of `samples` and the second parameter of `isosamples` to sufficiently large values. However, setting the second parameter of `samples` and the first parameter of `isosamples` to the smallest possible value does no harm.. This is not exactly intuitive. So how does this work?
>
> I note that I asked this question before on Stack Overflow, but got no answers.
>

I think you are confused between the generation of xy values and the
contour generation.

You should generate a dataset with a fixed sampling, and then look how
"set sample" influences the look of contours.

set samp 40
set isos 40
set table $dat
splot x**2+y**2
unset table
set view map
splot $dat title "an evenly spaced grid of datapoints"
reset

Now if you try to plot contours on this dataset, you will find that the
sampling settings just have no influence on the contour appearance. The
contour points are generated from the grid.

hth,

Karl

nawr...@gmail.com

unread,
Jul 12, 2018, 1:39:17 AM7/12/18
to
I'm sorry, I still have no idea what's going on here. Consider the following example:

set samples 6
set isosamples 500
set table $surface
splot x ** 2 + y ** 2
unset table
set contour
set cntrparam levels discrete 80
set view map
splot $surface

1. Why is there a smooth curve in the interval [-10, -6]?
2. Why is there a straight line in the interval [-6, -2]?
3. Why are there no points at all in the interval [-2, 2]?

Karl Ratzsch

unread,
Jul 12, 2018, 2:08:46 AM7/12/18
to
gnuplot takes the grid values in x-direction, and adds an interpolated
contour point wherever the connection between these two points crosses
the y-grid. (afterwards it does the same in the other direction, and
sorts the interpolated points into a closed contour line)

The 2 lines between -2 and 2 are horizontal, so they don't cross the
y-grid at all.

I mean, you cannot expect a nice-looking contour on a data grid that
only has six values in one direction, right? You need a grid with
similar density in BOTH directions.

nawr...@gmail.com

unread,
Jul 12, 2018, 2:50:52 AM7/12/18
to
By y-grid you mean the plane z = 80?

Karl Ratzsch

unread,
Jul 12, 2018, 11:18:24 AM7/12/18
to
Am 12.07.2018 um 08:50 schrieb nawr...@gmail.com:
> By y-grid you mean the plane z = 80?
>
no, the sampling distance between points in direction y.

set sample 6
set isosample 500

gives a grid with 6 points in direction x, times 500 in direction y.
That's the grid you see with

set view map
splot $surface

How should the contour routine know what the z values at x=0 are when
there is nothing to interpolate between?

Actually your contour is terrible between [-10:-6] and [6:10] too. It
looks nice and round, but is a very sketchy interpolation, much worse
even in [-6:-2] and [2:6]

reset
set samp 100
set isos 100
set table $surf200 # this is a well-gridded plot
splot x**2+y**2

set samp 6
set isos 500
set table $surface # this isn't
rep
unset table

set view map
set cntrparam levels discrete 20, 40, 60, 80
set contour
unset surface # comment out to see the grid
splot $surf200 w l title "200x200 grid", \
$surface w p ps .5 pt 1 title "6x500 grid"

nawr...@gmail.com

unread,
Jul 13, 2018, 3:22:54 AM7/13/18
to
Can we go through a simple example? Consider once again the following case:

set samples 6
set isosamples 21
set table $surface
splot x ** 2 + y ** 2
unset table
set contour
set cntrparam levels discrete 80
set view map
splot $surface

Now, you wrote:

> gnuplot takes the grid values in x-direction, and adds an interpolated
> contour point wherever the connection between these two points crosses
> the y-grid.

If I understand correctly, we consider two grid points consecutive in x-direction, for example (-6, -8) and (-2, -8). Now, we add a contour point between them, according to the plot at (-3.5, -8). Why exactly at (-3.5, -8)? What do you mean by crossing the y-grid?

Karl Ratzsch

unread,
Jul 13, 2018, 3:53:04 AM7/13/18
to
Am 11.07.2018 um 09:02 schrieb nawr...@gmail.com:

> set samples 250, 2
> set isosamples 2, 250
> set view map
> splot x**2 + y**2

> To generate correct contour lines, it appears you need to set the first parameter of `samples` and the second parameter of `isosamples` to sufficiently large values. However, setting the second parameter of `samples` and the first parameter of `isosamples` to the smallest possible value does no harm.. This is not exactly intuitive. So how does this work?

Has nothing to do with contours.

"set sample x, y" specifies how many points are generated on each
isoline in the respective direction.

"set isosamp x, y" specifies the number of isolines.

set sample 100,40
set isos 10,4
set view map; splot 1 w p

makes four isolines with 100 points in direction x,
and 10 isolines with 40 points each in direction y.

To not get isolines, but just an even grid, you give the same parameters
to set sample and isosample

set sample 50,20
set isosample 50,20

Actually you can always set one of the isosample parameters to "2", to
get an even grid, you only need the isolines in one direction. And you
can set the sample number in the other direction to "2" also, because
the needed points are already generated by the isolines in the first
direction.

set sample 50,2 # this also makes an even 50:20 matrix
set isosample 2,20




Karl Ratzsch

unread,
Jul 13, 2018, 6:39:53 AM7/13/18
to
That is where a line parallel to the x-axis at y=-8 and z=80 goes
through that the badly sampled surface of z = x^2 + y2. At least that is
how I understand the contour generation algorithm.



0 new messages