- Timestamp:
- 10/11/13 21:43:16 (11 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/plotter2.py
r2860 r2861 588 588 self._plotter.get_vinfo() 589 589 590 def get_colorindex(self, colorname):591 """\592 (for internal use)590 @classmethod 591 def get_colorindex(cls, colorname): 592 """\ 593 593 convert the given color name into color index used in PGPLOT. 594 594 """ 595 595 name = colorname.strip().lower() 596 597 if name == "white": idx = 0 # our definition of bgcolor 598 if name == "black": idx = 1 # our definition of fgcolor 599 if name == "red": idx = 2 600 if name == "green": idx = 3 601 if name == "blue": idx = 4 602 if name == "cyan": idx = 5 603 if name == "magenta": idx = 6 604 if name == "yellow": idx = 7 605 if name == "orange": idx = 8 606 if name == "yellowgreen": idx = 9 607 if name == "emerald": idx = 10 608 if name == "skyblue": idx = 11 609 if name == "purple": idx = 12 610 if name == "pink": idx = 13 611 if name == "gray": idx = 14 612 if name == "lightgray": idx = 15 613 614 return idx 615 616 def list_colornames(self): 596 available_color = True 597 598 if name == "white": idx = 0 # our definition of bgcolor 599 elif name == "black": idx = 1 # our definition of fgcolor 600 elif name == "red": idx = 2 601 elif name == "green": idx = 3 602 elif name == "blue": idx = 4 603 elif name == "cyan": idx = 5 604 elif name == "magenta": idx = 6 605 elif name == "yellow": idx = 7 606 elif name == "orange": idx = 8 607 elif name == "yellowgreen": idx = 9 608 elif name == "emerald": idx = 10 609 elif name == "skyblue": idx = 11 610 elif name == "purple": idx = 12 611 elif name == "pink": idx = 13 612 elif name == "gray": idx = 14 613 elif name == "lightgray": idx = 15 614 else: available_color = False 615 616 if (available_color): 617 return idx 618 else: 619 raise ValueError("Unavailable colour name.") 620 621 @classmethod 622 def list_colornames(cls): 617 623 """\ 618 624 list the available color names. … … 637 643 print "---------------------------------" 638 644 639 def get_linestyleindex(self, fstyle):640 """\641 (for internal use)645 @classmethod 646 def get_linestyleindex(cls, fstyle): 647 """\ 642 648 convert the given line style into style index used in PGPLOT. 643 649 """ 644 650 style = fstyle.strip().lower() 645 if style == "solid": idx = 1 646 if style == "dashed": idx = 2 647 if style == "dash-dotted": idx = 3 648 if style == "dotted": idx = 4 649 if style == "dash-dot-dot-dotted": idx = 5 650 651 return idx 652 653 def list_linestyles(self): 651 available_style = True 652 653 if style == "solid": idx = 1 654 elif style == "dashed": idx = 2 655 elif style == "dash-dotted": idx = 3 656 elif style == "dotted": idx = 4 657 elif style == "dash-dot-dot-dotted": idx = 5 658 else: available_style = False 659 660 if (available_style): 661 return idx 662 else: 663 raise ValueError("Unavailable line style.") 664 665 @classmethod 666 def list_linestyles(cls): 654 667 """\ 655 668 list the available line styles. … … 663 676 print "------------------------------" 664 677 665 def get_fillstyleindex(self, fstyle):666 """\667 (for internal use)678 @classmethod 679 def get_fillstyleindex(cls, fstyle): 680 """\ 668 681 convert the given fill style into style index used in PGPLOT. 669 682 """ 670 683 style = fstyle.strip().lower() 671 if style == "solid": idx = 1 672 if style == "outline": idx = 2 673 if style == "hatched": idx = 3 674 if style == "crosshatched": idx = 4 675 676 return idx 677 678 def list_fillstyles(self): 684 available_style = True 685 686 if style == "solid": idx = 1 687 elif style == "outline": idx = 2 688 elif style == "hatched": idx = 3 689 elif style == "crosshatched": idx = 4 690 else: available_style = False 691 692 if (available_style): 693 return idx 694 else: 695 raise ValueError("Unavailable fill style.") 696 697 @classmethod 698 def list_fillstyles(cls): 679 699 """\ 680 700 list the available fill styles. -
trunk/src/Plotter2.cpp
r2860 r2861 55 55 hasDataRange = false; 56 56 57 isAutoTickIntervalX = true; 58 isAutoTickIntervalY = true; 59 majorTickIntervalX = 0.1; 60 majorTickIntervalY = 0.1; 57 61 nMajorTickWithinTickNumsX = 2; 58 62 nMajorTickWithinTickNumsY = 2; 59 isAutoTickIntervalX = true;60 isAutoTickIntervalY = true;61 62 numLocationX = " l";63 numLocationY = " b";63 nMinorTickWithinMajorTicksX = 5; 64 nMinorTickWithinMajorTicksY = 5; 65 66 numLocationX = "b"; 67 numLocationY = "l"; 64 68 65 69 fontSizeDef = 1.0; 66 70 71 vData.clear(); 72 vRect.clear(); 73 74 labelXString = ""; 75 labelXPosX = 0.5; 76 labelXPosY = 0.05; 77 labelXAngle = 0.0; 78 labelXFJust = 0.5; 79 labelXSize = fontSizeDef * 1.1; 80 labelXColor = 1; 81 labelXBColor = 0; 82 83 labelYString = ""; 84 labelYPosX = 0.05; 85 labelYPosY = 0.5; 86 labelYAngle = 90.0; 87 labelYFJust = 0.5; 88 labelYSize = fontSizeDef * 1.1; 89 labelYColor = 1; 90 labelYBColor = 0; 91 92 titleString = ""; 93 titlePosX = 0.5; 94 titlePosY = 0.95; 95 titleAngle = 0.0; 96 titleFJust = 0.5; 97 titleSize = fontSizeDef * 1.5; 98 titleColor = 1; 99 titleBColor = 0; 100 67 101 vpBColor = -1; // transparent (<0) 68 69 vData.clear();70 102 } 71 103 … … 136 168 if (hasDataRange) { 137 169 if (isAutoTickIntervalX) { 138 adjustTickIntervalX( );170 adjustTickIntervalX(vpRangeXMin, vpRangeXMax); 139 171 } 140 172 if (isAutoTickIntervalY) { 141 adjustTickIntervalY(); 142 } 143 } 144 } 145 146 void Plotter2ViewportInfo::adjustTickIntervalX() { 147 adjustTickIntervalX(vpRangeXMin, vpRangeXMax); 173 adjustTickIntervalY(vpRangeYMin, vpRangeYMax); 174 } 175 } 148 176 } 149 177 150 178 void Plotter2ViewportInfo::adjustTickIntervalX(const float xmin, const float xmax) { 151 179 majorTickIntervalX = (float)pow(10.0, ceil(log10((xmax - xmin)/10.0))); 152 if ((xmax - xmin) / majorTickIntervalX < 2.0) { 153 majorTickIntervalX /= 10.0; 154 } 155 nMinorTickWithinMajorTicksX = 5; 156 } 157 158 void Plotter2ViewportInfo::adjustTickIntervalY() { 159 adjustTickIntervalY(vpRangeYMin, vpRangeYMax); 180 if ((xmax - xmin) / majorTickIntervalX < 4.0) { 181 majorTickIntervalX /= 2.0; 182 } 183 if ((xmax - xmin) / majorTickIntervalX < 4.0) { 184 majorTickIntervalX /= 2.0; 185 } 160 186 } 161 187 162 188 void Plotter2ViewportInfo::adjustTickIntervalY(const float ymin, const float ymax) { 163 189 majorTickIntervalY = (float)pow(10.0, ceil(log10((ymax - ymin)/10.0))); 164 if ((ymax - ymin) / majorTickIntervalY < 2.0) { 165 majorTickIntervalY /= 10.0; 166 } 167 nMinorTickWithinMajorTicksY = 5; 190 if ((ymax - ymin) / majorTickIntervalY < 4.0) { 191 majorTickIntervalY /= 2.0; 192 } 193 if ((ymax - ymin) / majorTickIntervalY < 4.0) { 194 majorTickIntervalY /= 2.0; 195 } 168 196 } 169 197 … … 205 233 info->hasData = true; 206 234 } 235 236 adjustRange(); 237 adjustTickInterval(); 207 238 } 208 239 … … 351 382 352 383 void Plotter2::getViewInfo() { 353 std::cout << "===================" << std::endl << std::flush; 384 std::string colorNames[16] = {"white", "black", "red", "green", 385 "blue", "cyan", "magenta", "yellow", 386 "orange", "yellowgreen", "emerald", "skyblue", 387 "purple", "pink", "gray", "lightgray"}; 388 std::string lstyleNames[6] = {"", "solid", "dashed", "dash-dotted", "dotted", "dash-dot-dot-dotted"}; 389 std::string fstyleNames[5] = {"", "solid", "outline", "hatched", "crosshatched"}; 390 354 391 for (unsigned int i = 0; i < vInfo.size(); ++i) { 355 std::cout << "[" << i << "] " << std::endl; 356 std::cout << "vpPos: "; 357 std::cout << "xmin=" << vInfo[i].vpPosXMin << ", "; 358 std::cout << "xmax=" << vInfo[i].vpPosXMax << ", "; 359 std::cout << "ymin=" << vInfo[i].vpPosYMin << ", "; 360 std::cout << "ymax=" << vInfo[i].vpPosYMax << std::endl; 361 362 std::cout << "vpRange: "; 363 std::cout << "xmin=" << vInfo[i].vpRangeXMin << ", "; 364 std::cout << "xmax=" << vInfo[i].vpRangeXMax << ", "; 365 std::cout << "ymin=" << vInfo[i].vpRangeYMin << ", "; 366 std::cout << "ymax=" << vInfo[i].vpRangeYMax << std::endl;; 367 368 std::cout << "vdatasize=" << vInfo[i].vData.size() << std::endl; 392 std::cout << "Viewport [ID = " << i << "] (" << (i+1) << "/" << vInfo.size() << ") "; 393 std::cout << "=============================================================" << std::endl; 394 395 std::cout << " Visible: " << (vInfo[i].showViewport ? "Yes" : "No") << std::endl; 396 397 std::cout << " Position in Window Coordinate: "; 398 std::cout << "X(left=" << vInfo[i].vpPosXMin << ",right=" << vInfo[i].vpPosXMax << "), "; 399 std::cout << "Y(bottom=" << vInfo[i].vpPosYMin << ",top=" << vInfo[i].vpPosYMax << ")" << std::endl; 400 401 std::cout << " Display Range: "; 402 std::cout << "X(" << (vInfo[i].isAutoRangeX ? "automatic" : "manual") << ", "; 403 std::cout << "min=" << vInfo[i].vpRangeXMin << ", max=" << vInfo[i].vpRangeXMax << "), "; 404 std::cout << "Y(" << (vInfo[i].isAutoRangeY ? "automatic" : "manual") << ", "; 405 std::cout << "min=" << vInfo[i].vpRangeYMin << ", max=" << vInfo[i].vpRangeYMax << ")" << std::endl; 406 407 std::cout << " Numbering/Ticks:" << std::endl; 408 std::cout << " X(" << ((vInfo[i].numLocationX == "b") ? "bottom" : ((vInfo[i].numLocationX == "t") ? "top" : (vInfo[i].numLocationX + " [*INVAILD*]"))) << ", interval[" << (vInfo[i].isAutoTickIntervalX ? "automatic" : "manual") << ", "; 409 std::cout << "numbering=" << (vInfo[i].majorTickIntervalX * vInfo[i].nMajorTickWithinTickNumsX) << ", "; 410 std::cout << "majortick=" << vInfo[i].majorTickIntervalX << ", "; 411 std::cout << "minortick=" << (vInfo[i].majorTickIntervalX / vInfo[i].nMinorTickWithinMajorTicksX) << "])" << std::endl; 412 std::cout << " Y(" << ((vInfo[i].numLocationY == "l") ? "left" : ((vInfo[i].numLocationY == "r") ? "right" : (vInfo[i].numLocationY + " [*INVAILD*]"))) << ", interval[" << (vInfo[i].isAutoTickIntervalY ? "automatic" : "manual") << ", "; 413 std::cout << "numbering=" << (vInfo[i].majorTickIntervalY * vInfo[i].nMajorTickWithinTickNumsY) << ", "; 414 std::cout << "majortick=" << vInfo[i].majorTickIntervalY << ", "; 415 std::cout << "minortick=" << (vInfo[i].majorTickIntervalY / vInfo[i].nMinorTickWithinMajorTicksY) << "])" << std::endl; 416 417 std::cout << " X Label: "; 418 if (vInfo[i].labelXString != "") { 419 std::cout << "\"" << vInfo[i].labelXString << "\"" << std::endl; 420 std::cout << " position=(" << vInfo[i].labelXPosX << "," << vInfo[i].labelXPosY << "), "; 421 std::cout << "justification=" << vInfo[i].labelXFJust << ", "; 422 std::cout << "angle=" << vInfo[i].labelXAngle << "deg, "; 423 std::cout << "fontsize=" << vInfo[i].labelXSize << std::endl; 424 } else { 425 std::cout << "No" << std::endl; 426 } 427 428 std::cout << " Y Label: "; 429 if (vInfo[i].labelYString != "") { 430 std::cout << "\"" << vInfo[i].labelYString << "\"" << std::endl; 431 std::cout << " position=(" << vInfo[i].labelYPosX << "," << vInfo[i].labelYPosY << "), "; 432 std::cout << "justification=" << vInfo[i].labelYFJust << ", "; 433 std::cout << "angle=" << vInfo[i].labelYAngle << "deg, "; 434 std::cout << "fontsize=" << vInfo[i].labelYSize << std::endl; 435 } else { 436 std::cout << "No" << std::endl; 437 } 438 439 std::cout << " Title: "; 440 if (vInfo[i].titleString != "") { 441 std::cout << "\"" << vInfo[i].titleString << "\"" << std::endl; 442 std::cout << " position=(" << vInfo[i].titlePosX << "," << vInfo[i].titlePosY << "), "; 443 std::cout << "justification=" << vInfo[i].titleFJust << ", "; 444 std::cout << "angle=" << vInfo[i].titleAngle << "deg, "; 445 std::cout << "fontsize=" << vInfo[i].titleSize << std::endl; 446 } else { 447 std::cout << "No" << std::endl; 448 } 449 450 std::cout << " Background Color = "; 451 if (vInfo[i].vpBColor < 0) { 452 std::cout << "transparent" << std::endl; 453 } else if (vInfo[i].vpBColor < 16) { 454 std::cout << colorNames[vInfo[i].vpBColor] << std::endl; 455 } else { 456 std::cout << "index:" << vInfo[i].vpBColor << " [INVAILD VALUE!]" << std::endl; 457 } 458 369 459 for (unsigned int j = 0; j < vInfo[i].vData.size(); ++j) { 370 std::cout << "vdataxdatasize=" << vInfo[i].vData[j].xData.size() << ", "; 371 for (unsigned int k = 0; k < vInfo[i].vData[j].xData.size(); ++k) { 372 std::cout << "(" << vInfo[i].vData[j].xData[k] << ", "; 373 std::cout << vInfo[i].vData[j].yData[k] << ") "; 460 std::cout << " Dataset [ID = " << j << "] (" << (j+1) << "/" << vInfo[i].vData.size() << ") "; 461 std::cout << "----------------------------------------------" << std::endl; 462 463 bool showDataset = (vInfo[i].vData[j].drawLine || vInfo[i].vData[j].drawMarker); 464 bool showViewport = vInfo[i].showViewport; 465 std::cout << " Visible: " << (showViewport ? "" : "("); 466 std::cout << (showDataset ? "Yes" : "No") << (showViewport ? "" : ")") << std::endl; 467 std::cout << " Number of Data Points: " << vInfo[i].vData[j].xData.size() << std::endl; 468 if (vInfo[i].vData[j].drawLine) { 469 std::cout << " Line: color="; 470 if (vInfo[i].vData[j].lineColor < 0) { 471 int defaultColorIdx = (j + 1) % 15 + 1; 472 std::cout << "default(" << colorNames[defaultColorIdx] << ")"; 473 } else if (vInfo[i].vData[j].lineColor < 16) { 474 std::cout << colorNames[vInfo[i].vData[j].lineColor]; 475 } else { 476 std::cout << "index:" << vInfo[i].vData[j].lineColor << " [*INVAILD*]"; 477 } 478 std::cout << ", width=" << vInfo[i].vData[j].lineWidth; 479 std::cout << ", style=" << lstyleNames[vInfo[i].vData[j].lineStyle] << std::endl; 374 480 } 375 std::cout << std::endl; 376 } 377 std::cout << "===================" << std::endl << std::flush; 378 } 481 if (vInfo[i].vData[j].drawMarker) { 482 std::cout << " Marker: color="; 483 if (vInfo[i].vData[j].markerColor < 0) { 484 std::cout << "default"; 485 } else if (vInfo[i].vData[j].markerColor < 16) { 486 std::cout << colorNames[vInfo[i].vData[j].markerColor]; 487 } else { 488 std::cout << "index:" << vInfo[i].vData[j].markerColor << " [*INVAILD*]"; 489 } 490 std::cout << ", shape=" << vInfo[i].vData[j].markerType; 491 std::cout << ", size=" << vInfo[i].vData[j].markerSize << std::endl; 492 } 493 494 } 495 496 for (unsigned int j = 0; j < vInfo[i].vRect.size(); ++j) { 497 std::cout << " XMask [ID = " << j << "] (" << (j+1) << "/" << vInfo[i].vRect.size() << ") "; 498 std::cout << "----------------------------------------------" << std::endl; 499 std::cout << " Range: (min=" << vInfo[i].vRect[j].xmin << ", max=" << vInfo[i].vRect[j].xmax << ")" << std::endl; 500 std::cout << " Attributes: (color=" << colorNames[vInfo[i].vRect[j].color]; 501 std::string fstyle = fstyleNames[vInfo[i].vRect[j].fill]; 502 std::cout << ", fillstyle=" << fstyle; 503 if (fstyle == "outline") { 504 std::cout << ", outlinewidth=" << vInfo[i].vRect[j].width; 505 } 506 if ((fstyle == "hatched")||(fstyle == "crosshatched")) { 507 std::cout << ", hatchspacing=" << vInfo[i].vRect[j].hsep; 508 } 509 std::cout << ")" << std::endl; 510 } 511 } 512 std::cout << "=====================================================================================" << std::endl << std::flush; 379 513 } 380 514 … … 790 924 ri.xmin = xmin; 791 925 ri.xmax = xmax; 792 std::vector<float> yrange = vi->getRangeY(); 793 float yexcess = 0.1*(yrange[1] - yrange[0]); 794 ri.ymin = yrange[0] - yexcess; 795 ri.ymax = yrange[1] + yexcess; 926 //y-range of xmask should be calculated in plot(). 927 //std::vector<float> yrange = vi->getRangeY(); 928 //float yexcess = 0.1*(yrange[1] - yrange[0]); 929 //ri.ymin = yrange[0] - yexcess; 930 //ri.ymax = yrange[1] + yexcess; 796 931 ri.color = color; 797 932 ri.fill = fill; … … 1009 1144 // setup viewport 1010 1145 cpgsvp(vi.vpPosXMin, vi.vpPosXMax, vi.vpPosYMin, vi.vpPosYMax); 1011 vi.adjustRange();1012 vi.adjustTickInterval();1013 1014 1146 cpgswin(vi.vpRangeXMin, vi.vpRangeXMax, vi.vpRangeYMin, vi.vpRangeYMax); 1015 1147 … … 1060 1192 delete [] pydata; 1061 1193 } 1194 1195 //calculate y-range of xmasks 1196 std::vector<float> yrange = vi.getRangeY(); 1197 float yexcess = 0.1*(yrange[1] - yrange[0]); 1198 float xmaskymin = yrange[0] - yexcess; 1199 float xmaskymax = yrange[1] + yexcess; 1062 1200 1063 1201 // masks … … 1082 1220 mxdata[2] = ri.xmax; 1083 1221 mxdata[3] = ri.xmin; 1084 mydata[0] = ri.ymin;1085 mydata[1] = ri.ymin;1086 mydata[2] = ri.ymax;1087 mydata[3] = ri.ymax;1222 mydata[0] = xmaskymin; 1223 mydata[1] = xmaskymin; 1224 mydata[2] = xmaskymax; 1225 mydata[3] = xmaskymax; 1088 1226 cpgpoly(4, mxdata, mydata); 1089 1227 } … … 1102 1240 // viewport outline, ticks and number labels 1103 1241 std::string numformatx, numformaty; 1104 if (vi.numLocationX == " l") {1242 if (vi.numLocationX == "b") { 1105 1243 numformatx = "N"; 1106 } else if (vi.numLocationX == " r") {1244 } else if (vi.numLocationX == "t") { 1107 1245 numformatx = "M"; 1108 1246 } else if (vi.numLocationX == "") { 1109 1247 numformatx = ""; 1110 1248 } 1111 if (vi.numLocationY == " b") {1249 if (vi.numLocationY == "l") { 1112 1250 numformaty = "NV"; 1113 } else if (vi.numLocationY == " t") {1251 } else if (vi.numLocationY == "r") { 1114 1252 numformaty = "MV"; 1115 1253 } else if (vi.numLocationY == "") { -
trunk/src/Plotter2.h
r2839 r2861 148 148 void adjustRangeX(float* xmin, float* xmax); 149 149 void adjustRangeY(float* ymin, float* ymax); 150 void adjustTickIntervalX();151 150 void adjustTickIntervalX(const float xmin, const float xmax); 152 void adjustTickIntervalY();153 151 void adjustTickIntervalY(const float ymin, const float ymax); 154 152 };
Note:
See TracChangeset
for help on using the changeset viewer.