guicho271828 / eazy-gnuplot

Super Duper Doopa Booka Lispy Gnuplot library
http://guicho271828.github.io/eazy-gnuplot/
63 stars 8 forks source link

function fitting #5

Closed guicho271828 closed 8 years ago

guicho271828 commented 8 years ago

the cookbook currently says it is not possible, but I managed to use the following code; possibly made into a function in the future.

(defun main (title key-flag width height out keys &rest argv)
  (declare (ignorable argv))
  (with-plots (s :debug t)
    (gp-setup :terminal `(:pdf :enhanced
                               :monochrome :dashed 
                               :size
                               ,(make-symbol (format nil "~a,~a" width height))
                          :font "Times New Roman, 12")
              :size :square
              :output out
              :logscale :xy
              :title title
              :title `(offset |0,-0.7|)
              :format '(:xy "10^{%L}")
              :xtics '|-2, 100, 100000000|
              :ytics '|-2, 100, 100000000|
              :xrange '|[0.01:100000]|
              :yrange '|[0.01:100000]|
              :xlabel "without Macro"
              :ylabel "with Macro (L=2)"
              :xlabel '(offset |0,0.5|)
              :ylabel '(offset |1.2,0|)
              :xtics '(offset |0,0.3|)
              :ytics '(offset |0.6,0|)
              :key (read-from-string key-flag))
    (iter (for (h1 . h2) in (plist-alist (mapcar #'read-into-table argv)))
          (for key in (read-from-string keys))
          (for var in '(a b c))
          (format s "~&~a(x) = ~a*x" key var)
          (format s "~&fit [] [10:1000] ~a(x) '-' using 1:2 via ~a~%" key var)
          (iter (for (key time1) in-hashtable h1)
                (for time2 = (gethash key h2))
                (when (and time1 time2)
                  (format s "~&~a ~a" time2 time1)))
          (format s "~&end~&"))
    (func-plot "x" :notitle nil)
    (iter (for key in (read-from-string keys))
          (for i downfrom 2)
          (func-plot (format nil "~a(x)" key)
                     :notitle nil
                     ;; :with :lines :lt i :lw i
                     ))
    (iter (for (h1 . h2) in (plist-alist (mapcar #'read-into-table argv)))
          (for key in (read-from-string keys))
          (for type from 0)
          (plot (lambda ()
                  (iter (for (key time1) in-hashtable h1)
                        (for time2 = (gethash key h2))
                        (when (and time1 time2)
                          (format s "~&~a ~a" time2 time1))))
                :title (princ-to-string key)
                :with :points :ps 0.3 :lw 0.7 :pt type :lt type))))
guicho271828 commented 8 years ago

result: screenshot from 2016-02-01 19 35 34

mmaul commented 8 years ago

Nice, I'll dump the generated gluplot and see what I need to fix in the cookbook. Can you post your data to a gist?

guicho271828 commented 8 years ago

https://gist.github.com/guicho271828/129d487e2bffa1b1ca47

guicho271828 commented 8 years ago

I am like in the midst of final run toward a research conference paper, so feel free to include "fit" function!

guicho271828 commented 8 years ago

Implemented in #31 , which contains lot of refactoring at the same time.