From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: org plot scripts [PATCH] Date: Tue, 07 Jul 2009 12:27:06 -0700 Message-ID: References: <87hbyedmw7.wl%josephzxu@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MOGJx-0002Yv-3Q for emacs-orgmode@gnu.org; Tue, 07 Jul 2009 15:27:17 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MOGJs-0002WT-5x for emacs-orgmode@gnu.org; Tue, 07 Jul 2009 15:27:16 -0400 Received: from [199.232.76.173] (port=36277 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MOGJr-0002WP-Sz for emacs-orgmode@gnu.org; Tue, 07 Jul 2009 15:27:12 -0400 Received: from rv-out-0708.google.com ([209.85.198.247]:47615) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MOGJq-0005nn-OY for emacs-orgmode@gnu.org; Tue, 07 Jul 2009 15:27:11 -0400 Received: by rv-out-0708.google.com with SMTP id f25so451843rvb.6 for ; Tue, 07 Jul 2009 12:27:10 -0700 (PDT) In-Reply-To: (Eric Schulte's message of "Sun, 28 Jun 2009 20:32:50 -0700") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: josephzxu@gmail.com Cc: emacs-orgmode@gnu.org --=-=-= Hi Carsten, Having played with this patch some more, I am confident that it is working and won't break org-plot. Please do apply it when you get a chance. Thanks -- Eric --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=prepend-options-to-script.patch diff --git a/lisp/org-plot.el b/lisp/org-plot.el index 78775a0..ae01aa2 100644 --- a/lisp/org-plot.el +++ b/lisp/org-plot.el @@ -181,9 +181,11 @@ and dependant variables." (setf back-edge "") (setf front-edge ""))))) row-vals)) -(defun org-plot/gnuplot-script (data-file num-cols params) +(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." +NUM-COLS controls the number of columns plotted in a 2-d plot. +Optional argument PREFACE returns only option parameters in a +manner suitable for prepending to a user-specified script." (let* ((type (plist-get params :plot-type)) (with (if (equal type 'grid) 'pm3d @@ -238,7 +240,8 @@ NUM-COLS controls the number of columns plotted in a 2-d plot." (add-to-script (concat "set timefmt \"" (or timefmt ;; timefmt passed to gnuplot "%Y-%m-%d-%H:%M:%S") "\""))) - (case type ;; plot command + (unless preface + (case type ;; plot command ('2d (dotimes (col num-cols) (unless (and (equal type '2d) (or (and ind (equal (+ 1 col) ind)) @@ -259,8 +262,8 @@ NUM-COLS controls the number of columns plotted in a 2-d plot." ('grid (setq plot-lines (list (format "'%s' with %s title ''" data-file with))))) - (add-to-script - (concat plot-cmd " " (mapconcat 'identity (reverse plot-lines) ",\\\n "))) + (add-to-script + (concat plot-cmd " " (mapconcat 'identity (reverse plot-lines) ",\\\n ")))) script))) ;;----------------------------------------------------------------------------- @@ -328,10 +331,13 @@ line directly before or after the table." ;; write script (with-temp-buffer (if (plist-get params :script) ;; user script - (progn (insert-file-contents (plist-get params :script)) - (goto-char (point-min)) - (while (re-search-forward "$datafile" nil t) - (replace-match data-file nil nil))) + (progn (insert + (org-plot/gnuplot-script data-file num-cols params t)) + (insert "\n") + (insert-file-contents (plist-get params :script)) + (goto-char (point-min)) + (while (re-search-forward "$datafile" nil t) + (replace-match data-file nil nil))) (insert (org-plot/gnuplot-script data-file num-cols params))) ;; graph table --=-=-= "Eric Schulte" writes: > josephzxu@gmail.com writes: > >> Hi: >> >> I've been trying to make candlestick plots with org-plot, and the only >> way I've found that I can do this is by specifying a custom script in >> the +PLOT options. However, I noticed that when I specify a script, >> all other +PLOT options I specify, such as with set: or line:, are >> completely ignored. I think it would be nice to allow the user to >> specify plot options in the latter manner along with custom scripts >> and just prepend the options to the script. This way, the user can use >> a single custom script to plot multiple data tables, while being able >> to set things like the title or range of the plot on a per-table >> basis. > > That sounds like a great idea, the attached patch[1] *should* implement > the prepending of options to a script as you described above. It works > for me on one simple test. Please let me know if it works for you. > >> Alternatively, I can also imagine giving the user the ability >> to hard code the exact plot commands right in the org file. >> > > This second approach could work with "org-babel" --a library for > org-mode on which I am currently working--. I hope to add gnuplot as a > supported language to org-babel. Once this is done it will be possible > to write gnuplot source-code blocks which can then be fed table data > returning graphs for display or inclusion in org-mode files. Through > the "library of babel" functionality, these gnuplot code blocks could be > named, saved, and called from other org-mode files. > > Cheers -- Eric > >> >> Thanks for your time. >> >> Joseph >> >> >> _______________________________________________ >> Emacs-orgmode mailing list >> Remember: use `Reply All' to send replies to the list. >> Emacs-orgmode@gnu.org >> http://lists.gnu.org/mailman/listinfo/emacs-orgmode > > > Footnotes: > [1] > diff --git a/lisp/org-plot.el b/lisp/org-plot.el > index 78775a0..ae01aa2 100644 > --- a/lisp/org-plot.el > +++ b/lisp/org-plot.el > @@ -181,9 +181,11 @@ and dependant variables." > (setf back-edge "") (setf front-edge ""))))) > row-vals)) > > -(defun org-plot/gnuplot-script (data-file num-cols params) > +(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." > +NUM-COLS controls the number of columns plotted in a 2-d plot. > +Optional argument PREFACE returns only option parameters in a > +manner suitable for prepending to a user-specified script." > (let* ((type (plist-get params :plot-type)) > (with (if (equal type 'grid) > 'pm3d > @@ -238,7 +240,8 @@ NUM-COLS controls the number of columns plotted in a 2-d plot." > (add-to-script (concat "set timefmt \"" > (or timefmt ;; timefmt passed to gnuplot > "%Y-%m-%d-%H:%M:%S") "\""))) > - (case type ;; plot command > + (unless preface > + (case type ;; plot command > ('2d (dotimes (col num-cols) > (unless (and (equal type '2d) > (or (and ind (equal (+ 1 col) ind)) > @@ -259,8 +262,8 @@ NUM-COLS controls the number of columns plotted in a 2-d plot." > ('grid > (setq plot-lines (list (format "'%s' with %s title ''" > data-file with))))) > - (add-to-script > - (concat plot-cmd " " (mapconcat 'identity (reverse plot-lines) ",\\\n "))) > + (add-to-script > + (concat plot-cmd " " (mapconcat 'identity (reverse plot-lines) ",\\\n ")))) > script))) > > ;;----------------------------------------------------------------------------- > @@ -328,10 +331,13 @@ line directly before or after the table." > ;; write script > (with-temp-buffer > (if (plist-get params :script) ;; user script > - (progn (insert-file-contents (plist-get params :script)) > - (goto-char (point-min)) > - (while (re-search-forward "$datafile" nil t) > - (replace-match data-file nil nil))) > + (progn (insert > + (org-plot/gnuplot-script data-file num-cols params t)) > + (insert "\n") > + (insert-file-contents (plist-get params :script)) > + (goto-char (point-min)) > + (while (re-search-forward "$datafile" nil t) > + (replace-match data-file nil nil))) > (insert > (org-plot/gnuplot-script data-file num-cols params))) > ;; graph table --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --=-=-=--