Showing posts with label contour plot. Show all posts
Showing posts with label contour plot. Show all posts

Saturday, September 24, 2011

Implicit function plotting using gnuplot

Assume three is an equation f(x,y)=g(x,y), and we want to plot the roots which obey this equation. This is a typical implicit function plotting problem. How do we handle this problem using gnuplot?

The most simple idea is solving the equation analytically (or numerically), and get the the root y=h(x) (or a data file containing the roots). Then plot h(x) (or the data file) with gnuplot. Of course, it is OK. But here we provide a more simpler method.

Note that the contour line at level 0 for function z=f(x,y)-g(x,y) is just the lines made up by the points which obey equation f(x,y)=g(x,y). So we can convert implicit function plotting problem to a contour plotting problem. Now come to a example.
reset
set term png enhanced lw 2 font "Times,18"
set output "implicit.png"
set contour
set cntrparam levels discrete 0
set view map
unset surface
set nokey
set isosamples 1000,1000
set xrange [-2:2]
set yrange [-2:2]
set xlabel "x"
set ylabel "y"
set title "Implicit plot of sin(x^2+y^2)=exp(-xy)"
splot sin(x**2+y**2)-exp(-x*y)
Picture implicit.png is as follows.

Implicit Plot Using Gnuplot
Creative Commons License
Except as otherwise noted, the content of this page is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.