Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Jun 16th, 2010 | Syntax: Ruby | Size: 2.74 KB | Hits: 51 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. #! /usr/bin/ruby
  2.  
  3. # This script generates a plot with differnet point types, available in gnuplot.
  4. # Default terminal is "postscript eps enhanced color"
  5.  
  6. # Copyright 2010 Alexey Nikolaev <http://5th.org.ru>.
  7. #
  8. # This script is free software; you can redistribute it and/or
  9. # modify it under the terms of the Simplified BSD License, see below the code
  10. # for the full license text.
  11.  
  12. # Number of Columns
  13. i_max = 8
  14. # Number of Rows
  15. j_max = 8
  16.  
  17. # ===========================================
  18.  
  19. require 'tempfile'
  20.  
  21. f_temp = Tempfile.new "gnuplot_points"
  22.  
  23. printf f_temp, "set terminal postscript eps enhanced color solid lw 1.0 size #{1.2*i_max+0.3}cm, #{1.2*j_max+0.5}cm # width, height
  24.  
  25. set output \"gnuplot_points.eps\"
  26.  
  27. set lmargin 2.0
  28. set rmargin 2.5
  29. set bmargin 2.5
  30. set tmargin 3.5
  31. show margin
  32.  
  33. set title \"Gnuplot Point Types\" font \"Helvetica,20\"
  34.  
  35. set xrange [-0.5:#{i_max-0.5}]
  36. set yrange [-0.5:#{j_max-0.5}]
  37. set notics  
  38. set noborder
  39. set style line 1 ps 0 lc rgb \"#703010\" lw 0.0
  40. plot "
  41.  
  42. (0...j_max).each{|j|
  43.         (0...i_max).each{|i|
  44.                 printf f_temp,
  45.                 "\"< echo \'#{i}\t#{j}\'\" u 1:2 w points ps 4 pt #{i+j*i_max} lc rgb \"#F06010\" lw 3.0 notitle, \\
  46. \"< echo \'#{i}\t#{j}\t#{i+j*i_max}\'\" u 1:2:3 w labels offset 2.0,-1.9 tc ls 1 font \"Helvetica,18\" notitle"
  47.                
  48.                 if (j!=j_max-1 || i!=i_max-1) then printf f_temp, ", \\\n" end
  49.         }
  50. }
  51.  
  52. f_temp.flush
  53. f_temp.close
  54.  
  55. %x[gnuplot #{f_temp.path}]
  56.  
  57.  
  58. #Copyright 2010 Alexey Nikolaev <http://5th.org.ru>. All rights reserved.
  59. #
  60. #Redistribution and use in source and binary forms, with or without modification, are
  61. #permitted provided that the following conditions are met:
  62. #
  63. #   1. Redistributions of source code must retain the above copyright notice, this list of
  64. #      conditions and the following disclaimer.
  65. #
  66. #   2. Redistributions in binary form must reproduce the above copyright notice, this list
  67. #      of conditions and the following disclaimer in the documentation and/or other materials
  68. #      provided with the distribution.
  69. #
  70. #THIS SOFTWARE IS PROVIDED BY Alexey Nikolaev ``AS IS'' AND ANY EXPRESS OR IMPLIED
  71. #WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  72. #FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Alexey Nikolaev OR
  73. #CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  74. #CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  75. #SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  76. #ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  77. #NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  78. #ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.