# vgplot 59 | 60 | This common lisp library is an interface to the gnuplot plotting 61 | utility. 62 | 63 | The intention of the API is to resemble to some of the plot commands 64 | of octave or matlab. 65 | 66 | ## Usage 67 | 68 | (asdf:load-system :vgplot) or (ql:quickload :vgplot) 69 | 70 | (vgplot:plot '(1 2 3) '(0 -2 17)) 71 | 72 | For examples run the demo function: 73 | 74 | (vgplot:demo) 75 | 76 | and see API documentation in docs/vgplot.html or on http://volkers.github.io/vgplot/vgplot.html 77 | 78 | ## License 79 | 80 | Copyright (C) 2013 - 2021 Volker Sarodnick 81 | 82 | mail: (remove #\y (subseq "avoidspamyvolykerysyar@gymyx.net" 9)) 83 | 84 | GNU General Public License 85 |
Actvate debugging when true.
Gnuplot binary. Change when gnuplot not in path.
Do a 3d plot. Uses gnuplot's 'splot'. 115 | The inputs are similar to 'plot', but with some key differences: 116 | vals could be: x y z 117 | x y z label-string 118 | style commands in the label-string work the same as in 'plot'.
Set axis to limit-list and return actual limit-list, limit-list could be: 126 | '(xmin xmax) or '(xmin xmax ymin ymax), 127 | values can be: 128 | a number: use it as the corresponding limit 129 | nil: do not change this limit 130 | t: autoscale this limit 131 | without limit-list do return current axis.
Create a bar plot y = f(x) on active plot, create plot if needed. 139 | :x (optional) vector or list of x strings or numbers 140 | plot to index if not provided 141 | :y list of y '((y &key :label :color) (y &key :label :color) ...) 142 | y vector or list of y values 143 | :label string for legend label (optional) 144 | :color string defining the color (optional); 145 | must be known by gnuplot, e.g. blue, green, red or cyan 146 | :style (optional) "grouped" (default) or "stacked" 147 | :width (optional) width of the bars where 1.0 means to fill the space completely 148 | (for the gap in style "grouped" see parameter gap) 149 | :gap (optional, only used in style "grouped") the gap between the groups 150 | in units of width of one boxwidth 151 | e.g.: 152 | (bar :x #("Item 1" "Item 2" "Item 3") 153 | :y '((#(0.3 0.2 0.1) :label "Values" :color "blue") 154 | (#(0.1 0.2 0.3) :label "Values" :color "red")) 155 | :style "stacked" 156 | :width 0.6)
Close all connected gnuplots
Close connected gnuplot
Show usecases of vgplot.
Add a new plot window to a current one.
Send a command directly to active gnuplot process, return gnuplots response 192 | print also response to stdout if print? is true
Add grid to plot if style t, otherwise remove grid. 200 | If key parameter replot is true (default) run an additional replot thereafter.
Provide options to the legend aka keys. 208 | :show Show legend (default) 209 | :hide Hide legend 210 | :boxon Use box around the legend 211 | :boxoff Don't use a box (default) 212 | :left Title left of sample line (default) 213 | :right Title right of sample line 214 | :north Place legend center top 215 | :south Center bottom 216 | :east Right center 217 | :west Left center 218 | :northeast Right top (default) 219 | :northwest Left top 220 | :southeast Right bottom 221 | :southwest Left bottom 222 | :at x y Place legend at position x,y 223 | :inside Place legend inside the plot (default) 224 | :outside Place legend outside the plot
Return a list of found vectors (one vector for one column) in data file fname 232 | (e.g. a csv-file). 233 | Datafile fname must hold columns separated by spaces, tabs or commas (other separators may work), 234 | content after # till end of line is assumed to be a comment and ignored.
Produce a two-dimensional plot using logarithmic scales scale for both axis. 242 | See the documentation of the plot command for a description of the arguments.
Helper function for a surface plot (surf). 250 | Map fun to every pair of elements of the arrays xx and yy and return the corresponding array zz. 251 | See surf for an example.
Helper function for a surface plot (surf). 259 | Given vectors of X and Y coordinates, return array XX for a 2-D grid. 260 | The columns of XX are copies of X. 261 | Usually used in combination with meshgrid-y. 262 | See surf for examples.
Helper function for a surface plot (surf). 270 | Given vectors of X and Y coordinates, return array YY for a 2-D grid. 271 | The rows of YY are copies of Y. 272 | Usually used in combination with meshgrid-x. 273 | See surf for examples.
Add a new plot window to a current one.
Plot y = f(x) on active plot, create plot if needed. 288 | vals could be: y plot y over its index 289 | y label-string plot y over its index using label-string as label 290 | x y plot y = f(x) 291 | x y label-string plot y = f(x) using label-string as label 292 | following parameters add curves to same plot e.g.: 293 | x y label x1 y1 label1 ... 294 | label: 295 | A simple label in form of "text" is printed directly. 296 | 297 | A label with style commands: label in form "styles;text;add-styles": 298 | 299 | In the ordinary case add-styles will be empty. 300 | 301 | styles can be (combinations possible): 302 | "-" lines 303 | ":" dotted lines 304 | "." dots 305 | "+" points 306 | "o" circles 307 | "r" red 308 | "g" green 309 | "b" blue 310 | "c" cyan 311 | "k" black 312 | "y" yellow 313 | "m" magenta 314 | "w" white 315 | "#RRGGBB" sets an arbitrary 24-bit RGB color (have to be exactly 6 digits) 316 | 317 | e.g.: 318 | (plot x y "r+;red values;") plots y = f(x) as red points with the 319 | label "red values" 320 | 321 | If add-styles is not empty, the string in add-styles is send unmodyfied to gnuplot, other styles and colors are skipped. 322 | This is useful to set more complicated styles, e.g.: 323 | 324 | (plot x y ";use of additional styles;with linespoints pt 7 ps 2 lc 'red'") 325 | plots y = f(x) as lines with red points, pointsize 2 with the 326 | label "use of additional styles" 327 | 328 | To use a backslash in add-styles you have to quote it, e.g.: 329 | 330 | (plot x y ";;with points pt '\U+2299'") 331 |
Plot data-file directly, datafile must hold columns separated by spaces, tabs or commas 339 | (other separators may work), use with-lines style. 340 | :x-col (optional) column to use as x values. 341 | plot to index if not provided
Print the actual plot into filename (a pathname). 349 | Use the (optional) terminal or if not provided, 350 | use the extension of filename to guess the terminal type. 351 | Guessing of terminals works currently for: gif, pdf, png 352 | 353 | Examples: (vgplot:print-plot #p"plot.pdf") 354 | (vgplot:print-plot #p"plot.eps" :terminal "epscairo") 355 | 356 | It is possible to give additional parameters inside the terminal parameter, e.g.: 357 | (vgplot:print-plot #p"plot.pdf" :terminal "pdfcairo size \"5cm\",\"5cm\"") 358 |
Return vector of values in a certain range: 366 | (range limit) return natural numbers below limit 367 | (range start limit) return ordinary numbers starting with start below limit 368 | (range start limit step) return numbers starting with start, successively adding step untill reaching limit (excluding)
Send the replot command to gnuplot, i.e. apply all recent changes in the plot.
Produce a two-dimensional plot using a logarithmic scale for the X axis. 383 | See the documentation of the plot command for a description of the arguments.
Produce a two-dimensional plot using a logarithmic scale for the Y axis. 391 | See the documentation of the plot command for a description of the arguments.
Produce a stairstep plot. 399 | vals could be: y plot y over its index 400 | x y plot y = f(x) 401 | x y label-string plot y = f(x) using label-string as label 402 | following parameters add curves to same plot e.g.: 403 | x y label x1 y1 label1 ... 404 | 405 | For the syntax of label-string see documentation of plot command. 406 | 407 | If you only want to prepare the sequences for later plot, see 408 | function stairs-no-plot.
Prepare a stairstep plot, but don't actually plot it. 416 | Return a list of 2 sequences, x and y, usable for the later plot. 417 | 418 | If one argument is given use it as y sequence, there x are the indices. 419 | If both arguments are given use yx as x and y is y. 420 | 421 | If you want to plot the stairplot directly, see function stairs.
Set up a plot grid with rows by cols subwindows and use location index for next plot command. 429 | The plot index runs row-wise. First all the columns in a row are 430 | filled and then the next row is filled. 431 | 432 | For example, a plot with 2 rows by 3 cols will have following plot indices: 433 | 434 | +-----+-----+-----+ 435 | | 0 | 1 | 2 | 436 | +-----+-----+-----+ 437 | | 3 | 4 | 5 | 438 | +-----+-----+-----+ 439 | 440 | Observe, gnuplot doesn't allow interactive mouse commands in multiplot mode. 441 |
Plot a 3-D surface mesh. 449 | Vals could be: zz [label-string] 450 | xx yy zz [label-string] 451 | 452 | For label-string see documentation of plot. 453 | 454 | xx, yy and zz are 2 dimensional arrays usually produced by meshgrid-x, meshgrid-y and meshgrid-map. 455 | All 3 arrays have to have the same form where the rows follow the x direction and the columns the y. 456 | xx: #2A((x0 x0 x0 ... x0) 457 | (x1 x1 x1 ... x1) 458 | ... 459 | (xn xn xn ... xn)) 460 | yy: #2A((y0 y1 y2 ... ym) 461 | (y0 y1 y2 ... ym) 462 | ... 463 | (y0 y1 y2 ... ym)) 464 | zz: #2A((z00 z01 z02 ... z0m) 465 | (z10 z11 z12 ... z1m) 466 | ... 467 | (zn0 zn1 zn2 ... znm)) 468 | 469 | Example 1: Plot some measurement data without providing xx and yy: 470 | (let ((zz (make-array (list 3 4) :initial-contents '((0.8 1.5 1.7 2.8) (1.8 1.2 1.2 2.1) (1.7 1.0 1.0 1.9))))) 471 | (vgplot:surf zz "r;array plotted without providing xx or yy;")) 472 | 473 | Example 2: Plot some measurement data: 474 | (let* ((x #(1.0 2.0 3.0)) 475 | (y #(0.0 2.0 4.0 6.0)) 476 | (zz (make-array (list (length x) (length y)) :initial-contents '((0.8 1.5 1.7 2.8) (1.8 1.2 1.2 2.1) (1.7 1.0 1.0 1.9)))) 477 | (xx (vgplot:meshgrid-x x y)) 478 | (yy (vgplot:meshgrid-y x y))) 479 | (vgplot:surf xx yy zz)) 480 | 481 | Example 3: Plot a function z = f(x,y), e.g. the sombrero function: 482 | (let* ((eps double-float-epsilon) 483 | (fun #'(lambda (x y) (/ (sin (sqrt (+ (* x x) (* y y) eps))) (sqrt (+ (* x x) (* y y) eps))))) 484 | (x (vgplot:range -8 8 0.2)) 485 | (y (vgplot:range -8 8 0.2)) 486 | (xx (vgplot:meshgrid-x x y)) 487 | (yy (vgplot:meshgrid-y x y)) 488 | (zz (vgplot:meshgrid-map fun xx yy))) 489 | (vgplot:surf xx yy zz) 490 | (vgplot:format-plot nil "set hidden3d") 491 | (vgplot:format-plot nil "set pm3d") 492 | (vgplot:replot)) 493 |
Add text label text-string at position x,y 502 | optional: 503 | :tag nr label number specifying which text label to modify 504 | (integer you get when running (text-show-label)) 505 | :horizontalalignment "left"(default), "center" or "right" 506 | :rotation degree rotate text by this angle in degrees (default 0) [if the terminal can do so] 507 | :font "" use this font, e.g. :font "Times" [terminal depending, gnuplot help 508 | recommends: http://fontconfig.org/fontconfig-user.html for more information] 509 | :fontsize nr 510 | :color "color" one of red, green, blue, cyan, black, yellow or white 511 | an unrecogniced color is send unchanged to gnuplot, this can be used to get other colors or effects, e.g: 512 | "tc rgb '#112233'" gives color with the RGB code 0x112233 (0xRRGGBB) 513 | "tc lt 1" gives the same color as line 1 514 | 515 | Observe, it could alter the font of the labels (aka legend or key in 516 | gnuplot terms) if you change font or fontsize of a text field. To 517 | explicitly chose fontsize (or font) for the label you could use: 518 | 519 | (format-plot t "set key font \",10\"") 520 | (replot) 521 |
Delete text labels specified by tags. 529 | A tag is the number of the text label you get when running (text-show-label).
Show text labels. This is useful to get the tag number for (text-delete)
Add title str to plot. If key parameter replot is true (default) 544 | run an additional replot thereafter.
Add x axis label. If key parameter replot is true (default) 552 | run an additional replot thereafter.
Add y axis label. If key parameter replot is true (default) 560 | run an additional replot thereafter.
Add z axis label. If key parameter replot is true (default) 568 | run an additional replot thereafter.