Menu

contour

Help
2024-11-18
2024-11-22
  • Jesper Olsen

    Jesper Olsen - 2024-11-18

    Matlab/octave can do contour plots - for a classification problem (2D) it can be used to draw the decision boundary between two classes.

    With gnuplot I have resorted to calculating a fine grid and plotting the points - with a colour that indicates the class that point is classified as. Is there a "smoother" way of doing this?

     
  • Hiroki Motoyoshi

    If you can use gnuplot version 6.0.0 or later, you might want to consider using the ‘zclip’ option for the 'splot' command. Alternatively, you could also use ‘with contourfill’, which was also introduced in version 6.0.0.

    Note: The ‘zclip’ option is marked as ‘Experimental’ in the gnuplot documentation.

    Here is an example using the 'zclip' option for splot command.

    set term qt
    
    f(x,y) = x**2+(x/2.0+y)**2
    threshold = 0.6
    
    set view map      # for 2D plot
    set isotropic        # aspect ratio  
    set xrange [-1:1]
    set yrange [-1:1]
    set samples 50
    set isosamples 50
    set contour surface
    set cntrparam levels incremental 0,0.2,5
    set cntrlabel onecolor
    unset key
    unset colorbox
    
    splot f(x,y) w pm3d zclip [0:threshold] fs solid 0.5 border fc "red" lc "black", \
          f(x,y) nosurface lt black
    
    pause mouse
    
    set cntrparam levels discrete threshold
    
    splot f(x,y) w pm3d zclip [0:threshold] fs solid 0.5 border fc "red" lc "black", \
          f(x,y) nosurface lt black
    
    pause mouse
    

    The following gnuplot demo is a good reference for seeing what you can do with ‘with contourfill’.
    https://gnuplot.sourceforge.net/demo_6.0/contourfill.html

    I hope this will be helpful to you.

     
    • Jesper Olsen

      Jesper Olsen - 2024-11-21

      Thanks for the pointer. I'm using v. 6 - but via the rust gnuplot crate rather than the script interface. It is convenient because the function can not be written in simple analytical form like in the example.

      But seems splot can take a datafile as input, so I guess I could use that.

       
      • Hiroki Motoyoshi

        If the input data for the 'splot' command is gridded data, there is not much difference from the case of plotting a function.

        If the grid data is sparse, you can use the ‘interpolation’ option for ‘set pm3d’ to make it smoother.

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.