├── .gitignore ├── LICENSE ├── README ├── data.csv ├── data.txt ├── demo.lisp ├── docs └── vgplot.html ├── package.lisp ├── test.lisp ├── vgplot.asd └── vgplot.lisp /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.fasl 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | # vgplot 2 | 3 | This common lisp library is an interface to the gnuplot plotting 4 | utility. 5 | 6 | The intention of the API is to resemble to some of the plot commands 7 | of octave or matlab. 8 | 9 | ## Usage 10 | 11 | (asdf:load-system :vgplot) or (ql:quickload :vgplot) 12 | 13 | (vgplot:plot '(1 2 3) '(0 -2 17)) 14 | 15 | For examples run the demo function: 16 | 17 | (vgplot:demo) 18 | 19 | and see API documentation in docs/vgplot.html or on http://volkers.github.io/vgplot/vgplot.html 20 | 21 | ## License 22 | 23 | Copyright (C) 2013 - 2021 Volker Sarodnick 24 | 25 | mail: (remove #\y (subseq "avoidspamyvolykerysyar@gymyx.net" 9)) 26 | 27 | GNU General Public License 28 | -------------------------------------------------------------------------------- /data.csv: -------------------------------------------------------------------------------- 1 | # comment 2 | # second line 3 | # ... 4 | +1e-02,17,-3,8 5 | -3,16,-2,7 6 | 4,17,0,7 7 | 3,18,1,6 # comment 8 | 5,19,1,8 9 | -------------------------------------------------------------------------------- /data.txt: -------------------------------------------------------------------------------- 1 | 1 2 3 2 | 2 1 17 3 | 3 7 10 # comment 4 | 17 8 13 5 | # comment 6 | 16 7 12 7 | -------------------------------------------------------------------------------- /demo.lisp: -------------------------------------------------------------------------------- 1 | ;;;; demo.lisp 2 | 3 | #| 4 | This file contains a demonstration of some of the functions of vgplot. 5 | vgplot is an interface to the gnuplot utility. 6 | Copyright (C) 2013 - 2020 Volker Sarodnick 7 | 8 | This program is free software: you can redistribute it and/or modify 9 | it under the terms of the GNU General Public License as published by 10 | the Free Software Foundation, either version 3 of the License, or 11 | (at your option) any later version. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with this program. If not, see . 20 | |# 21 | 22 | (in-package #:vgplot) 23 | 24 | (defun drop-substring (substring instring) 25 | (let ((i 0) 26 | (ilen (length substring)) 27 | (chars)) 28 | (loop for c across instring do 29 | (if (char= c (aref substring i)) 30 | (incf i) 31 | (if (= i 0) 32 | (push c chars) 33 | (progn 34 | (loop for j below i do 35 | (push (aref substring j) chars)) 36 | (push c chars) 37 | (setf i 0)))) 38 | (if (= i ilen) 39 | (setf i 0))) 40 | (coerce (nreverse chars) 'string))) 41 | 42 | (defun print-n-run-list (lst) 43 | "Print commands in lst and run them after a (read-char), 44 | ENTER continue, all other characters break and quit demo" 45 | (loop for cmd in lst do 46 | (progn (princ (drop-substring "vgplot::" (format nil "~s" cmd))) 47 | (unless (char= #\Newline (read-char)) 48 | (close-all-plots) 49 | (return-from print-n-run-list nil)) 50 | (eval cmd)))) 51 | 52 | (defun demo () 53 | "Show usecases of vgplot." 54 | (let ((*print-case* :downcase)) 55 | (format t "****************************************************************~%") 56 | (format t "vgplot demo, run commands by pressing RETURN~%") 57 | (format t "press q (or any other character) RETURN to leave the demo~%") 58 | (format t "****************************************************************~%") 59 | (print-n-run-list 60 | '( ;; add demo commands here 61 | (progn 62 | (plot #(1 2 3) #(0 -2 -17) ";silly example;") 63 | (title "Simple curve") 64 | (text 1.2 -14 "Plot vectors with legend and add a title")) 65 | (progn 66 | (defvar x) 67 | (defvar y) 68 | (setf x (range 0 (* 2 pi) 0.01)) 69 | (setf y (map 'vector #'sin x)) 70 | (plot x y "y = sin(x)") 71 | (xlabel "[rad]") 72 | (ylabel "magnitude") 73 | (text 0.2 -0.6 "Use function range to create vectors and add labels to axes")) 74 | (and "text-show-labels shows the active labels and their tags" 75 | (text-show-label)) 76 | (and "Usefull to delete or change labels" 77 | (text-delete 1 2)) 78 | (text 0.5 -0.5 "You can use a different size" :fontsize 14) 79 | (progn 80 | (text 0.5 -0.5 "You can change a present label" 81 | :tag 1 :rotation 60 :font "Times" :fontsize 12 :color "green") 82 | (and "font definitions for text change also the font of the legend, 83 | the following is needed to change the keys back") 84 | (format-plot t "set key font \",10\"") 85 | (replot)) 86 | (and "the :color color command can also send arbitrarily style commands" 87 | (text 0.5 -0.5 "Label in the same color as line 1" :tag 1 :color "tc lt 1")) 88 | (progn 89 | (text-delete 1) 90 | (text 3 0.5 "axis can change the range of the x axis") 91 | (axis (list (/ pi 2) 5))) 92 | (progn 93 | (text -0.5 -0.5 "axis can also change the range of both x and y axis" :tag 1) 94 | (axis (list -1 pi -1.2 1.2))) 95 | (progn 96 | (text 0.5 -0.5 "t means autoscale and nil unchanged corresponding axis" :tag 1) 97 | (axis '(t nil))) 98 | (progn 99 | (text 0.5 -0.5 "another example of the use of axis" :tag 1) 100 | (axis '(nil nil -1.5 t))) 101 | (progn 102 | (text 0.5 -0.5 "Remove the grid" :tag 1) 103 | (grid nil)) 104 | (progn 105 | (text 0.5 -0.5 "print-plot prints the plot into a file" :tag 1) 106 | (print-plot #p"plot.pdf")) 107 | (and "close-plot closes the actual plot" 108 | (close-plot)) 109 | (progn 110 | (defvar z) 111 | (setf z (map 'vector #'cos x)) 112 | (plot x y "b;y = sin(x);" x z "g;y = cos(x);") 113 | (title "Some Other Graphs")) 114 | (progn 115 | (legend :outside :boxon :southeast :right) 116 | (title "Use legend to manipulate the legend (aka keys)")) 117 | (progn 118 | (legend :at 5 0.4) 119 | (title "Place the legend directly at position x y")) 120 | (progn 121 | (new-plot) 122 | (setf y (map 'vector #'(lambda (a) (sin (* 2 a))) x)) 123 | (plot x y "+k;y = cos(2x) (new-plot);") 124 | (text 0.5 -0.5 "new-plot adds a new plot window")) 125 | (text-show-label) 126 | (progn 127 | (plot x y "og;y = cos(2x) (new-plot);" #(0 1 2 4 7) #(-1 2 1 -1.2 0) ":r;dotted style;") 128 | (text 0.5 0.5 "Different line styles" :tag 1)) 129 | (progn 130 | (plot x y "#bf0810;# followed by 6 hex digits, e.g. #bf0810;") 131 | (text 0.5 0.5 "Use of RGB colors in line style" :tag 1)) 132 | (progn 133 | (and "(format-plot) allows direct commands to the running gnuplot process") 134 | (format-plot t "set size square 0.5,0.5~%") 135 | (replot)) 136 | (close-all-plots) 137 | (progn 138 | (plot x y "w;" #(0 1 2 4 7) #(-1 2 1 -1.2 0) "y;") 139 | (format-plot t "set object rectangle from screen 0,0 to screen 1,1 fillcolor 'black' behind") 140 | (format-plot t "set border lc 'white'") 141 | (text 2.5 1.5 "Another example for use of format-plot commands" :color "white") 142 | (vgplot:replot)) 143 | (close-all-plots) 144 | (plot #(1 2 3 4) #(2 4 3 1) ";use of additional styles;with linespoints pt 7 ps 2 lc 'red'") 145 | (close-all-plots) 146 | (let ((x #(1 2 3 4))) 147 | (subplot 3 2 0) 148 | (plot x #(0.5 2 -3 4) x #(-1 2 3 4)) 149 | (title "Use of multiplots") 150 | (subplot 3 2 1) 151 | (plot x #(0.2 0.4 3 0.4) x #(-1 -2 3 4)) 152 | (title "") 153 | (subplot 3 2 2) 154 | (plot x #(-1 2 3 4) x #(-1 -2 -3 4)) 155 | (subplot 3 2 3) 156 | (plot x #(1 -1.8 -2.8 4) x #(-1 -2 -3 -4)) 157 | (subplot 3 2 4) 158 | (plot x #(1 2 -3 4) x #(1 -2 3 4)) 159 | (subplot 3 2 5) 160 | (plot x #(1 -2 3 4) x #(1 -2 -3 4))) 161 | (let ((x #(1 10 100 1000)) 162 | (y #(1 2 3 4))) 163 | (subplot 2 2 0) 164 | (plot x y) 165 | (title "Linear axes (plot)") 166 | (subplot 2 2 1) 167 | (semilogx x y) 168 | (title "Log x axis (semilogx)") 169 | (subplot 2 2 2) 170 | (semilogy x y) 171 | (title "Log y axis (semilogy)") 172 | (subplot 2 2 3) 173 | (loglog x y) 174 | (title "Log x and y axis (loglog)")) 175 | (close-plot) 176 | (let* ((z (range 0 (* 3 pi) 0.1)) 177 | (x (map 'vector #'sin z)) 178 | (y (map 'vector #'cos z))) 179 | (3d-plot x y z) 180 | (title "Example of a 3D plot")) 181 | (close-plot) 182 | (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))))) 183 | (vgplot:surf zz "r;array plotted without providing xx or yy;")) 184 | (close-plot) 185 | (let* ((eps double-float-epsilon) 186 | (fun #'(lambda (x y) (/ (sin (sqrt (+ (* x x) (* y y) eps))) (sqrt (+ (* x x) (* y y) eps))))) 187 | (x (range -8 8 0.2)) 188 | (y (range -8 8 0.2)) 189 | (xx (meshgrid-x x y)) 190 | (yy (meshgrid-y x y)) 191 | (zz (meshgrid-map fun xx yy))) 192 | (surf xx yy zz) 193 | (format-plot nil "set hidden3d") 194 | (format-plot nil "set pm3d") 195 | (format-plot nil "set arrow 1 from -5,-2.1,1.4 to 0,0,1") 196 | (format-plot nil "set label 1 'This is equal to (0,0,1)' at -5,-2,1.5 centre") 197 | (xlabel "x") 198 | (ylabel "y") 199 | (zlabel "z") 200 | (title "Example of a surface plot (the famous sombrero)")) 201 | (close-plot) 202 | (progn 203 | (setf y #(0 4 6.5 6.8 6.5 6.2 6.1 6.05 6.0 6.0)) 204 | (stairs y) 205 | (title "Example of a stairstep plot")) 206 | (progn 207 | (setf x (range (length y))) 208 | (stairs x y "line 1" '(0 1 10) '(0 6 6) "k;line 2;")) 209 | (flet ((e-fun (x) (- 1 (exp (- x))))) 210 | (let* ((x (range 0 6 0.1)) 211 | (y (map 'vector #'e-fun x)) 212 | (xd (range 7)) 213 | (yd (map 'vector #'e-fun xd)) 214 | (sampled (stairs-no-plot xd yd))) 215 | (plot x y "b;continuous;" 216 | (first sampled) (second sampled) "sampled")) 217 | (legend :southeast) 218 | (title "Example of a mixture of continuous and discrete characteristics")) 219 | (progn 220 | (bar :y '(((0.9 0.8 0.3)) 221 | ((0.6 0.7 0.1)))) 222 | (title "Very simple example of a bar plot")) 223 | (progn 224 | (bar :x #(2011 2013 2014) 225 | :y '((#(0.9 0.8 0.3) :label "Values 1") 226 | (#(0.6 0.7 0.1) :label "Values 2"))) 227 | (title "Simple example of a bar plot")) 228 | (progn 229 | (bar :x #("January 2015" "Mars 2015" "June 2015") 230 | :y '((#(0.8 0.9 -0.3) :color "blue" :label "Values 1") 231 | (#(0.7 0.65 0.5) :color "red" :label "Values 2") 232 | (#(0.75 0.4 0.1) :color "cyan" :label "Values 3") 233 | (#(0.6 0.5 0.2) :color "green" :label "Values 4")) 234 | :width 0.5) 235 | (axis '(t t -0.5 1)) 236 | (xlabel "Year of the event") 237 | (ylabel "Result") 238 | (grid nil) 239 | (title "Another example of a bar plot")) 240 | (progn 241 | (bar :x #("January 2015" "Mars 2015" "June 2015") 242 | :y '((#(0.8 0.9 -0.3) :color "blue" :label "Values 1") 243 | (#(0.7 0.65 0.5) :color "red" :label "Values 2") 244 | (#(0.75 0.4 0.1) :color "cyan" :label "Values 3") 245 | (#(0.6 0.5 0.2) :color "green" :label "Values 4")) 246 | :width 0.5 247 | :gap 4) 248 | (axis '(t t -0.5 1)) 249 | (xlabel "Year of the event") 250 | (ylabel "Result") 251 | (grid nil) 252 | (title "Use of the gap parameter in a grouped bar plot (gap = 4.0)")) 253 | (progn 254 | (bar :x #("January 2015" "Mars 2015" "June 2015") 255 | :y '((#(0.8 0.9 -0.3) :color "blue" :label "Values 1") 256 | (#(0.7 0.65 0.5) :color "red" :label "Values 2") 257 | (#(0.75 0.4 0.1) :color "cyan" :label "Values 3") 258 | (#(0.6 0.5 0.2) :color "green" :label "Values 4")) 259 | :width 1.2) 260 | (axis '(t t -0.5 1)) 261 | (xlabel "Year of the event") 262 | (ylabel "Result") 263 | (grid nil) 264 | (title "Use of the width parameter in a grouped bar plot (width = 1.2)")) 265 | (progn 266 | (bar :x #("John" "Paul" "Mary") 267 | :y '((#(0.8 0.9 0.3) :color "blue" :label "Values 1") 268 | (#(0.7 0.65 0.5) :color "red" :label "Values 2") 269 | (#(0.75 0.4 0.1) :color "cyan" :label "Values 3") 270 | (#(0.6 0.5 0.2) :color "green" :label "Values 4")) 271 | :width 0.5 272 | :style "stacked") 273 | (axis '(t t 0 3)) 274 | (xlabel "Student") 275 | (ylabel "Result") 276 | (title "Example of a stacked bar plot")) 277 | (close-plot) 278 | (or "The following works if you copy data.txt and data.csv 279 | from vgplot's source directory to your directory") 280 | (when (cl-fad:file-exists-p "data.txt") 281 | (plot-file "data.txt")) 282 | (when (cl-fad:file-exists-p "data.csv") 283 | (plot-file "data.csv")) 284 | (when (cl-fad:file-exists-p "data.csv") 285 | (plot (first (load-data-file "data.csv"))) 286 | (text 2 -1 "load-data-file returns data from a csv file")) 287 | (close-all-plots))))) 288 | -------------------------------------------------------------------------------- /docs/vgplot.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | API for VGPLOT 6 | 39 | 53 | 54 |
55 |
API for package: 56 | vgplot
57 |
58 |
# 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 | 
86 |
87 |
88 | -Variables
89 |
90 |
91 |
92 | *debug*: 93 | NIL 94 | variable
95 |
96 |
Actvate debugging when true.
97 |
98 |
99 | *gnuplot-binary*: 100 | "gnuplot" 101 | variable
102 |
103 |
Gnuplot binary. Change when gnuplot not in path.
104 |
105 |
106 | -Functions
107 |
108 |
109 |
110 | 3d-plot 111 | &rest vals 112 | function
113 |
114 |
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'.
119 |
120 |
121 | axis 122 | &optional limit-list 123 | compiled-function
124 |
125 |
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.
132 |
133 |
134 | bar 135 | &key x y (style grouped) (width 0.8) (gap 2.0) 136 | function
137 |
138 |
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)
157 |
158 |
159 | close-all-plots 160 | 161 | function
162 |
163 |
Close all connected gnuplots
164 |
165 |
166 | close-plot 167 | 168 | function
169 |
170 |
Close connected gnuplot
171 |
172 |
173 | demo 174 | 175 | compiled-function
176 |
177 |
Show usecases of vgplot.
178 |
179 |
180 | figure 181 | 182 | function
183 |
184 |
Add a new plot window to a current one.
185 |
186 |
187 | format-plot 188 | print? text &rest args 189 | function
190 |
191 |
Send a command directly to active gnuplot process, return gnuplots response
192 | print also response to stdout if print? is true
193 |
194 |
195 | grid 196 | style &key (replot t) 197 | compiled-function
198 |
199 |
Add grid to plot if style t, otherwise remove grid.
200 | If key parameter replot is true (default) run an additional replot thereafter.
201 |
202 |
203 | legend 204 | &rest options 205 | compiled-function
206 |
207 |
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
225 |
226 |
227 | load-data-file 228 | fname 229 | compiled-function
230 |
231 |
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.
235 |
236 |
237 | loglog 238 | &rest vals 239 | function
240 |
241 |
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.
243 |
244 |
245 | meshgrid-map 246 | fun xx yy 247 | compiled-function
248 |
249 |
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.
252 |
253 |
254 | meshgrid-x 255 | x y 256 | compiled-function
257 |
258 |
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.
263 |
264 |
265 | meshgrid-y 266 | x y 267 | compiled-function
268 |
269 |
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.
274 |
275 |
276 | new-plot 277 | 278 | function
279 |
280 |
Add a new plot window to a current one.
281 |
282 |
283 | plot 284 | &rest vals 285 | function
286 |
287 |
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 | 
332 |
333 |
334 | plot-file 335 | data-file &key (x-col) 336 | function
337 |
338 |
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
342 |
343 |
344 | print-plot 345 | filename &key terminal 346 | function
347 |
348 |
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 | 
359 |
360 |
361 | range 362 | a &optional b (step 1) 363 | compiled-function
364 |
365 |
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)
369 |
370 |
371 | replot 372 | 373 | compiled-function
374 |
375 |
Send the replot command to gnuplot, i.e. apply all recent changes in the plot.
376 |
377 |
378 | semilogx 379 | &rest vals 380 | function
381 |
382 |
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.
384 |
385 |
386 | semilogy 387 | &rest vals 388 | function
389 |
390 |
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.
392 |
393 |
394 | stairs 395 | &rest vals 396 | compiled-function
397 |
398 |
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.
409 |
410 |
411 | stairs-no-plot 412 | yx &optional y 413 | compiled-function
414 |
415 |
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.
422 |
423 |
424 | subplot 425 | rows cols index 426 | function
427 |
428 |
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 | 
442 |
443 |
444 | surf 445 | &rest vals 446 | function
447 |
448 |
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 | 
494 |
495 |
496 | text 497 | x y text-string &key (tag) (horizontalalignment left) (rotation 0) (font) (fontsize) (color 498 | ) 499 | compiled-function
500 |
501 |
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 | 
522 |
523 |
524 | text-delete 525 | &rest tags 526 | compiled-function
527 |
528 |
Delete text labels specified by tags.
529 | A tag is the number of the text label you get when running (text-show-label).
530 |
531 |
532 | text-show-label 533 | 534 | compiled-function
535 |
536 |
Show text labels. This is useful to get the tag number for (text-delete)
537 |
538 |
539 | title 540 | str &key (replot t) 541 | compiled-function
542 |
543 |
Add title str to plot. If key parameter replot is true (default)
544 | run an additional replot thereafter.
545 |
546 |
547 | xlabel 548 | str &key (replot t) 549 | compiled-function
550 |
551 |
Add x axis label. If key parameter replot is true (default)
552 | run an additional replot thereafter.
553 |
554 |
555 | ylabel 556 | str &key (replot t) 557 | compiled-function
558 |
559 |
Add y axis label. If key parameter replot is true (default)
560 | run an additional replot thereafter.
561 |
562 |
563 | zlabel 564 | str &key (replot t) 565 | compiled-function
566 |
567 |
Add z axis label. If key parameter replot is true (default)
568 | run an additional replot thereafter.
569 | -------------------------------------------------------------------------------- /package.lisp: -------------------------------------------------------------------------------- 1 | ;;;; package.lisp 2 | 3 | (defpackage #:vgplot 4 | (:use :cl) 5 | (:import-from :ltk :do-execute) 6 | (:import-from :cl-fad :with-output-to-temporary-file) 7 | (:documentation "# vgplot 8 | 9 | This common lisp library is an interface to the gnuplot plotting 10 | utility. 11 | 12 | The intention of the API is to resemble to some of the plot commands 13 | of octave or matlab. 14 | 15 | ## Usage 16 | 17 | (asdf:load-system :vgplot) or (ql:quickload :vgplot) 18 | 19 | (vgplot:plot '(1 2 3) '(0 -2 17)) 20 | 21 | For examples run the demo function: 22 | 23 | (vgplot:demo) 24 | 25 | and see API documentation in docs/vgplot.html or on http://volkers.github.io/vgplot/vgplot.html 26 | 27 | ## License 28 | 29 | Copyright (C) 2013 - 2022 Volker Sarodnick 30 | 31 | mail: (remove #\\y (subseq \"avoidspamyvolykerysyar@gymyx.net\" 9)) 32 | 33 | GNU General Public License 34 | ") 35 | (:export :*debug* 36 | :*gnuplot-binary* 37 | :axis 38 | :bar 39 | :close-all-plots 40 | :close-plot 41 | :demo 42 | :figure 43 | :format-plot 44 | :grid 45 | :legend 46 | :load-data-file 47 | :loglog 48 | :meshgrid-x 49 | :meshgrid-y 50 | :meshgrid-map 51 | :new-plot 52 | :plot 53 | :plot-file 54 | :print-plot 55 | :replot 56 | :range 57 | :semilogx 58 | :semilogy 59 | :stairs 60 | :stairs-no-plot 61 | :subplot 62 | :surf 63 | :text 64 | :text-delete 65 | :text-show-label 66 | :title 67 | :xlabel 68 | :ylabel 69 | :zlabel 70 | :3d-plot)) 71 | -------------------------------------------------------------------------------- /test.lisp: -------------------------------------------------------------------------------- 1 | ;;;; test.lisp 2 | 3 | #| 4 | This is the test environment for vgplot, an interface to the gnuplot utility. 5 | Copyright (C) 2013 - 2020 Volker Sarodnick 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | |# 20 | 21 | (in-package :cl-user) 22 | 23 | (defpackage :vgplot/test 24 | (:use :cl :lisp-unit :vgplot) 25 | (:export :run)) 26 | 27 | 28 | (in-package #:vgplot/test) 29 | 30 | (setq lisp-unit:*print-failures* t) 31 | 32 | (define-test test-get-separator 33 | (assert-equal t (vgplot::get-separator "30 4 87")) 34 | (assert-equal t (vgplot::get-separator " 1499 -938 -535 31")) 35 | (assert-equal t (vgplot::get-separator "1.9e3 4 87")) 36 | (assert-equal nil (vgplot::get-separator " # comment")) 37 | (assert-equal nil (vgplot::get-separator "")) 38 | (assert-equal #\, (vgplot::get-separator "30,4,87")) 39 | (assert-equal #\; (vgplot::get-separator "30.04567;4;87 # comment")) 40 | (assert-equal #\, (vgplot::get-separator " 30.0d19 ,4 , 87"))) 41 | 42 | (define-test test-count-data-columns 43 | (assert-equal 0 (vgplot::count-data-columns "")) 44 | (assert-equal 1 (vgplot::count-data-columns "17")) 45 | (assert-equal 2 (vgplot::count-data-columns "17 987654321")) ; TAB used 46 | (assert-equal 4 (vgplot::count-data-columns " 1499 -938 -535 31")) 47 | (assert-equal 2 (vgplot::count-data-columns "1.7d179, 87654321" #\,)) 48 | (assert-equal 20 (vgplot::count-data-columns "1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0" #\,)) 49 | (assert-equal 2 (vgplot::count-data-columns " 1.7e179 ; 87654321 # comment" #\;)) 50 | ) 51 | 52 | (define-test test-parse-floats 53 | (assert-equalp '(1 2 3) (vgplot::parse-floats "1, 2, 3" #\,)) 54 | (assert-equalp '(3.0d20 2 3) (vgplot::parse-floats "30.0d19; 2; 3" #\;)) 55 | (assert-equalp '(1 2 3) (vgplot::parse-floats "1 2 3" t)) 56 | (assert-equalp '(1499 -938 -535 31) (vgplot::parse-floats " 1499 -938 -535 31" t)) 57 | (assert-equalp '(1.3254 2 300000.0) (vgplot::parse-floats "1.3254 2 3e5" t))) 58 | 59 | (define-test test-stairs-no-plot 60 | (assert-equalp (list #(0) #(1)) (vgplot:stairs-no-plot #(1))) 61 | (assert-equalp '(#(0 1 1 2 2 3 3 4 4) #(3 3 2 2 7 7 1 1 6)) 62 | (vgplot:stairs-no-plot #(3 2 7 1 6))) 63 | (assert-equalp '(#(0 1 1 2 2 3 3 4 4) #(3 3 2 2 7 7 1 1 6)) 64 | (vgplot:stairs-no-plot '(3 2 7 1 6))) 65 | (assert-equalp '(#(0 1 1 2 2 3 3 4 4) #(3 3 2 2 7 7 1 1 6)) 66 | (vgplot:stairs-no-plot '(0 1 2 3 4) '(3 2 7 1 6))) 67 | (assert-equalp '(#(1 3 3) #(4.0 4.0 -1)) 68 | (vgplot:stairs-no-plot #(1 3) #(4.0 -1))) 69 | (assert-equalp '(#(1 3 3) #(17.0 17.0 -1.0)) 70 | (vgplot:stairs-no-plot #(1 3) '(17.0 -1.0)))) 71 | 72 | (define-test test-parse-label 73 | (assert-equalp "with lines title '' " 74 | (vgplot::parse-label "")) 75 | (assert-equalp "with lines title '' " 76 | (vgplot::parse-label ";")) 77 | (assert-equalp "with lines title '' " 78 | (vgplot::parse-label ";;")) 79 | (assert-equalp "with lines title 'title' " 80 | (vgplot::parse-label ";title;")) 81 | (assert-equalp "with lines title 'title' " 82 | (vgplot::parse-label ";title")) 83 | (assert-equalp "add-styles title 'title' " 84 | (vgplot::parse-label ";title;add-styles")) 85 | (assert-equalp "add-styles title 'title' " 86 | (vgplot::parse-label "+b;title;add-styles")) 87 | (assert-equalp "with lines linecolor rgb 'red' title 'title' " 88 | (vgplot::parse-label "-r;title;")) 89 | (assert-equalp "with points linecolor rgb 'green' title 'title' " 90 | (vgplot::parse-label "g+;title;")) 91 | (assert-equalp "with lines dt '. . ' linecolor rgb 'blue' title 'title' " 92 | (vgplot::parse-label ":b;title;")) 93 | (assert-equalp "with dots linecolor rgb 'cyan' title 'title' " 94 | (vgplot::parse-label ".c;title;")) 95 | (assert-equalp "with points linecolor rgb 'black' title 'title' " 96 | (vgplot::parse-label "+k;title;")) 97 | (assert-equalp "with circles linecolor rgb 'yellow' title 'title' " 98 | (vgplot::parse-label "oy;title;")) 99 | (assert-equalp "with circles linecolor rgb 'magenta' title 'title' " 100 | (vgplot::parse-label "om;title;")) 101 | (assert-equalp "with dots linecolor rgb 'white' title 'title' " 102 | (vgplot::parse-label ".w;title;")) 103 | (assert-equalp "with dots linecolor rgb '#112233' title 'title' " 104 | (vgplot::parse-label ".#112233;title;")) 105 | (assert-equalp "with points linecolor rgb '#112233' title 'title' " 106 | (vgplot::parse-label "#112233+;title;")) 107 | ) 108 | 109 | (defun run () 110 | (lisp-unit:run-tests :all :vgplot/test)) 111 | -------------------------------------------------------------------------------- /vgplot.asd: -------------------------------------------------------------------------------- 1 | ;;;; vgplot.asd 2 | 3 | (asdf:defsystem :vgplot 4 | :serial t 5 | :description "Interface to gnuplot" 6 | :author "Volker Sarodnick" 7 | :license "GPL" 8 | :depends-on (:ltk :cl-fad :cl-ppcre) 9 | :components ((:file "package") 10 | (:file "vgplot") 11 | (:file "demo"))) 12 | 13 | (asdf:defsystem :vgplot/test 14 | :serial t 15 | :description "Test environment for vgplot" 16 | :author "Volker Sarodnick" 17 | :license "GPL" 18 | :depends-on (:vgplot :lisp-unit) 19 | :components ((:file "test"))) 20 | -------------------------------------------------------------------------------- /vgplot.lisp: -------------------------------------------------------------------------------- 1 | ;;;; vgplot.lisp 2 | 3 | #| 4 | This library is an interface to the gnuplot utility. 5 | Copyright (C) 2013 - 2020 Volker Sarodnick 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | Main author: Volker Sarodnick 21 | 22 | Contributions: Lewis Grozinger, Alexander Radcliffe 23 | |# 24 | 25 | (in-package #:vgplot) 26 | 27 | (defvar *debug* nil 28 | "Actvate debugging when true.") 29 | 30 | (defvar *gnuplot-binary* "gnuplot" 31 | "Gnuplot binary. Change when gnuplot not in path.") 32 | 33 | (defclass plots () 34 | ((plot-stream :initform (open-plot) :accessor plot-stream) 35 | (multiplot-p :initform nil :accessor multiplot-p) 36 | (tmp-file-list :initform nil :accessor tmp-file-list)) 37 | (:documentation "Holding properties of the plot")) 38 | 39 | (defun make-plot () 40 | (make-instance 'plots)) 41 | 42 | (defun open-plot () 43 | "Start gnuplot process and return stream to gnuplot" 44 | (do-execute *gnuplot-binary* nil)) 45 | 46 | (defun read-no-hang (s) 47 | "Read from stream and return string (non blocking)" 48 | (sleep 0.01) ;; not perfect, better idea? 49 | (let ((chars)) 50 | (do ((c (read-char-no-hang s) 51 | (read-char-no-hang s))) 52 | ((null c)) 53 | (push c chars)) 54 | (coerce (nreverse chars) 'string))) 55 | 56 | (defun read-n-print-no-hang (s) 57 | "Read from stream and print directly (non blocking). Return read string" 58 | (princ (read-no-hang s))) 59 | 60 | (defun vectorize (vals) 61 | "Coerce all sequences except strings to simple-vectors" 62 | (mapcar #'(lambda (x) (if (stringp x) 63 | x 64 | (coerce x 'simple-vector))) 65 | vals)) 66 | 67 | (defun vectorize-lists (vals) 68 | "Coerce lists in vals to simple-vectors" 69 | (mapcar #'(lambda (x) (if (listp x) 70 | (coerce x 'simple-vector) 71 | x)) 72 | vals)) 73 | 74 | (defun vectorize-val-list (vals) 75 | "Coerce :x and :y lists in vals to vectors 76 | vals has the form 77 | \(\(:x x :y y :label lbl :color clr) (:x x :y y :label lbl :color clr) ...)" 78 | (mapcar #'vectorize-lists vals)) 79 | 80 | (defun listelize-list (l) 81 | "Coerce sequences in l except strings to lists: 82 | \(listelize-list '(#(1 2 3) #(a b c))) 83 | -> \((1 2 3) (A B C))" 84 | (mapcar #'(lambda (x) (if (stringp x) 85 | x 86 | (coerce x 'list))) 87 | l)) 88 | 89 | (defun min-x-diff (x-l) 90 | "Return minimal difference between 2 consecutive elements in x. 91 | Throw an error if x is not increasing, i.e. difference not bigger than 0" 92 | (let ((min-diff (reduce #'min (map 'simple-vector #'- (subseq x-l 1) x-l)))) 93 | (assert (< 0 min-diff) nil "X has to be increasing") 94 | min-diff)) 95 | 96 | (defun extract-min-x-diff (l) 97 | "l is a list in the form 98 | \((:x x :y y :label lbl :color clr) (:x x :y y :label lbl :color clr) ...). 99 | Return minimal difference of two consecutive x values" 100 | (reduce #'min (map 'list #'min-x-diff (map 'list #'(lambda (l) (getf l :x #(0 1))) l)))) 101 | 102 | (defun parse-vals (vals) 103 | "Parse input values to plot and return grouped list: ((x y lbl-string) (x1 y1 lbl-string)...) 104 | For efficiency reasons return ((y nil lbl-string)(...)) if only y given" 105 | (cond 106 | ((stringp (third vals)) (cons (list (pop vals) (pop vals) (pop vals)) 107 | (parse-vals vals))) 108 | ((stringp (second vals)) (cons (list (pop vals) nil (pop vals)) 109 | (parse-vals vals))) 110 | ((second vals) (cons (list (pop vals) (pop vals) "") 111 | (parse-vals vals))) 112 | (vals (list (list (first vals) nil ""))) ;; special case of plot val to index, i.e. only y exist 113 | (t nil))) 114 | 115 | (defun parse-vals-3d (vals) 116 | "Analogous to parse-vals, but for 3d plots. 117 | Parse input values to 3d-plot and return grouped list: ((x y z lbl-string) (x1 y1 z1 lbl-string) ...) 118 | " 119 | (cond 120 | ((stringp (fourth vals)) (cons (list (pop vals) (pop vals) (pop vals) (pop vals)) 121 | (parse-vals-3d vals))) 122 | 123 | ((third vals) (cons (list (pop vals) (pop vals) (pop vals) "") 124 | (parse-vals-3d vals))) 125 | (t nil))) 126 | 127 | (defun parse-bar-vals (vals) 128 | "Parse input values to plot and return grouped list: ((x y lbl-string) (x1 y1 lbl-string)...) 129 | Create x if not existing." 130 | (cond 131 | ((stringp (third vals)) (cons (list (pop vals) (pop vals) (pop vals)) 132 | (parse-bar-vals vals))) 133 | ;; insert x if only y given 134 | ((stringp (second vals)) (cons (list (range (length (first vals))) (pop vals) (pop vals)) 135 | (parse-bar-vals vals))) 136 | ((second vals) (cons (list (pop vals) (pop vals) "") 137 | (parse-bar-vals vals))) 138 | ;; insert x because only y given 139 | (vals (list (list (range (length (first vals))) (first vals) ""))) 140 | (t nil))) 141 | 142 | (defun parse-label (lbl) 143 | "Parse label string e.g. \"-k;label;add-styles\" and return style command, e.g.: \"with points linecolor rgb 'red' title 'label'\". 144 | If add-styles isn't empty it will replace all styles and color strings." 145 | (let ((style "with lines") 146 | (color "") 147 | (rgb) 148 | (title "") 149 | (start-title (or (search ";" lbl) -1)) ;; -1 because subseq jumps over first ; 150 | (end-title (or (search ";" lbl :from-end t) (length lbl)))) 151 | (when (>= start-title end-title) 152 | ;; only one semicolon found, use the part after the first one as title 153 | (setf end-title (length lbl))) 154 | (setf title (subseq lbl (1+ start-title) end-title)) 155 | (if (< (1+ end-title) (length lbl)) 156 | ;; there is something after the second ; this is used directly as the style, all other styles skipped 157 | (setf style (subseq lbl (1+ end-title))) 158 | ;; nothing after second ; -> ordinary parsing of styles and colors 159 | (when (> start-title 0) 160 | (loop for c across (subseq lbl 0 start-title) do 161 | (if rgb 162 | (progn ;; process rgb string, e.g. "#ff12ff", i.e. 6 hex digits with heading # 163 | (setf rgb (concatenate 'string rgb (string c))) 164 | (when (= 7 (length rgb)) 165 | (setf color (format nil "linecolor rgb '~A'" rgb)) 166 | (setf rgb nil))) 167 | (ecase c 168 | (#\- (setf style "with lines")) 169 | (#\: (setf style "with lines dt '. . '")) 170 | (#\. (setf style "with dots")) 171 | (#\+ (setf style "with points")) 172 | (#\o (setf style "with circles")) 173 | (#\r (setf color "linecolor rgb 'red'")) 174 | (#\g (setf color "linecolor rgb 'green'")) 175 | (#\b (setf color "linecolor rgb 'blue'")) 176 | (#\c (setf color "linecolor rgb 'cyan'")) 177 | (#\k (setf color "linecolor rgb 'black'")) 178 | (#\y (setf color "linecolor rgb 'yellow'")) 179 | (#\m (setf color "linecolor rgb 'magenta'")) 180 | (#\w (setf color "linecolor rgb 'white'")) 181 | (#\# (setf rgb "#"))))))) ; use rgb string 182 | (format nil "~A ~A title '~A' " style color title))) 183 | 184 | (defun get-color-cmd (color) 185 | "Return color command string or empty string" 186 | (if color 187 | (format nil " linecolor rgb \"~A\"" color) 188 | "")) 189 | 190 | (defun get-tc-rgb-cmd (color-name) 191 | "Return textcolor rgb command string for color name or unchanged color-string when not found" 192 | (cond 193 | ((equal color-name "red") "tc rgb '#ff0000'") 194 | ((equal color-name "green") "tc rgb '#00ff00'") 195 | ((equal color-name "blue") "tc rgb '#0000ff'") 196 | ((equal color-name "cyan") "tc rgb '#00ffff'") 197 | ((equal color-name "black") "tc rgb '#000000'") 198 | ((equal color-name "yellow") "tc rgb '#ffff00'") 199 | ((equal color-name "magenta") "tc rgb '#ff00ff'") 200 | ((equal color-name "white") "tc rgb '#ffffff'") 201 | (t color-name))) ; unchanged string if not found 202 | 203 | 204 | (defun parse-floats (line sep) 205 | "Parse string line and return the found numbers separated by separator or whitespace when 206 | separator is just t" 207 | (if (characterp sep) 208 | ;; separator is a character 209 | (let ((c-list) 210 | (r-list)) 211 | (loop for c across line do 212 | (cond 213 | ((eql c #\# ) (loop-finish)) ; rest of line is comment 214 | ((eql c #\ )) ; ignore space 215 | ((eql c #\ )) ; ignore tab 216 | ((eql c sep) (progn 217 | (push (read-from-string (nreverse (coerce c-list 'string))) r-list) 218 | (setf c-list nil))) 219 | (t (push c c-list)))) 220 | ;; add also number after the last sep: 221 | (push (read-from-string (nreverse (coerce c-list 'string)) nil) r-list) 222 | (nreverse r-list)) 223 | ;; separator is only t: 224 | (with-input-from-string (s line) 225 | (loop 226 | :for num := (read s nil nil) 227 | :while num 228 | :collect num)))) 229 | 230 | (defun v-format (format-string v) 231 | "Convert members of sequence v to strings using format-string and 232 | concatenates the result." 233 | (reduce #'(lambda (s-1 s-2) (concatenate 'string s-1 s-2)) 234 | (map 'simple-vector #'(lambda (x) (format nil format-string x)) v))) 235 | 236 | (defun make-del-tmp-file-function (tmp-file-list) 237 | "Return a function that removes the files in tmp-file-list." 238 | #'(lambda () 239 | (loop for name in tmp-file-list do 240 | (when (probe-file name) 241 | (delete-file name))))) 242 | 243 | (defun del-tmp-files (tmp-file-list) 244 | "Delete files in tmp-file-list and return nil" 245 | (funcall (make-del-tmp-file-function tmp-file-list)) 246 | nil) ; not really needed but makes it clear 247 | 248 | (defun add-del-tmp-files-to-exit-hook (tmp-file-list) 249 | "If possible, add delete of tmp files to exit hooks. 250 | \(implemented on sbcl and clisp)" 251 | #+sbcl (push (make-del-tmp-file-function tmp-file-list) sb-ext:*exit-hooks*) 252 | #+clisp (push (make-del-tmp-file-function tmp-file-list) custom:*fini-hooks*) 253 | #-(or sbcl clisp) (declare (ignore tmp-file-list))) 254 | 255 | (defun get-separator (s) 256 | "Return the used separator in data string 257 | t for whitespace \(standard separator in gnuplot) 258 | c separator character 259 | nil comment line \(or empty line)" 260 | (let ((data-found nil)) ; to handle comment-only lines 261 | (loop for c across s do 262 | (cond 263 | ((digit-char-p c) (setf data-found t)) 264 | ((eql c #\#) (loop-finish)) 265 | ;; ignore following characters 266 | ((eql c #\.)) 267 | ((eql c #\e)) ; e could be inside a number in exponential form 268 | ((eql c #\E)) 269 | ((eql c #\d)) ; even d could be inside a number... 270 | ((eql c #\D)) 271 | ((eql c #\-)) 272 | ((eql c #\+)) 273 | ((eql c #\ )) 274 | ((eql c #\ )) 275 | (t (return-from get-separator c)))) 276 | (if data-found 277 | t ; there was data before EOL or comment but no other separator 278 | nil))) ; comment-only line 279 | 280 | (defun count-data-columns (s &optional (separator)) 281 | "Count data columns in strings like \"1 2 3 # comment\", separators 282 | could be a variable number of spaces, tabs or the optional separator" 283 | (let ((sep t) (num 0)) 284 | (loop for c across s do 285 | (cond 286 | ((eql c #\# ) (return)) 287 | ((eql c (or separator #\Tab)) (setf sep t)) 288 | ((eql c #\Space) (setf sep t)) 289 | (t (when sep 290 | (incf num) 291 | (setf sep nil))))) 292 | num)) 293 | 294 | (defun stairs (&rest vals) 295 | "Produce a stairstep plot. 296 | vals could be: y plot y over its index 297 | x y plot y = f(x) 298 | x y label-string plot y = f(x) using label-string as label 299 | following parameters add curves to same plot e.g.: 300 | x y label x1 y1 label1 ... 301 | 302 | For the syntax of label-string see documentation of plot command. 303 | 304 | If you only want to prepare the sequences for later plot, see 305 | function stairs-no-plot." 306 | (let ((par-list)) 307 | (labels ((construct-plist (p-list pars) 308 | (cond 309 | ((null pars) 310 | (nreverse p-list)) 311 | ((stringp (first pars)) 312 | (push (first pars) p-list) 313 | (construct-plist p-list (rest pars))) 314 | ((= 1 (length pars)) 315 | (multiple-value-bind (x y) (values-list (stairs-no-plot 316 | (first pars))) 317 | (push x p-list) 318 | (push y p-list) 319 | (construct-plist p-list (rest pars)))) 320 | (t 321 | (multiple-value-bind (x y) (values-list (stairs-no-plot 322 | (first pars) (second pars))) 323 | (push x p-list) 324 | (push y p-list) 325 | (construct-plist p-list (rest (rest pars)))))))) 326 | (format-plot *debug* "set nologscale") ; ensure that there is no log scaling from plotting before active 327 | (apply #'do-plot (construct-plist par-list (vectorize vals)))))) 328 | 329 | (defun stairs-no-plot (yx &optional y) 330 | "Prepare a stairstep plot, but don't actually plot it. 331 | Return a list of 2 sequences, x and y, usable for the later plot. 332 | 333 | If one argument is given use it as y sequence, there x are the indices. 334 | If both arguments are given use yx as x and y is y. 335 | 336 | If you want to plot the stairplot directly, see function stairs." 337 | (cond 338 | ((not y) 339 | (let* ((y (coerce yx 'simple-vector)) 340 | (len (length y)) 341 | (x (range len))) 342 | (stairs-no-plot x y))) 343 | ((or (not (simple-vector-p yx)) (not (simple-vector-p y))) 344 | (stairs-no-plot (coerce yx 'simple-vector) (coerce y 'simple-vector))) 345 | (t (let* 346 | ((len (min (length yx) (length y))) 347 | (xx (make-array (1- (* 2 len)))) 348 | (yy (make-array (1- (* 2 len)))) 349 | (xi 0) 350 | (yi 0) 351 | (i 1)) 352 | (if (= len 1) 353 | (list yx y) 354 | (progn 355 | ;; setup start 356 | ;; x0 y0 357 | ;; y0 358 | (setf (svref xx xi) (svref yx 0)) 359 | (setf (svref yy yi) (svref y 0)) 360 | (setf (svref yy (incf yi)) (svref y 0)) 361 | ;; main loop 362 | (loop for ii from 1 below (1- len) do 363 | (progn 364 | (setf (svref xx (incf xi)) (svref yx i)) 365 | (setf (svref xx (incf xi)) (svref yx i)) 366 | (setf (svref yy (incf yi)) (svref y i)) 367 | (setf (svref yy (incf yi)) (svref y i)) 368 | (incf i))) 369 | ;; and finalize 370 | ;; xl 371 | ;; xl yl 372 | (setf (svref xx (incf xi)) (svref yx i)) 373 | (setf (svref yy (incf yi)) (svref y i)) 374 | (setf (svref xx (incf xi)) (svref yx i)) 375 | (list xx yy))))))) 376 | 377 | (let ((plot-list nil) ; List holding not active plots 378 | (act-plot nil)) ; actual plot 379 | (defun format-plot (print? text &rest args) 380 | "Send a command directly to active gnuplot process, return gnuplots response 381 | print also response to stdout if print? is true" 382 | (unless act-plot 383 | (setf act-plot (make-plot))) 384 | (apply #'format (plot-stream act-plot) text args) 385 | (fresh-line (plot-stream act-plot)) 386 | (force-output (plot-stream act-plot)) 387 | (if print? 388 | (progn 389 | (when *debug* 390 | (apply #'format t text args) 391 | (format t "~%")) 392 | (read-n-print-no-hang (plot-stream act-plot))) 393 | (read-no-hang (plot-stream act-plot)))) 394 | (defun close-plot () 395 | "Close connected gnuplot" 396 | (when act-plot 397 | (format (plot-stream act-plot) "quit~%") 398 | (force-output (plot-stream act-plot)) 399 | (close (plot-stream act-plot)) 400 | (del-tmp-files (tmp-file-list act-plot)) 401 | (setf act-plot (pop plot-list)))) 402 | (defun close-all-plots () 403 | "Close all connected gnuplots" 404 | (close-plot) 405 | (when act-plot 406 | (close-all-plots))) 407 | (defun new-plot () 408 | "Add a new plot window to a current one." 409 | (when act-plot 410 | (push act-plot plot-list) 411 | (setf act-plot (make-plot)))) 412 | (defun do-plot (&rest vals) 413 | "Do the actual plot. For documentation see doc string of the macro plot" 414 | (if act-plot 415 | (unless (multiplot-p act-plot) 416 | (setf (tmp-file-list act-plot) (del-tmp-files (tmp-file-list act-plot)))) 417 | (setf act-plot (make-plot))) 418 | (let ((val-l (parse-vals (vectorize vals))) 419 | (plt-cmd)) 420 | (loop for pl in val-l do 421 | (push (with-output-to-temporary-file (tmp-file-stream :template "vgplot-%.dat") 422 | (if (null (second pl)) ;; special case plotting to index 423 | (map nil #'(lambda (a) (format tmp-file-stream "~,,,,,,'eE~%" a)) (first pl)) 424 | (map nil #'(lambda (a b) (format tmp-file-stream "~,,,,,,'eE ~,,,,,,'eE~%" a b)) 425 | (first pl) (second pl)))) 426 | (tmp-file-list act-plot)) 427 | (setf plt-cmd (concatenate 'string (if plt-cmd 428 | (concatenate 'string plt-cmd ", ") 429 | "plot ") 430 | (format nil "\"~A\" ~A "(first (tmp-file-list act-plot)) (parse-label (third pl)))))) 431 | (format-plot *debug* "set grid~%") 432 | (when *debug* 433 | (format t "~A~%" plt-cmd)) 434 | (format (plot-stream act-plot) "~A~%" plt-cmd) 435 | (force-output (plot-stream act-plot)) 436 | (add-del-tmp-files-to-exit-hook (tmp-file-list act-plot))) 437 | (read-n-print-no-hang (plot-stream act-plot))) 438 | (defun plot (&rest vals) 439 | "Plot y = f(x) on active plot, create plot if needed. 440 | vals could be: y plot y over its index 441 | y label-string plot y over its index using label-string as label 442 | x y plot y = f(x) 443 | x y label-string plot y = f(x) using label-string as label 444 | following parameters add curves to same plot e.g.: 445 | x y label x1 y1 label1 ... 446 | label: 447 | A simple label in form of \"text\" is printed directly. 448 | 449 | A label with style commands: label in form \"styles;text;add-styles\": 450 | 451 | In the ordinary case add-styles will be empty. 452 | 453 | styles can be (combinations possible): 454 | \"-\" lines 455 | \":\" dotted lines 456 | \".\" dots 457 | \"+\" points 458 | \"o\" circles 459 | \"r\" red 460 | \"g\" green 461 | \"b\" blue 462 | \"c\" cyan 463 | \"k\" black 464 | \"y\" yellow 465 | \"m\" magenta 466 | \"w\" white 467 | \"#RRGGBB\" sets an arbitrary 24-bit RGB color (have to be exactly 6 digits) 468 | 469 | e.g.: 470 | (plot x y \"r+;red values;\") plots y = f(x) as red points with the 471 | label \"red values\" 472 | 473 | If add-styles is not empty, the string in add-styles is send unmodyfied to gnuplot, other styles and colors are skipped. 474 | This is useful to set more complicated styles, e.g.: 475 | 476 | (plot x y \";use of additional styles;with linespoints pt 7 ps 2 lc 'red'\") 477 | plots y = f(x) as lines with red points, pointsize 2 with the 478 | label \"use of additional styles\" 479 | 480 | To use a backslash in add-styles you have to quote it, e.g.: 481 | 482 | (plot x y \";;with points pt '\\U+2299'\") 483 | " 484 | (format-plot *debug* "set nologscale") 485 | (multiple-value-call #'do-plot (values-list vals))) 486 | (defun 3d-plot (&rest vals) 487 | "Do a 3d plot. Uses gnuplot's 'splot'. 488 | The inputs are similar to 'plot', but with some key differences: 489 | vals could be: x y z 490 | x y z label-string 491 | style commands in the label-string work the same as in 'plot'." 492 | (format-plot *debug* "set nologscale") 493 | (if act-plot 494 | (unless (multiplot-p act-plot) 495 | (setf (tmp-file-list act-plot) (del-tmp-files (tmp-file-list act-plot)))) 496 | (setf act-plot (make-plot))) 497 | (let ((val-l (parse-vals-3d (vectorize vals))) 498 | (plt-cmd)) 499 | (loop for pl in val-l do 500 | ;; (format t "~a~%" val-l) 501 | (push (with-output-to-temporary-file (tmp-file-stream :template "vgplot-%.dat") 502 | (if (null (second pl)) ;; special case plotting to index 503 | (map nil #'(lambda (a) (format tmp-file-stream "~,,,,,,'eE~%" a)) (first pl)) 504 | (map nil #'(lambda (a b c) (format tmp-file-stream "~,,,,,,'eE ~,,,,,,'eE ~,,,,,,'eE~%" a b c)) 505 | (first pl) (second pl) (third pl)))) 506 | (tmp-file-list act-plot)) 507 | (setf plt-cmd (concatenate 'string (if plt-cmd 508 | (concatenate 'string plt-cmd ", ") 509 | "splot ") 510 | (format nil "\"~A\" ~A "(first (tmp-file-list act-plot)) (parse-label (fourth pl)))))) 511 | (format-plot *debug* "set grid~%") 512 | (when *debug* 513 | (format t "~A~%" plt-cmd)) 514 | (format (plot-stream act-plot) "~A~%" plt-cmd) 515 | (force-output (plot-stream act-plot)) 516 | (add-del-tmp-files-to-exit-hook (tmp-file-list act-plot))) 517 | (read-n-print-no-hang (plot-stream act-plot))) 518 | (defun surf (&rest vals) 519 | "Plot a 3-D surface mesh. 520 | Vals could be: zz [label-string] 521 | xx yy zz [label-string] 522 | 523 | For label-string see documentation of plot. 524 | 525 | xx, yy and zz are 2 dimensional arrays usually produced by meshgrid-x, meshgrid-y and meshgrid-map. 526 | All 3 arrays have to have the same form where the rows follow the x direction and the columns the y. 527 | xx: #2A((x0 x0 x0 ... x0) 528 | (x1 x1 x1 ... x1) 529 | ... 530 | (xn xn xn ... xn)) 531 | yy: #2A((y0 y1 y2 ... ym) 532 | (y0 y1 y2 ... ym) 533 | ... 534 | (y0 y1 y2 ... ym)) 535 | zz: #2A((z00 z01 z02 ... z0m) 536 | (z10 z11 z12 ... z1m) 537 | ... 538 | (zn0 zn1 zn2 ... znm)) 539 | 540 | Example 1: Plot some measurement data without providing xx and yy: 541 | (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))))) 542 | (vgplot:surf zz \"r;array plotted without providing xx or yy;\")) 543 | 544 | Example 2: Plot some measurement data: 545 | (let* ((x #(1.0 2.0 3.0)) 546 | (y #(0.0 2.0 4.0 6.0)) 547 | (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)))) 548 | (xx (vgplot:meshgrid-x x y)) 549 | (yy (vgplot:meshgrid-y x y))) 550 | (vgplot:surf xx yy zz)) 551 | 552 | Example 3: Plot a function z = f(x,y), e.g. the sombrero function: 553 | (let* ((eps double-float-epsilon) 554 | (fun #'(lambda (x y) (/ (sin (sqrt (+ (* x x) (* y y) eps))) (sqrt (+ (* x x) (* y y) eps))))) 555 | (x (vgplot:range -8 8 0.2)) 556 | (y (vgplot:range -8 8 0.2)) 557 | (xx (vgplot:meshgrid-x x y)) 558 | (yy (vgplot:meshgrid-y x y)) 559 | (zz (vgplot:meshgrid-map fun xx yy))) 560 | (vgplot:surf xx yy zz) 561 | (vgplot:format-plot nil \"set hidden3d\") 562 | (vgplot:format-plot nil \"set pm3d\") 563 | (vgplot:replot)) 564 | " 565 | ;; handle plotting without povided xx and yy 566 | (if (or (= 1 (length vals)) 567 | (and (= 2 (length vals)) (stringp (second vals)))) 568 | ;; handle plotting without povided xx and yy 569 | (let* ((zz (first vals)) 570 | (x (range (array-dimension zz 0))) 571 | (y (range (array-dimension zz 1))) 572 | (xx (meshgrid-x x y)) 573 | (yy (meshgrid-y x y))) 574 | (if (= 1 (length vals)) 575 | (surf xx yy zz) 576 | (surf xx yy zz (second vals)))) 577 | ;; handle xx yy zz potting 578 | (progn 579 | (format-plot *debug* "set nologscale") 580 | (if act-plot 581 | (unless (multiplot-p act-plot) 582 | (setf (tmp-file-list act-plot) (del-tmp-files (tmp-file-list act-plot)))) 583 | (setf act-plot (make-plot))) 584 | (let ((val-l (parse-vals-3d vals)) 585 | (plt-cmd)) 586 | (loop for pl in val-l do 587 | (push (with-output-to-temporary-file (tmp-file-stream :template "vgplot-%.dat") 588 | (let* ((xx (first pl)) 589 | (yy (second pl)) 590 | (zz (third pl)) 591 | (x-len (array-dimension xx 0)) 592 | (y-len (array-dimension xx 1))) 593 | (dotimes (y-idx y-len) 594 | (progn 595 | (dotimes (x-idx x-len) 596 | (format tmp-file-stream "~,,,,,,'eE ~,,,,,,'eE ~,,,,,,'eE~%" 597 | (aref xx x-idx y-idx) 598 | (aref yy x-idx y-idx) 599 | (aref zz x-idx y-idx))) 600 | (format tmp-file-stream "~%"))))) ; an empty line between the surface lines 601 | (tmp-file-list act-plot)) 602 | (setf plt-cmd (concatenate 'string (if plt-cmd 603 | (concatenate 'string plt-cmd ", ") 604 | "splot ") 605 | (format nil "\"~A\" ~A "(first (tmp-file-list act-plot)) (parse-label (fourth pl)))))) 606 | (format-plot *debug* "set grid~%") 607 | (when *debug* 608 | (format t "~A~%" plt-cmd)) 609 | (format (plot-stream act-plot) "~A~%" plt-cmd) 610 | (force-output (plot-stream act-plot)) 611 | (add-del-tmp-files-to-exit-hook (tmp-file-list act-plot))) 612 | (read-n-print-no-hang (plot-stream act-plot))))) 613 | (defun print-plot (filename &key terminal) 614 | "Print the actual plot into filename (a pathname). 615 | Use the (optional) terminal or if not provided, 616 | use the extension of filename to guess the terminal type. 617 | Guessing of terminals works currently for: gif, pdf, png 618 | 619 | Examples: (vgplot:print-plot #p\"plot.pdf\") 620 | (vgplot:print-plot #p\"plot.eps\" :terminal \"epscairo\") 621 | 622 | It is possible to give additional parameters inside the terminal parameter, e.g.: 623 | (vgplot:print-plot #p\"plot.pdf\" :terminal \"pdfcairo size \\\"5cm\\\",\\\"5cm\\\"\") 624 | " 625 | (assert (pathnamep filename)) 626 | (let* ((filename-string (namestring filename)) 627 | (extension (cl-ppcre:scan-to-strings "\\w+$" filename-string)) 628 | (terminals '(("gif" . "gif") 629 | ("pdf" . "pdfcairo") 630 | ("png" . "png")))) 631 | (vgplot:format-plot *debug* "set terminal push") 632 | (vgplot:format-plot *debug* "set terminal ~A" 633 | (or terminal 634 | (cdr (assoc extension terminals :test #'string=)) 635 | (error "Provide a terminal to print to (no terminal given and guessing failed)!"))) 636 | (vgplot:format-plot *debug* "set output \"~A\"" filename-string) 637 | (vgplot:format-plot *debug* "refresh") 638 | (vgplot:format-plot *debug* "unset output") 639 | ;; and back to original terminal: 640 | (vgplot:format-plot *debug* "set terminal pop"))) 641 | 642 | (defun semilogx (&rest vals) 643 | "Produce a two-dimensional plot using a logarithmic scale for the X axis. 644 | See the documentation of the plot command for a description of the arguments." 645 | (format-plot *debug* "set logscale x") 646 | (format-plot *debug* "set nologscale y") 647 | (multiple-value-call #'do-plot (values-list vals))) 648 | (defun semilogy (&rest vals) 649 | "Produce a two-dimensional plot using a logarithmic scale for the Y axis. 650 | See the documentation of the plot command for a description of the arguments." 651 | (format-plot *debug* "set nologscale x") 652 | (format-plot *debug* "set logscale y") 653 | (multiple-value-call #'do-plot (values-list vals))) 654 | (defun loglog (&rest vals) 655 | "Produce a two-dimensional plot using logarithmic scales scale for both axis. 656 | See the documentation of the plot command for a description of the arguments." 657 | (format-plot *debug* "set logscale xy") 658 | (multiple-value-call #'do-plot (values-list vals))) 659 | (defun bar (&key x y (style "grouped") (width 0.8) (gap 2.0)) 660 | "Create a bar plot y = f(x) on active plot, create plot if needed. 661 | :x (optional) vector or list of x strings or numbers 662 | plot to index if not provided 663 | :y list of y '((y &key :label :color) (y &key :label :color) ...) 664 | y vector or list of y values 665 | :label string for legend label (optional) 666 | :color string defining the color (optional); 667 | must be known by gnuplot, e.g. blue, green, red or cyan 668 | :style (optional) \"grouped\" (default) or \"stacked\" 669 | :width (optional) width of the bars where 1.0 means to fill the space completely 670 | (for the gap in style \"grouped\" see parameter gap) 671 | :gap (optional, only used in style \"grouped\") the gap between the groups 672 | in units of width of one boxwidth 673 | e.g.: 674 | \(bar :x #(\"Item 1\" \"Item 2\" \"Item 3\") 675 | :y '((#(0.3 0.2 0.1) :label \"Values\" :color \"blue\") 676 | (#(0.1 0.2 0.3) :label \"Values\" :color \"red\")) 677 | :style \"stacked\" 678 | :width 0.6)" 679 | (labels 680 | ((combine-col (l) 681 | "Build a list combining corresponding elements in previded sublists 682 | e.g. \(combine-col '((1 2 3) (a b c d) (x y z))) 683 | -> \((1 A X) (2 B Y) (3 C Z))" 684 | (let ((first-part (loop for x in l collect (first x))) 685 | (rest-part (loop for x in l collect (rest x)))) 686 | (if (some #'null rest-part) 687 | (list first-part) 688 | (cons first-part (combine-col rest-part))))) 689 | (extract-y-val (l) 690 | "Extracts the y values from the supplied y list and splices the result, e.g. 691 | \(extract-y-val '((#(0.9 0.8 0.3) :label \"Values\" :color \"blue\") 692 | (#(0.7 0.8 0.9) :label \"Values\" :color \"blue\"))) 693 | -> ((0.9 0.7) (0.8 0.8) (0.3 0.9))" 694 | (combine-col (listelize-list (mapcar #'first l))))) 695 | (let ((style-cmd (cond ((equal style "grouped") (format nil "set style histogram clustered gap ~A" gap)) 696 | ((equal style "stacked") "set style histogram rowstacked") 697 | (t (error "Unknown style \"~A\"!" style)))) 698 | (plt-file) 699 | (n-bars (length y))) 700 | (if act-plot 701 | (setf (tmp-file-list act-plot) (del-tmp-files (tmp-file-list act-plot))) 702 | (setf act-plot (make-plot))) 703 | (unless x 704 | ;; plot to index 705 | (setf x (range (length (extract-y-val y))))) 706 | (push (with-output-to-temporary-file (tmp-file-stream :template "vgplot-%.dat") 707 | (map nil #'(lambda (a b) 708 | (format tmp-file-stream "\"~A\" ~A~%" a (v-format " ~,,,,,,'eE" b))) 709 | x (extract-y-val y))) 710 | (tmp-file-list act-plot)) 711 | (setf plt-file (first (tmp-file-list act-plot))) 712 | (format-plot *debug* "set style fill solid 1.00 border lt -1") 713 | (format-plot *debug* "set grid") 714 | (format-plot *debug* "set boxwidth ~A absolute" width) 715 | (format-plot *debug* style-cmd) 716 | (format-plot *debug* "set style data histograms") 717 | ;; gnuplot command shall be e.g.: 718 | ;; plot 'data.txt' using 2:xtic(1) linecolor rgb 'blue' title 'label1', 'data.txt' using 3:xtic(1) linecolor rgb 'green' title 'label2' 719 | (format-plot *debug* 720 | (reduce #'(lambda (s1 s2) (concatenate 'string s1 s2)) 721 | (loop 722 | for col-num from 2 to (1+ n-bars) ;; columns start at 2 in the command 723 | for l-num from 0 to (1- n-bars) ;; but the lists starts at 0 724 | collect 725 | ;; y is e.g. '((#(1 3 2) :label "Lbl1" :color "blue") (#(2 1 3) :label "Lbl2" :color "green")) 726 | (let* ((color-cmd (get-color-cmd (getf (rest (nth l-num y)) :color))) 727 | (label (getf (rest (nth l-num y)) :label ""))) 728 | (format nil (if (eql l-num 0) 729 | "plot \'~A\' using ~A:xtic(1) ~A title \'~A\'" 730 | ", \'~A\' using ~A:xtic(1) ~A title \'~A\'") 731 | plt-file col-num color-cmd label))))) 732 | (axis '(t t 0 t)) 733 | (force-output (plot-stream act-plot)) 734 | (add-del-tmp-files-to-exit-hook (tmp-file-list act-plot)) 735 | (read-n-print-no-hang (plot-stream act-plot))))) 736 | (defun subplot (rows cols index) 737 | "Set up a plot grid with rows by cols subwindows and use location index for next plot command. 738 | The plot index runs row-wise. First all the columns in a row are 739 | filled and then the next row is filled. 740 | 741 | For example, a plot with 2 rows by 3 cols will have following plot indices: 742 | 743 | +-----+-----+-----+ 744 | | 0 | 1 | 2 | 745 | +-----+-----+-----+ 746 | | 3 | 4 | 5 | 747 | +-----+-----+-----+ 748 | 749 | Observe, gnuplot doesn't allow interactive mouse commands in multiplot mode. 750 | " 751 | (when (or (< index 0) 752 | (>= index (* rows cols))) 753 | (progn 754 | (format t "Index out of bound~%") 755 | (return-from subplot nil))) 756 | (let ((x-size (coerce (/ 1 cols) 'float)) 757 | (y-size (coerce (/ 1 rows) 'float)) 758 | (x-orig) 759 | (y-orig)) 760 | (setf x-orig (* x-size (mod index cols))) 761 | (setf y-orig (- 1 (* y-size (+ 1 (floor (/ index cols)))))) 762 | ;; 763 | (unless act-plot 764 | (setf act-plot (make-plot))) 765 | (unless (multiplot-p act-plot) 766 | (format-plot *debug* "set multiplot~%") 767 | (setf (multiplot-p act-plot) t)) 768 | (read-n-print-no-hang (plot-stream act-plot)) 769 | (format-plot *debug* "set size ~A,~A~%" x-size y-size) 770 | (read-n-print-no-hang (plot-stream act-plot)) 771 | (format-plot *debug* "set origin ~A,~A~%" x-orig y-orig) 772 | (read-n-print-no-hang (plot-stream act-plot)) 773 | (force-output (plot-stream act-plot)) 774 | (read-n-print-no-hang (plot-stream act-plot)))) 775 | (defun plot-file (data-file &key (x-col)) 776 | "Plot data-file directly, datafile must hold columns separated by spaces, tabs or commas 777 | \(other separators may work), use with-lines style. 778 | :x-col (optional) column to use as x values. 779 | plot to index if not provided" 780 | (let ((c-num) 781 | (separator) 782 | (cmd-string "")) 783 | (with-open-file (in data-file :direction :input) 784 | (setf separator (do ((c (get-separator (read-line in)) 785 | (get-separator (read-line in)))) 786 | ((or c) c))) ; comment lines return nil, drop them 787 | ;; use only lines with more than zero columns, i.e. drop comment lines 788 | (setf c-num (do ((num (count-data-columns (read-line in) separator) 789 | (count-data-columns (read-line in) separator))) 790 | ((> num 0) num)))) 791 | 792 | (flet ((add-cmd (data-file x-col y-col current-cmd) 793 | (unless (eql x-col y-col) 794 | (let ((plot-or-comma (if (string= current-cmd "") "plot" ","))) 795 | (if x-col 796 | (format nil "~A \"~A\" using ~A:($~A) with lines" 797 | plot-or-comma data-file x-col y-col) 798 | (format nil "~A \"~A\" using ($~A) with lines" 799 | plot-or-comma data-file y-col)))))) 800 | (loop 801 | for i from 1 to c-num 802 | do 803 | (setf cmd-string 804 | (concatenate 'string cmd-string 805 | (add-cmd data-file x-col i cmd-string))))) 806 | 807 | (unless act-plot 808 | (setf act-plot (make-plot))) 809 | (format-plot *debug* "set grid~%") 810 | (when (characterp separator) 811 | (format-plot *debug* "set datafile separator \"~A\"~%" separator)) 812 | (format-plot *debug* "~A~%" cmd-string) 813 | (when (characterp separator) 814 | (format-plot *debug* "set datafile separator~%")) ; reset separator 815 | (force-output (plot-stream act-plot))) 816 | (read-n-print-no-hang (plot-stream act-plot))) 817 | ) 818 | 819 | ;; figure is an alias to new-plot (because it's used that way in octave/matlab) 820 | (setf (symbol-function 'figure) #'new-plot) 821 | 822 | (defun replot () 823 | "Send the replot command to gnuplot, i.e. apply all recent changes in the plot." 824 | (format-plot *debug* "clear") ;; maybe only for multiplot needed? 825 | (format-plot *debug* "replot")) 826 | 827 | (defun grid (style &key (replot t)) 828 | "Add grid to plot if style t, otherwise remove grid. 829 | If key parameter replot is true (default) run an additional replot thereafter." 830 | (if style 831 | (format-plot *debug* "set grid") 832 | (format-plot *debug* "unset grid")) 833 | (when replot 834 | (replot))) 835 | 836 | (defun legend (&rest options) 837 | "Provide options to the legend aka keys. 838 | :show Show legend (default) 839 | :hide Hide legend 840 | :boxon Use box around the legend 841 | :boxoff Don't use a box (default) 842 | :left Title left of sample line (default) 843 | :right Title right of sample line 844 | :north Place legend center top 845 | :south Center bottom 846 | :east Right center 847 | :west Left center 848 | :northeast Right top (default) 849 | :northwest Left top 850 | :southeast Right bottom 851 | :southwest Left bottom 852 | :at x y Place legend at position x,y 853 | :inside Place legend inside the plot (default) 854 | :outside Place legend outside the plot" 855 | (let* ((opt-tbl '(:show " on" 856 | :hide " off" 857 | :boxon " box" 858 | :boxoff " nobox" 859 | :left " noreverse" 860 | :right " reverse" 861 | :north " center top" 862 | :south " center bottom" 863 | :east " right center" 864 | :west " left center" 865 | :northeast " right top" 866 | :northwest " left top" 867 | :southeast " right bottom" 868 | :southwest " left bottom" 869 | :inside " inside" 870 | :outside " outside"))) 871 | (labels ((parse-opts (opts) 872 | (cond 873 | ((null opts) "") 874 | ;; handle special case ":at x y" 875 | ((eq :at (first opts)) 876 | (let ((x (second opts)) 877 | (y (third opts))) 878 | (assert (and (numberp x) (numberp y)) nil 879 | "Coordinates x=~A y=~A after :at have to be numbers!" x y) 880 | (concatenate 'string (format nil " at ~A,~A" x y) 881 | (parse-opts (rest (rest (rest opts))))))) 882 | ;; handle standard cases 883 | (t (concatenate 'string 884 | (or (getf opt-tbl (first opts)) 885 | (error "Unrecognized option ~A" (first opts))) 886 | (parse-opts (rest opts))))))) 887 | (format-plot *debug* "set key ~A" (parse-opts options)) 888 | (replot)))) 889 | (defun title (str &key (replot t)) 890 | "Add title str to plot. If key parameter replot is true (default) 891 | run an additional replot thereafter." 892 | (format-plot *debug* "set title \"~A\"" str) 893 | (format-plot *debug* "show title") 894 | (when replot 895 | (replot))) 896 | 897 | (defun set-label (label str replot) 898 | "Set label label to string, replot if replot is true." 899 | (format-plot *debug* "set ~A \"~A\"" label str) 900 | (format-plot *debug* "show ~A" label) 901 | (when replot 902 | (replot))) 903 | 904 | (defun xlabel (str &key (replot t)) 905 | "Add x axis label. If key parameter replot is true (default) 906 | run an additional replot thereafter." 907 | (set-label "xlabel" str replot)) 908 | 909 | (defun ylabel (str &key (replot t)) 910 | "Add y axis label. If key parameter replot is true (default) 911 | run an additional replot thereafter." 912 | (set-label "ylabel" str replot)) 913 | 914 | (defun zlabel (str &key (replot t)) 915 | "Add z axis label. If key parameter replot is true (default) 916 | run an additional replot thereafter." 917 | (set-label "zlabel" str replot)) 918 | 919 | (defun text (x y text-string &key (tag) (horizontalalignment "left") (rotation 0) (font) (fontsize) (color "")) 920 | "Add text label text-string at position x,y 921 | optional: 922 | :tag nr label number specifying which text label to modify 923 | (integer you get when running (text-show-label)) 924 | :horizontalalignment \"left\"(default), \"center\" or \"right\" 925 | :rotation degree rotate text by this angle in degrees (default 0) [if the terminal can do so] 926 | :font \"\" use this font, e.g. :font \"Times\" [terminal depending, gnuplot help 927 | recommends: http://fontconfig.org/fontconfig-user.html for more information] 928 | :fontsize nr 929 | :color \"color\" one of red, green, blue, cyan, black, yellow or white 930 | an unrecogniced color is send unchanged to gnuplot, this can be used to get other colors or effects, e.g: 931 | \"tc rgb '#112233'\" gives color with the RGB code 0x112233 (0xRRGGBB) 932 | \"tc lt 1\" gives the same color as line 1 933 | 934 | Observe, it could alter the font of the labels (aka legend or key in 935 | gnuplot terms) if you change font or fontsize of a text field. To 936 | explicitly chose fontsize (or font) for the label you could use: 937 | 938 | \(format-plot t \"set key font \\\",10\\\"\"\) 939 | \(replot\) 940 | " 941 | (let ((cmd-str "set label ") 942 | (tag-str (and tag (format nil " ~a " tag))) 943 | (text-str (format nil " \"~a\" " text-string)) 944 | (at-str (format nil " at ~a,~a " x y)) 945 | (al-str (format nil " ~a " horizontalalignment)) 946 | (rot-str (format nil " rotate by ~a " rotation)) 947 | (font-str (and (or font fontsize) 948 | (format nil " font \"~a,~a\" " (or font "") (or fontsize "")))) 949 | (color-str (format nil " ~a " (get-tc-rgb-cmd color)))) 950 | (format-plot *debug* (concatenate 'string cmd-str tag-str text-str at-str al-str rot-str font-str color-str))) 951 | (replot)) 952 | 953 | (defun text-show-label () 954 | "Show text labels. This is useful to get the tag number for (text-delete)" 955 | (format-plot t "show label")) 956 | 957 | (defun text-delete (&rest tags) 958 | "Delete text labels specified by tags. 959 | A tag is the number of the text label you get when running (text-show-label)." 960 | (loop for tag in tags do 961 | (format-plot *debug* "unset label ~a" tag)) 962 | (replot)) 963 | 964 | (defun parse-axis (axis-s) 965 | "Parse gnuplot string e.g. 966 | \" set xrange [ * : 4.00000 ] noreverse nowriteback # (currently [1.00000:] )\" 967 | and return range as a list of floats, e.g. '(1.0 3.0)" 968 | ;; number before colon 969 | (cl-ppcre:register-groups-bind (min) ("([-\\d.]+) ?:" axis-s) 970 | ;; number efter colon 971 | (cl-ppcre:register-groups-bind (max) (": ?([-\\d.]+)" axis-s) 972 | (mapcar (lambda (s) (float (read-from-string s))) (list min max))))) 973 | 974 | (defun axis (&optional limit-list) 975 | "Set axis to limit-list and return actual limit-list, limit-list could be: 976 | '(xmin xmax) or '(xmin xmax ymin ymax), 977 | values can be: 978 | a number: use it as the corresponding limit 979 | nil: do not change this limit 980 | t: autoscale this limit 981 | without limit-list do return current axis." 982 | (unless (null limit-list) 983 | ;; gather actual limits 984 | (let* ((is-limit (append (parse-axis (format-plot *debug* "show xrange")) 985 | (parse-axis (format-plot *debug* "show yrange")))) 986 | (limit (loop for i to 3 collect 987 | (let ((val (nth i limit-list))) 988 | (cond ((numberp val) (format nil "~,,,,,,'eE" val)) 989 | ((or val) "*") ; autoscale 990 | (t (nth i is-limit))))))) ; same value again 991 | (format-plot *debug* "set xrange [~a:~a]" (first limit) (second limit)) 992 | (format-plot *debug* "set yrange [~a:~a]" (third limit) (fourth limit)) 993 | (replot))) 994 | ;; and return current axis settings 995 | (append (parse-axis (format-plot *debug* "show xrange")) 996 | (parse-axis (format-plot *debug* "show yrange")))) 997 | 998 | (defun load-data-file (fname) 999 | "Return a list of found vectors (one vector for one column) in data file fname 1000 | \(e.g. a csv-file). 1001 | Datafile fname must hold columns separated by spaces, tabs or commas \(other separators may work), 1002 | content after # till end of line is assumed to be a comment and ignored." 1003 | (let ((c-num) 1004 | (separator) 1005 | (val-list)) 1006 | (with-open-file (in fname :direction :input) 1007 | (setf separator (do ((c (get-separator (read-line in)) 1008 | (get-separator (read-line in)))) 1009 | ((or c) c))) ; comment lines return nil, drop them 1010 | ;; use only lines with more than zero columns, i.e. drop comment lines 1011 | (setf c-num (do ((num (count-data-columns (read-line in) separator) 1012 | (count-data-columns (read-line in) separator))) 1013 | ((> num 0) num)))) 1014 | (dotimes (i c-num) 1015 | (push (make-array 100 :element-type 'number :adjustable t :fill-pointer 0) val-list)) 1016 | 1017 | (with-open-file (in fname :direction :input) 1018 | (let ((float-list) 1019 | (line-num 0)) 1020 | (do ((line (read-line in nil 'eof) 1021 | (read-line in nil 'eof))) 1022 | ((eql line 'eof)) 1023 | (incf line-num) 1024 | (setf float-list (parse-floats line separator)) 1025 | (setf float-list (remove-if-not 'numberp float-list)) 1026 | (cond 1027 | ((null (first float-list))) ; ignore comment lines 1028 | ((/= c-num (length float-list)) 1029 | (error "Number of columns wrong in ~a on line ~a!" fname line-num)) 1030 | (t (mapcar #'vector-push-extend float-list val-list)))))) 1031 | (vectorize val-list))) 1032 | 1033 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1034 | ;; exported utilities 1035 | 1036 | (defun range (a &optional b (step 1)) 1037 | "Return vector of values in a certain range: 1038 | \(range limit\) return natural numbers below limit 1039 | \(range start limit\) return ordinary numbers starting with start below limit 1040 | \(range start limit step\) return numbers starting with start, successively adding step untill reaching limit \(excluding\)" 1041 | (let ((len) (vec)) 1042 | (unless b 1043 | (setf b a 1044 | a 0)) 1045 | (setf len (ceiling (/ (- b a) step))) 1046 | (setf vec (make-array len)) 1047 | (loop for i below len do 1048 | (setf (svref vec i) a) 1049 | (incf a step)) 1050 | vec)) 1051 | 1052 | (defun meshgrid-x (x y) 1053 | "Helper function for a surface plot (surf). 1054 | Given vectors of X and Y coordinates, return array XX for a 2-D grid. 1055 | The columns of XX are copies of X. 1056 | Usually used in combination with meshgrid-y. 1057 | See surf for examples." 1058 | (let ((x-len (length x)) 1059 | (y-len (length y))) 1060 | (make-array (list x-len y-len) :initial-contents (loop with yi for xi across x do (setf yi (make-sequence 'vector y-len :initial-element xi)) collect yi)))) 1061 | 1062 | (defun meshgrid-y (x y) 1063 | "Helper function for a surface plot (surf). 1064 | Given vectors of X and Y coordinates, return array YY for a 2-D grid. 1065 | The rows of YY are copies of Y. 1066 | Usually used in combination with meshgrid-x. 1067 | See surf for examples." 1068 | (let ((x-len (length x)) 1069 | (y-len (length y))) 1070 | (make-array (list x-len y-len) :initial-contents (make-sequence 'vector x-len :initial-element y)))) 1071 | 1072 | (defun meshgrid-map (fun xx yy) 1073 | "Helper function for a surface plot (surf). 1074 | Map fun to every pair of elements of the arrays xx and yy and return the corresponding array zz. 1075 | See surf for an example." 1076 | (let* ((x-len (array-dimension xx 0)) 1077 | (y-len (array-dimension xx 1)) 1078 | (zz (make-array (list x-len y-len)))) 1079 | (dotimes (i (array-total-size xx)) 1080 | (setf (row-major-aref zz i) 1081 | (funcall fun 1082 | (row-major-aref xx i) 1083 | (row-major-aref yy i)))) 1084 | zz)) 1085 | 1086 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1087 | ;; other utilities 1088 | 1089 | (defun make-doc () 1090 | "Update README and html documentation. Load cl-api before use." 1091 | (let ((apigen nil)) 1092 | (ignore-errors 1093 | ;; dependency to cl-api not defined in asd-file because I don't want getting 1094 | ;; this dependency (make-doc is internal and should only be used by developer) 1095 | ;; ignore that :api-gen is probably not loaded in standard case 1096 | (setq apigen (find-symbol "API-GEN" 'cl-api))) 1097 | (if apigen 1098 | (with-open-file (stream "README" :direction :output :if-exists :supersede) 1099 | (write-string (documentation (find-package :vgplot) 't) stream) 1100 | (funcall apigen :vgplot "docs/vgplot.html")) 1101 | (error "CL-API not loaded, but needed for make-doc!")))) 1102 | 1103 | 1104 | --------------------------------------------------------------------------------