diff --git a/lisp/org-plot.el b/lisp/org-plot.el index a23195d2a..87a415137 100644 --- a/lisp/org-plot.el +++ b/lisp/org-plot.el @@ -179,6 +179,28 @@ and dependent variables." (setf back-edge "") (setf front-edge "")))) row-vals)) +(defun org-plot/zip-deps-with (num-cols ind deps with) + "describe each column to be plotted as (col . with)" + ;; make 'deps explicit + (unless deps + (setf deps (let (r) + (dotimes (i num-cols r) + (unless (eq num-cols (+ ind i)) + (setq r (cons (- num-cols i) r))))))) + ;; make sure 'with matches 'deps + (unless with + (setf with "lines")) + (unless (listp with) + (setf with (mapcar (lambda (x) with) deps))) + ;; invoke zipping function on converted data + (org-plot/zip deps with)) + +(defun org-plot/zip (xs ys) + (unless + (null xs) + (cons (cons (car xs) (or (car ys) "lines")) + (org-plot/zip (cdr xs) (cdr ys))))) + (defun org-plot/gnuplot-script (data-file num-cols params &optional preface) "Write a gnuplot script to DATA-FILE respecting the options set in PARAMS. NUM-COLS controls the number of columns plotted in a 2-d plot. @@ -240,22 +262,22 @@ manner suitable for prepending to a user-specified script." "%Y-%m-%d-%H:%M:%S") "\""))) (unless preface (pcase type ; plot command - (`2d (dotimes (col num-cols) - (unless (and (eq type '2d) - (or (and ind (equal (1+ col) ind)) - (and deps (not (member (1+ col) deps))))) - (setf plot-lines - (cons - (format plot-str data-file - (or (and ind (> ind 0) - (not text-ind) - (format "%d:" ind)) "") - (1+ col) - (if text-ind (format ":xticlabel(%d)" ind) "") - with - (or (nth col col-labels) - (format "%d" (1+ col)))) - plot-lines))))) + (`2d (dolist + (col-with + (org-plot/zip-deps-with num-cols ind deps with)) + (setf plot-lines + (cons + (format plot-str data-file + (or (and ind (> ind 0) + (not text-ind) + (format "%d:" ind)) "") + (car col-with) + (if text-ind (format ":xticlabel(%d)" ind) "") + (cdr col-with) + (or (nth (1- (car col-with)) + col-labels) + (format "%d" (car col-with)))) + plot-lines)))) (`3d (setq plot-lines (list (format "'%s' matrix with %s title ''" data-file with)))) @@ -310,7 +332,8 @@ line directly before or after the table." table data-file params))) (when y-labels (plist-put params :ylabels y-labels))))) ;; Check for timestamp ind column. - (let ((ind (1- (plist-get params :ind)))) + (let ((ind (1- (plist-get params :ind))) + (with (plist-get params :with))) (when (and (>= ind 0) (eq '2d (plist-get params :plot-type))) (if (= (length (delq 0 (mapcar @@ -320,7 +343,7 @@ line directly before or after the table." 0) (plist-put params :timeind t) ;; Check for text ind column. - (if (or (string= (plist-get params :with) "hist") + (if (or (and (stringp with) (string= with "hist")) (> (length (delq 0 (mapcar (lambda (el)