问题
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.
- What is the difference between
set samples
andset isosamples
in the context of contour lines? - How does
set samples
affect the generation of contour lines? - 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?
回答1:
First, a discussion on what samples
and isosamples
where designed to do. This is best when viewing the actual plot and not the contour map.
samples
is used to set the number of function evaluations along an axis in the range being plotted. For splot
(3-D images), you can control samples in both independent directions x and y. Here is a sample where the x-direction only has 4 evaluations and the y-direction has 200:
reset
set xrange [-10:10]
set yrange [-10:10]
set xlabel 'X'
set ylabel 'Y'
set samples 4,200
splot x**2+y**2
In the following 2 images note that along the x-direction, the function is only evaluated 4 times and straight lines are drawn between them. Along the y-direction, it is evaluated 200 times and it looks like 'smooth' curves. Note that in both directions, exactly 10 lines are drawn. I will get to that below while discussing isolines.
Looking toward x-axis:
Looking toward y-axis:
So, 10 lines in each axis direction are drawn because the default value for isolines in both x and y directions is 10. We can change this at will. Lets increase samples in both directions for a nice smooth curves but demonstrate isosamples.
reset
set xrange [-10:10]
set yrange [-10:10]
set xlabel 'X'
set ylabel 'Y'
set samples 200,200
set isosamples 4,12
splot x**2+y**2
Note the nice smooth curves in both directions. Along the x-axis, there are only 4 points where, along the y-axis, the surface curves are drawn and along the y-axis, there are 12 points where surface curves are drawn parallel to the x-axis.
The above examples demonstrate the primary purpose of set samples
and set isosamples
. They only indirectly affect contours. In your case, you are only interested in the contour map without even displaying the surface plot. A clue as to how gnuplot plots contours is in its explanation of how contours can be drawn with discreet data.
Gromacs:
In order to draw contours, the data should be organized as "grid data". In such a file all the points for a single y-isoline are listed, then all the points for the next y-isoline, and so on. A single blank line (a line containing no characters other than blank spaces and a carriage return and/or a line feed) separates one y-isoline from the next.
From this explanation, gnuplot seems to prefer to pick an x value and draw a y-isoline. We can deduce then that when gnuplot draws contours from functions, that it picks x values and draws y-isolines. Therefore having many x samples and many y isolines draws hi resolution contours while the y samples and the x isolines are irrelevant (if you are not drawing the surface).
来源:https://stackoverflow.com/questions/51237482/samples-isosamples-and-how-they-affect-contour-lines