[nixies-devel] Improvements to plot-scatter-graphic and for postscript output
Olaf Merkert
olaf at m-merkert.de
Sat Mar 20 21:43:29 UTC 2010
Hello everybody,
I am currently using cgn for my programming exercises in numerics. With a
number of small adjustments, it now fits my needs almost perfectly (I just want
to plot arrays of numbers in MATLAB style).
Please consider my changes for inclusion in the official repo. I mainly fixed
plot-scatter-graphic to work without error data and changed the default style
to lines because that is more appropriate for my purposes. If the latter is a
no-go, I could easily enhance the code such that errorbars are used if error
data is supplied (have not done that yet because I have no need for that).
I also made some minor changes to postscript-copy because that one only
produced empty files. However, it turns out that replot is no option if you
are piping the data to gnuplot (as in plot-scatter-graphic).
Other than that, I added some more functions to the exports of the package.
Sincerely,
Olaf Merkert
-------------- next part --------------
Sat Mar 20 21:07:08 CET 2010 Olaf Merkert <olaf at m-merkert.de>
* style option for plot-scatter-graphic
plot-scatter-graphic has a new parameter style, where a gnuplot style can be given as a string.
Furthermore, plot-scatter-graphic can now handle data-series where no error data is given.
Sat Mar 20 21:17:58 CET 2010 Olaf Merkert <olaf at m-merkert.de>
* improved postscript output
Export a number of useful functions in the package definition, for example the crucial create-scatter-data-serie.
Add fancy parameters to the postscript-copy function (and fix it to actually write something in the output file).
If the data is piped to gnuplot, replot requires it to be piped again. Add two functions to workaround this problem for postscript output.
New patches:
[style option for plot-scatter-graphic
Olaf Merkert <olaf at m-merkert.de>**20100320200708
Ignore-this: 56ed72949a54cc63a833f783b83ea76d
plot-scatter-graphic has a new parameter style, where a gnuplot style can be given as a string.
Furthermore, plot-scatter-graphic can now handle data-series where no error data is given.
] {
hunk ./cgn.lisp 191
"Creates a new serie for a histogram. x is a list of values"
(setf (graphic-series hg ) (concatenate 'list (graphic-series hg ) (list (make-instance 'simple-data-serie :x x :title title )))))
-(defgeneric plot-scatter-graphic ( sc &key fit-function ))
+(defgeneric plot-scatter-graphic ( sc &key fit-function style))
;fit-function es una funcio de gnuplot (un string).
hunk ./cgn.lisp 194
-(defmethod plot-scatter-graphic ( (sc scatter-graphic ) &key fit-function)
+(defmethod plot-scatter-graphic ( (sc scatter-graphic ) &key fit-function (style "lines"))
"This method is used to plot a scatter graphic. sc is an object of type scatter-graphic-description, cointaining some data series which we want to plot. plot-scatter-graphic simply will plot each of them with Its name as legend title. fit-function is a key parameter used to provided a fit function to plot with the data series. At the moment, fit-function must be a string containing some function that gnuplot can understand."
(let
(
hunk ./cgn.lisp 206
(error "Can't plot an empty graphic.")
)
(if (= nombre_de_series 1 )
- (setq plot_command (concatenate 'string plot_command (format nil " '-' with xyerrorbars title '~A' " (data-serie-title (elt (graphic-series sc ) 0)))) )
+ (setq plot_command (concatenate 'string plot_command (format nil " '-' with ~A title '~A' " style (data-serie-title (elt (graphic-series sc ) 0)))) )
(progn
;This works for doing plot '-' , '-' , '-' , '-' , '-' ...
hunk ./cgn.lisp 209
- (do ((i 0 (incf i )))
+ (do ((i 0 (1+ i )))
((= i (- nombre_de_series 1 )) t )
(if (= i 0 )
hunk ./cgn.lisp 212
- (setq plot_command (concatenate 'string plot_command (format nil " '-' with xyerrorbars title '~A', " (data-serie-title (elt (graphic-series sc ) i)))))
- (setq plot_command (concatenate 'string plot_command (format nil " '-' with xyerrorbars title '~A', " (data-serie-title (elt (graphic-series sc ) i)))))
+ (setq plot_command (concatenate 'string plot_command (format nil " '-' with ~A title '~A', " style (data-serie-title (elt (graphic-series sc ) i)))))
+ (setq plot_command (concatenate 'string plot_command (format nil " '-' with ~A title '~A', " style (data-serie-title (elt (graphic-series sc ) i)))))
)
)
hunk ./cgn.lisp 216
- (setq plot_command (concatenate 'string plot_command (format nil " '-' with xyerrorbars title '~A' " (data-serie-title (elt (graphic-series sc ) (- nombre_de_series 1 ))))))
+ (setq plot_command (concatenate 'string plot_command (format nil " '-' with ~A title '~A' " style (data-serie-title (elt (graphic-series sc ) (- nombre_de_series 1 ))))))
)
)
(format-gnuplot "set title '~A' " (graphic-title sc))
hunk ./cgn.lisp 231
(error_y (data-serie-error_y graphic))
)
- (incf numero_de_serie )
- (do ((i 0 (incf i )))
- ((= i (length x ) ) (values))
- (format-gnuplot " ~F ~F ~F ~F~%" (elt x i) (elt y i ) (elt error_x i ) (elt error_y i )))
+ (incf numero_de_serie )
+ (if (and error_x error_y) ; only pass error data if both are non-nil
+ (dotimes (i (length x))
+ ;; end-of-line will be output by format-gnuplot
+ (format-gnuplot "~F ~F ~F ~F" (elt x i) (elt y i )
+ (elt error_x i) (elt error_y i)))
+ (dotimes (i (length x))
+ (format-gnuplot "~F ~F" (elt x i) (elt y i ))))
(format-gnuplot "e" )
)
)
}
[improved postscript output
Olaf Merkert <olaf at m-merkert.de>**20100320201758
Ignore-this: 6f7c39a2d6dcea4ed13040bb6c915eb8
Export a number of useful functions in the package definition, for example the crucial create-scatter-data-serie.
Add fancy parameters to the postscript-copy function (and fix it to actually write something in the output file).
If the data is piped to gnuplot, replot requires it to be piped again. Add two functions to workaround this problem for postscript output.
] {
hunk ./cgn.lisp 38
(defpackage :cgn
(:use :cl :ltk)
- (:export #:start-gnuplot #:format-gnuplot #:close-gnuplot #:set-title #:set-grid #:on #:off #:plot-function #:replot-function #:x #:y #:set-range #:plot-points #:postscript-copy #:w32 #:print-graphic #:plot #:plot-1 #:save-cgn #:load-cgn #:with-gnuplot #:animate-function #:enable-debug #:disable-debug #:show-release-info #:plot-scatter-graphic #:create-scatter-graphic-description #:create-data-serie #:splot #:plot-histogram #:plot-complex-histogram #:discrete)
+ (:export #:start-gnuplot #:format-gnuplot #:close-gnuplot #:set-title #:set-grid #:on #:off #:plot-function #:replot-function #:x #:y #:set-range #:plot-points #:postscript-copy #:w32 #:print-graphic #:plot #:plot-1 #:save-cgn #:load-cgn #:with-gnuplot #:animate-function #:enable-debug #:disable-debug #:show-release-info #:plot-scatter-graphic #:create-scatter-graphic-description #:create-scatter-data-serie #:splot #:plot-histogram #:plot-complex-histogram #:discrete #:plot2d #:plot3d #:set-eps-output #:reset-output)
(:documentation "cgn is a library to control gnuplot from inside Common Lisp."))
(in-package :cgn)
hunk ./cgn.lisp 1119
(defun postscript-copy ( filename )
- "Saves a postscript copy of the screen ."
- (format-gnuplot "set terminal postscript color")
- (format-gnuplot "set output '~F'" filename)
- (format-gnuplot "set terminal pop")
- (values))
+ "Saves a postscript copy of the screen. Careful: this does not work
+with scatter plots."
+ (format-gnuplot "set terminal postscript eps enhanced colour")
+ (format-gnuplot "set output '~F'" filename)
+ (format-gnuplot "replot")
+ (format-gnuplot "set terminal pop"))
+
+;; replot does not work with piped data
+(defun set-eps-output (filename)
+ "Plot to a postscript file instead of the screen."
+ (format-gnuplot "set terminal postscript eps enhanced colour")
+ (format-gnuplot "set output '~F'" filename))
+
+(defun reset-output ()
+ "Restore plotting to the screen after plotting to a file."
+ (format-gnuplot "set terminal pop"))
}
Context:
[Histogram utilities
superratoli at gmail.com**20081122085746
Within this patch I add some utilities to CGN in order to make It
easier to create histograms. I have to translate them to english, but
they are usable.
]
[
superratoli at gmail.com**20081029195144
corrected plot-histogram xtics problem
Now plot-histogram plots the xtics in diagonal.
]
[plot2d complete
superratoli at gmail.com**20080403164257
Now plot2d is complete. There are some more options to implement, but It can print everythin: discrete plots with (optional) errorbars , lisp functions (also lambda functions) and gnuplot functions (lisp strings containing something like "sin(x)" ). Now we can do everything CGN can do (except plotting histograms) with only this function.
]
[plot2d with errorbars
superratoli at gmail.com**20080403145502
Since now plot2d understands errorbars.
]
[plot-points-and-function
superratoli at gmail.com**20080322200515
Dan Becker has contributed the plot-points-and-function function, which is similar to plot-scatter-graphic. I've added It, plus some changes he has sent to change the use of nth to elt. I've also written the plot-points-and-function-test test, and updated some autodoc. Also the manual documents this new function and the limitation to use gnuplot >= 4.2.0.
]
[elt instead of nth
superratoli at gmail.com**20080312185807
Now we use elt instead of nth. This way CGN can understand vectors and lists easily. Hack contributed by Dan.
]
[Improved docstrings
superratoli at gmail.com**20080303190127
We are going towards CGN 009, and we want to improve the quality of the source code. One step is to improve docstrings for CGN.
]
[fit-function on plot-scatter-graphic
superratoli at gmail.com**20080302105555
Now plot-scatter-graphic supports a key parameter called fit-function. It's a string with a gnuplot function. I've also updated doc strings and the pdf manual.
]
[Multiple connections
superratoli at gmail.com**20080301190214
From now, CGN can use multiple connections. You can run (cgn::multiple-connection-test) to see an example about how It works. I've improved the pdf manual and the documentation too. I've corrected a little bug that prevented CGN 009 from running on Windows.009 from running on Windows.
]
[options for plot3d
superratoli at gmail.com**20080215105950
Now plot3d understands the same options that plot2d.
]
[plot3d and others
superratoli at gmail.com**20080212160452
From now, we have plot3d. It only understand a function to plot. At the moment, we don't use the paramether options at all.
Also format-gnuplot and gformat start a gnuplot connection if It's not running when you use them. This doesn't override the default use of the with-gnuplot macro, but makes things easier for novices.
We add some demos too: see plot2d-test, plot-test and splot-test.
]
[Initial import
superratoli at gmail.com**20080212090654]
Patch bundle hash:
b51846370260ba46347ade762003f1efb95d3f5d
More information about the nixies-devel
mailing list