emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org plot scripts
@ 2009-06-18  7:25 josephzxu
  2009-06-29  3:32 ` Eric Schulte
  0 siblings, 1 reply; 3+ messages in thread
From: josephzxu @ 2009-06-18  7:25 UTC (permalink / raw)
  To: emacs-orgmode

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. Alternatively, I can also imagine giving the user the ability
to hard code the exact plot commands right in the org file.

Thanks for your time.

Joseph

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: org plot scripts
  2009-06-18  7:25 org plot scripts josephzxu
@ 2009-06-29  3:32 ` Eric Schulte
  2009-07-07 19:27   ` org plot scripts [PATCH] Eric Schulte
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Schulte @ 2009-06-29  3:32 UTC (permalink / raw)
  To: josephzxu; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1788 bytes --]

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]  

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: prepend-options-to-script.patch --]
[-- Type: text/x-patch, Size: 2525 bytes --]

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

[-- Attachment #3: Type: text/plain, Size: 204 bytes --]

_______________________________________________
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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: org plot scripts [PATCH]
  2009-06-29  3:32 ` Eric Schulte
@ 2009-07-07 19:27   ` Eric Schulte
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Schulte @ 2009-07-07 19:27 UTC (permalink / raw)
  To: josephzxu; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 174 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: prepend-options-to-script.patch --]
[-- Type: text/x-patch, Size: 2525 bytes --]

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

[-- Attachment #3: Type: text/plain, Size: 4540 bytes --]



"Eric Schulte" <schulte.eric@gmail.com> 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

[-- Attachment #4: Type: text/plain, Size: 204 bytes --]

_______________________________________________
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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-07-07 19:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-18  7:25 org plot scripts josephzxu
2009-06-29  3:32 ` Eric Schulte
2009-07-07 19:27   ` org plot scripts [PATCH] Eric Schulte

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).