Changeset 1619 for trunk/examples/objects/api/python/plot
- Timestamp:
- Nov 25, 2009, 10:40:35 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/objects/api/python/plot
r1610 r1619 35 35 Notes: None 36 36 Code Example: 37 {{{ 38 lib = Rappture.Library() 39 p = Rappture.Plot(lib) 40 }}} 37 41 38 42 Rappture.Plot(o) … … 43 47 Notes: None 44 48 Code Example: 49 {{{ 50 lib = Rappture.Library() 51 p1 = Rappture.Plot(lib) 52 p2 = Rappture.Plot(p1) 53 }}} 45 54 46 55 … … 55 64 val, if provided, is used to set the object name 56 65 Code Example: 66 {{{ 67 p = Rappture.Plot() 68 p.name() 69 # "" 70 p.name("fdfactor") 71 p.name() 72 # "fdfactor" 73 }}} 57 74 58 75 p.path([val]) … … 66 83 val, if provided, is used to set the object path 67 84 Code Example: 85 {{{ 86 p = Rappture.Plot() 87 p.path() 88 # "" 89 p.path("output") 90 p.path() 91 # "output" 92 }}} 68 93 69 94 p.label([val]) … … 76 101 val, if provided, is used to set the object label 77 102 Code Example: 103 {{{ 104 p = Rappture.Plot() 105 p.label() 106 # "" 107 p.label("Fermi-Dirac Factor") 108 p.label() 109 # "Fermi-Dirac Factor" 110 }}} 78 111 79 112 p.desc([val]) … … 88 121 val, if provided, is used to set the object description 89 122 Code Example: 123 {{{ 124 p = Rappture.Plot() 125 p.desc() 126 # "" 127 p.desc("A plot of the Fermi-Dirac Factor") 128 p.desc() 129 # "A plot of the Fermi-Dirac Factor" 130 }}} 90 131 91 132 p.hints([val]) … … 98 139 val, if provided, is used to set the object hints 99 140 Code Example: 141 {{{ 142 p = Rappture.Plot() 143 p.hints() 144 # "" 145 p.hints("no hints") 146 p.hint() 147 # "no hints" 148 }}} 100 149 101 150 p.color([val]) … … 108 157 val, if provided, is used to set the object color 109 158 Code Example: 159 {{{ 160 p = Rappture.Plot() 161 p.color() 162 # "" 163 p.color("no color") 164 p.color() 165 # "no color" 166 }}} 110 167 111 168 p.property(key[, val]) … … 117 174 Notes: A copy val is stored in the property database 118 175 Code Example: 176 {{{ 177 p = Rappture.Plot() 178 p.property("name") 179 # "" 180 p.property("name","fdfactor") 181 # "fdfactor" 182 p.name() 183 # "fdfactor" 184 }}} 119 185 120 186 p.propremove(key) … … 125 191 Notes: None 126 192 Code Example: 193 {{{ 194 p = Rappture.Plot() 195 p.name("fdfactor") 196 p.property("name") 197 # "fdfactor" 198 p.propremove("name") 199 # "fdfactor" 200 p.property("name") 201 # "" 202 }}} 127 203 128 204 p.add(x, y, fmt, name) … … 138 214 this follows matlab's formatting rules. 139 215 Code Example: 216 {{{ 217 x = list() 218 y = list() 219 for i in range(0,10) : 220 x.append(i) 221 y.append(pow(i,2)) 222 223 p = Rappture.Plot() 224 p.add(x, y, fmt="g:o", name="xsquared") 225 # a single curve, named "xsquared", is stored in the plot object 226 }}} 140 227 141 228 p.add(c, name) … … 147 234 Notes: Curve object should not be deleted by user? 148 235 Code Example: 236 {{{ 237 x = list() 238 y = list() 239 for i in range(0,10) : 240 x.append(i) 241 y.append(pow(i,2)) 242 243 c = Rappture.Curve() 244 245 c.axis(name="xvals", label="X Values", 246 desc="Values along the X axis" val=x) 247 248 c.axis(name="yvals", label="Y Values", 249 desc="Values along the Y axis", val=y) 250 251 p = Rappture.Plot() 252 p.add(c, name="xsquared") 253 # a single curve, named "xsquared", is stored in the plot object 254 }}} 149 255 150 256 p.count() … … 154 260 Notes: None 155 261 Code Example: 262 {{{ 263 x = list() 264 y1 = list() 265 y2 = list() 266 for i in range(0,10) : 267 x.append(i) 268 y1.append(pow(i,2)) 269 y2.append(pow(i,3)) 270 } 271 272 p = Rappture.Plot() 273 p.add(x, y1, format="g:o", name="xsquared") 274 p.add(x, y2, format="b-o", name="xcubed") 275 print p.count() 276 # 2 277 }}} 156 278 157 279 p.curve(name) … … 162 284 Notes: None 163 285 Code Example: 286 {{{ 287 x = list() 288 y1 = list() 289 y2 = list() 290 for i in range(0,10) : 291 x.append(i) 292 y1.append(pow(i,2)) 293 y2.append(pow(i,3)) 294 } 295 296 p = Rappture.Plot() 297 p.add(x, y1, format="g:o", name="xsquared") 298 p.add(x, y2, format="b-o", name="xcubed") 299 c = p.curve("xsquared") 300 print c.name() 301 # xsquared 302 }}} 164 303 165 304 p.getNthCurve(n) … … 171 310 Notes: None 172 311 Code Example: 312 {{{ 313 x = list() 314 y1 = list() 315 y2 = list() 316 for i in range(0,10) : 317 x.append(i) 318 y1.append(pow(i,2)) 319 y2.append(pow(i,3)) 320 } 321 322 p = Rappture.Plot() 323 p.add(x, y1, format="g:o", name="xsquared") 324 p.add(x, y2, format="b-o", name="xcubed") 325 c = p.getNthCurve(1) 326 print c.name() 327 # xcubed 328 }}} 173 329 174 330 p.vvalue([...]) … … 184 340 hintKey=hintVal 185 341 Code Example: 342 {{{ 343 x = list() 344 y1 = list() 345 y2 = list() 346 for i in range(0,10) : 347 x.append(i) 348 y1.append(pow(i,2)) 349 y2.append(pow(i,3)) 350 } 351 352 p = Rappture.Plot() 353 p.add(x, y1, format="g:o", name="xsquared") 354 p.add(x, y2, format="b-o", name="xcubed") 355 print p.vvalue() 356 # [ [ [1 2 3 4 5 6 7 8 9 10] \ 357 # [1 4 9 16 25 36 49 64 81 100] ] \ 358 # [ [1 2 3 4 5 6 7 8 9 10] \ 359 # [1 8 27 64 125 216 343 512 729 1000] ] ] 360 361 }}} 186 362 187 363 p.random(); … … 193 369 max if they were specified. 194 370 Code Example: 371 {{{ 372 p = Rappture.Plot() 373 p.random() 374 # plot is filed with random data 375 print p.vvalue() 376 # [ [ [1 2 3 4 5 6 7 8 9 10] \ 377 # [1 2 3 4 5 6 7 8 9 10] ] \ 378 # [ [1 2 3 4 5 6 7 8 9 10] \ 379 # [1 4 9 16 25 36 49 64 81 100] ] \ 380 # [ [1 2 3 4 5 6 7 8 9 10] \ 381 # [1 8 27 64 125 216 343 512 729 1000] ] ] 382 print p.count() 383 # 3 384 385 }}} 195 386 196 387 p.diff(o); … … 202 393 Notes: None 203 394 Code Example: 395 {{{ 396 p1 = Rappture.Plot() 397 p1.random() 398 # plot is filed with random data 399 print p.vvalue() 400 # [ [ [1 2 3 4 5 6 7 8 9 10] \ 401 # [1 4 9 16 25 36 49 64 81 100] ] ] 402 403 p2 = Rappture.Plot() 404 p2.random() 405 # plot is filed with random data 406 print p.vvalue() 407 # [ [ [1 2 3 4 5 6 7 8 9 10] \ 408 # [1 8 27 64 125 216 343 512 729 1000] ] ] 409 410 diffs = p1.diff(p2) 411 # diffs is a list of tuples or list of lists. 412 413 for ctype, prop, oVal, nVal in diffs { 414 print "%s %s %s %s" % (ctype, prop, oVal, nVal)" 415 } 416 # c name temperature Ef 417 # c units K eV 418 # c def 300 4.5 419 # c min 0 0 420 # c max 500 10 421 # c label "Ambiant Temperature" "Fermi Level" 422 # c desc "Temperature of the environment" "Energy at center of distribution" 423 # 424 # Note that this function will find a difference in the 425 # minimum values even though they are numerically equal. 426 # This is because the objects have different units that 427 # are not compatible. If compatible units were found, 428 # n2's values would have been converted to n1's units 429 # for each comparison. 430 # 431 # if diffs is a flat list, user would need to write something like this: 432 # for i in range(len(diffs)/4): 433 # ctype, prop, oVal, nVal = diffs[(i*4):(i*4)+4] 434 # print ctype, prop, oVal, nVal 435 436 }}} 204 437 205 438 p.configure(as, c) … … 218 451 Notes: object is configured based on values in "c" 219 452 Code Example: 453 {{{ 454 p = Rappture.Plot() 455 xmldata = """ 456 <?xml version="1.0"> 457 <curve id="xsquared"> 458 <about> 459 <group>auto34</group> 460 <label>x squared</label> 461 <description>x values are squared</description> 462 <type></type> 463 <format>g:o</format> 464 </about> 465 <xaxis> 466 <label>x values</label> 467 <description>values being squared</description> 468 <units></units> 469 <scale>linear</scale> 470 </xaxis> 471 <yaxis> 472 <label>y values</label> 473 <description>squared values</description> 474 <units></units> 475 <scale>linear</scale> 476 </yaxis> 477 <component> 478 <xy> 1 1 479 2 4 480 3 9 481 4 16 482 5 25 483 6 36 484 7 49 485 8 64 486 9 81 487 10 100 488 </xy> 489 </component> 490 </curve> 491 <curve id="xcubed"> 492 <about> 493 <group>auto34</group> 494 <label>x cubed</label> 495 <description>x values are cubed</description> 496 <type></type> 497 <format>b-o</format> 498 </about> 499 <xaxis> 500 <label>x values</label> 501 <description>values being cubed</description> 502 <units></units> 503 <scale>linear</scale> 504 </xaxis> 505 <yaxis> 506 <label>y values</label> 507 <description>cubed values</description> 508 <units></units> 509 <scale>linear</scale> 510 </yaxis> 511 <component> 512 <xy> 1 1 513 2 8 514 3 27 515 4 64 516 5 125 517 6 216 518 7 343 519 8 512 520 9 729 521 10 1000 522 </xy> 523 </component> 524 </curve> 525 """ 526 527 p.configure(RPCONFIG_XML,xmldata) 528 print p.vvalue() 529 # [ [ [1 2 3 4 5 6 7 8 9 10] \ 530 # [1 4 9 16 25 36 49 64 81 100] ] \ 531 # [ [1 2 3 4 5 6 7 8 9 10] \ 532 # [1 8 27 64 125 216 343 512 729 1000] ] ] 533 534 for cur in range(p.count()): 535 c = p.getNthCurve(cur) 536 print c.name() 537 print c.label() 538 print c.desc() 539 print c.format() 540 for axisCnt in range(c.dims()): 541 axis = c.getNthAxis(axisCnt) 542 print axis.label() 543 print axis.desc() 544 print axis.units() 545 print axis.scale() 546 print axis.data() 547 # xsquared 548 # x squared 549 # x values are squared 550 # g:o 551 # xaxis 552 # x values 553 # values being squared 554 # 555 # linear 556 # [1 2 3 4 5 6 7 8 9 10] 557 # yaxis 558 # y values 559 # squared values 560 # 561 # linear 562 # [1 4 9 16 25 36 49 64 81 100] 563 # xcubed 564 # x cubed 565 # x values are cubed 566 # b-o 567 # xaxis 568 # x values 569 # values being cubed 570 # 571 # linear 572 # [1 2 3 4 5 6 7 8 9 10] 573 # yaxis 574 # y values 575 # cubed values 576 # 577 # linear 578 # [1 8 27 64 125 216 343 512 729 1000] 579 580 }}} 220 581 221 582 p.dump(as, c) … … 234 595 Notes: None 235 596 Code Example: 597 {{{ 598 x = list() 599 y1 = list() 600 y2 = list() 601 for i in range(0,10) : 602 x.append(i) 603 y1.append(pow(i,2)) 604 y2.append(pow(i,3)) 605 } 606 607 p = Rappture.Plot() 608 p.add(x, y1, format="g:o", name="xsquared") 609 p.add(x, y2, format="b-o", name="xcubed") 610 print p.dump(RPCONFIG_XML) 611 # <curve id="xsquared"> 612 # <about> 613 # <group>auto34</group> 614 # <label></label> 615 # <description></description> 616 # <type>(null)</type> 617 # <format>g:o</format> 618 # </about> 619 # <xaxis> 620 # <label></label> 621 # <description></description> 622 # <units></units> 623 # <scale>linear</scale> 624 # </xaxis> 625 # <yaxis> 626 # <label></label> 627 # <description></description> 628 # <units></units> 629 # <scale>linear</scale> 630 # </yaxis> 631 # <component> 632 # <xy> 1 1 633 # 2 4 634 # 3 9 635 # 4 16 636 # 5 25 637 # 6 36 638 # 7 49 639 # 8 64 640 # 9 81 641 # 10 100 642 # </xy> 643 # </component> 644 # </curve> 645 # <curve id="xcubed"> 646 # <about> 647 # <group>unnamed</group> 648 # <label></label> 649 # <description></description> 650 # <type>(null)</type> 651 # <format>b-o</format> 652 # </about> 653 # <xaxis> 654 # <label></label> 655 # <description></description> 656 # <units></units> 657 # <scale>linear</scale> 658 # </xaxis> 659 # <yaxis> 660 # <label></label> 661 # <description></description> 662 # <units></units> 663 # <scale>linear</scale> 664 # </yaxis> 665 # <component> 666 # <xy> 1 1 667 # 2 8 668 # 3 27 669 # 4 64 670 # 5 125 671 # 6 216 672 # 7 343 673 # 8 512 674 # 9 729 675 # 10 1000 676 # </xy> 677 # </component> 678 # </curve> 679 680 }}} 236 681 237 682 p.outcome() … … 241 686 Notes: None 242 687 Code Example: 688 {{{ 689 p = Rappture.Plot() 690 out = p.outcome() 691 if (out.value() != 0) { 692 sys.stderr.write(out.context()) 693 sys.stderr.write(out.remark()) 694 } 695 }}} 696 243 697 244 698 p.is()
Note: See TracChangeset
for help on using the changeset viewer.