1## Copyright (C) 2010-2014 Alan W. Irwin 2## 3## Demonstrate most pllegend capability including unicode symbols. 4## 5## This file is part of PLplot. 6## 7## PLplot is free software; you can redistribute it and/or modify 8## it under the terms of the GNU Library General Public License as published 9## by the Free Software Foundation; either version 2 of the License, or 10## (at your option) any later version. 11### 12## PLplot 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 Library General Public License for more details. 16### 17## You should have received a copy of the GNU Library General Public License 18## along with PLplot; if not, write to the Free Software 19## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20## 21## This example designed just for devices (e.g., the cairo-related and 22## qt-related devices) where the best choice of glyph is automatically 23## selected by the related libraries (pango/cairo or Qt4) for each 24## unicode character depending on what system fonts are installed. Of 25## course, you must have the appropriate TrueType fonts installed to 26## have access to all the required glyphs. 27 281; 29 30global position_options special_symbols colorbar_option_kinds colorbar_option_kind_labels colorbar_position_options colorbar_position_option_labels colorbar_label_options colorbar_label_option_labels colorbar_cap_options colorbar_cap_option_labels 31global COLORBAR_KINDS COLORBAR_POSITIONS COLORBAR_LABELS COLORBAR_CAPS 32 33position_options = [ 34 bitor(PL_POSITION_LEFT, bitor(PL_POSITION_TOP, PL_POSITION_OUTSIDE)); 35 bitor(PL_POSITION_TOP, PL_POSITION_OUTSIDE); 36 bitor(PL_POSITION_RIGHT, bitor(PL_POSITION_TOP, PL_POSITION_OUTSIDE)); 37 bitor(PL_POSITION_RIGHT, PL_POSITION_OUTSIDE); 38 bitor(PL_POSITION_RIGHT, bitor(PL_POSITION_BOTTOM, PL_POSITION_OUTSIDE)); 39 bitor(PL_POSITION_BOTTOM, PL_POSITION_OUTSIDE); 40 bitor(PL_POSITION_LEFT, bitor(PL_POSITION_BOTTOM, PL_POSITION_OUTSIDE)); 41 bitor(PL_POSITION_LEFT, PL_POSITION_OUTSIDE); 42 bitor(PL_POSITION_LEFT, bitor(PL_POSITION_TOP, PL_POSITION_INSIDE)); 43 bitor(PL_POSITION_TOP, PL_POSITION_INSIDE); 44 bitor(PL_POSITION_RIGHT, bitor(PL_POSITION_TOP, PL_POSITION_INSIDE)); 45 bitor(PL_POSITION_RIGHT, PL_POSITION_INSIDE); 46 bitor(PL_POSITION_RIGHT, bitor(PL_POSITION_BOTTOM, PL_POSITION_INSIDE)); 47 bitor(PL_POSITION_BOTTOM, PL_POSITION_INSIDE); 48 bitor(PL_POSITION_LEFT, bitor(PL_POSITION_BOTTOM, PL_POSITION_INSIDE)); 49 bitor(PL_POSITION_LEFT, PL_POSITION_INSIDE) 50 ]; 51 52## Pick 5 arbitrary UTF-8 symbols useful for plotting points (✠✚✱✪✽✺✰✴✦). 53special_symbols = [ 54 "✰"; 55 "✴"; 56 "✱"; 57 "✽"; 58 "✦" 59 ]; 60 61# plcolorbar options 62 63# Colorbar type options 64COLORBAR_KINDS = 4; 65colorbar_option_kinds = [ 66 PL_COLORBAR_SHADE; 67 bitor(PL_COLORBAR_SHADE,PL_COLORBAR_SHADE_LABEL); 68 PL_COLORBAR_IMAGE; 69 PL_COLORBAR_GRADIENT 70]; 71 72colorbar_option_kind_labels = { 73 "Shade colorbars"; 74 "Shade colorbars with custom labels"; 75 "Image colorbars"; 76 "Gradient colorbars" 77}; 78 79# Which side of the page are we positioned relative to? 80COLORBAR_POSITIONS = 4; 81colorbar_position_options = [ 82 PL_POSITION_LEFT; 83 PL_POSITION_RIGHT; 84 PL_POSITION_TOP; 85 PL_POSITION_BOTTOM 86]; 87 88colorbar_position_option_labels = { 89 "Left", 90 "Right", 91 "Top", 92 "Bottom" 93}; 94 95# Colorbar label positioning options 96COLORBAR_LABELS = 4; 97colorbar_label_options = [ 98 PL_COLORBAR_LABEL_LEFT; 99 PL_COLORBAR_LABEL_RIGHT; 100 PL_COLORBAR_LABEL_TOP; 101 PL_COLORBAR_LABEL_BOTTOM 102]; 103 104colorbar_label_option_labels = { 105 "Label left", 106 "Label right", 107 "Label top", 108 "Label bottom" 109}; 110 111# Colorbar cap options 112COLORBAR_CAPS = 4; 113colorbar_cap_options = [ 114 PL_COLORBAR_CAP_NONE; 115 PL_COLORBAR_CAP_LOW; 116 PL_COLORBAR_CAP_HIGH; 117 bitor(PL_COLORBAR_CAP_LOW, PL_COLORBAR_CAP_HIGH) 118]; 119 120colorbar_cap_option_labels = { 121 "No caps"; 122 "Low cap"; 123 "High cap"; 124 "Low and high caps" 125}; 126 127function plcolorbar_example_page( kind_i, label_i, cap_i, cont_color, cont_width, values ) 128 129 global COLORBAR_POSITIONS colorbar_option_kinds colorbar_option_kind_labels colorbar_position_options colorbar_position_option_labels colorbar_label_options colorbar_label_option_labels colorbar_cap_options colorbar_cap_option_labels 130 global PL_POSITION_LEFT PL_POSITION_RIGHT PL_POSITION_BOTTOM PL_COLORBAR_BOUNDING_BOX PL_COLORBAR_BACKGROUND 131 132 label_opts = zeros(1,1); 133 ticks = zeros(1,1); 134 sub_ticks = zeros(1,1); 135 136 n_values_array(1,:) = length(values); 137 values_array(1,:) = values; 138 139 low_cap_color = 0.0; 140 high_cap_color = 1.0; 141 142 # Start a new page 143 pladv( 0 ); 144 145 # Draw one colorbar relative to each side of the page 146 for position_i = 1:COLORBAR_POSITIONS 147 position = colorbar_position_options(position_i); 148 opt = bitor( 149 colorbar_option_kinds(kind_i), bitor( 150 colorbar_label_options(label_i), 151 colorbar_cap_options(cap_i) ) ); 152 153 vertical = bitand(position, PL_POSITION_LEFT) || bitand(position, PL_POSITION_RIGHT); 154 ifn = bitand(position, PL_POSITION_LEFT) || bitand(position, PL_POSITION_BOTTOM); 155 156 # Set the offset position on the page 157 if ( vertical ) 158 x = 0.0; 159 y = 0.0; 160 x_length = 0.05; 161 y_length = 0.5; 162 else 163 x = 0.0; 164 y = 0.0; 165 x_length = 0.5; 166 y_length = 0.05; 167 endif 168 169 # Set appropriate labelling options. 170 if ( ifn ) 171 if ( cont_color == 0 || cont_width == 0. ) 172 axis_opts(1,:) = "uwtivn"; 173 else 174 axis_opts(1,:) = "uwxvn"; 175 endif 176 else 177 if ( cont_color == 0 || cont_width == 0. ) 178 axis_opts(1,:) = "uwtivm"; 179 else 180 axis_opts(1,:) = "uwxvm"; 181 endif 182 endif 183 184 label = cstrcat(char(colorbar_position_option_labels(position_i)), ", ", char(colorbar_label_option_labels(label_i)) ); 185 186 # Smaller text 187 plschr( 0.0, 0.75 ); 188 # Small ticks on the vertical axis 189 plsmaj( 0.0, 0.5 ); 190 plsmin( 0.0, 0.5 ); 191 192 plvpor( 0.20, 0.80, 0.20, 0.80 ); 193 plwind( 0.0, 1.0, 0.0, 1.0 ); 194 # Set interesting background colour. 195 plscol0a( 15, 0, 0, 0, 0.20 ); 196 [colorbar_width, colorbar_height] = plcolorbar( 197 bitor(opt, bitor(PL_COLORBAR_BOUNDING_BOX, PL_COLORBAR_BACKGROUND)), 198 position, x, y, x_length, y_length, 199 15, 1, 1, low_cap_color, high_cap_color, 200 cont_color, cont_width, label_opts, label, 201 axis_opts, ticks, sub_ticks, 202 n_values_array, values_array ); 203 204 # Reset text and tick sizes 205 plschr( 0.0, 1.0 ); 206 plsmaj( 0.0, 1.0 ); 207 plsmin( 0.0, 1.0 ); 208 endfor 209 210 # Draw a page title 211 title = cstrcat(char(colorbar_option_kind_labels(kind_i)), " - ", char(colorbar_cap_option_labels(cap_i)) ); 212 plvpor( 0.0, 1.0, 0.0, 1.0 ); 213 plwind( 0.0, 1.0, 0.0, 1.0 ); 214 plptex( 0.5, 0.5, 0.0, 0.0, 0.5, title ); 215endfunction 216 217function plcolorbar_example( palette, kind_i, cont_color, cont_width, values ) 218 219 global COLORBAR_LABELS COLORBAR_CAPS 220 221 # Load the color palette 222 plspal1( palette, 1 ); 223 224 for label_i = 1:COLORBAR_LABELS 225 for cap_i = 1:COLORBAR_CAPS 226 plcolorbar_example_page( kind_i, label_i, cap_i, 227 cont_color, cont_width, values ); 228 endfor 229 endfor 230endfunction 231 232 233 234function ix33c() 235 ## Parse and process command line arguments 236 237 ## (void) plparseopts(&argc, argv, PL_PARSE_FULL); 238 239 ## Initialize plplot 240 ## set global attributes for PLplot variables used in this function. 241 global PL_FCI_SANS PL_FCI_MONO PL_LEGEND_NONE PL_LEGEND_COLOR_BOX PL_LEGEND_LINE PL_LEGEND_SYMBOL PL_LEGEND_TEXT_LEFT PL_LEGEND_BACKGROUND PL_LEGEND_BOUNDING_BOX PL_LEGEND_ROW_MAJOR 242 global PL_POSITION_LEFT PL_POSITION_RIGHT PL_POSITION_TOP PL_POSITION_BOTTOM PL_POSITION_INSIDE PL_POSITION_OUTSIDE PL_POSITION_SUBPAGE 243 global PL_COLORBAR_IMAGE PL_COLORBAR_SHADE PL_COLORBAR_GRADIENT PL_COLORBAR_SHADE_LABEL 244 global position_options special_symbols 245 global COLORBAR_KINDS 246 plinit(); 247 248 ## First page illustrating the 16 standard positions. 249 pladv(0); 250 plvpor(0.25, 0.75, 0.25, 0.75); 251 plwind(0.0, 1.0, 0.0, 1.0); 252 plbox("bc", 0.0, 0, "bc", 0.0, 0); 253 plsfont(PL_FCI_SANS, -1, -1); 254 plmtex("t", 8.0, 0.5, 0.5, "The 16 standard legend positions with"); 255 plmtex("t", 6.0, 0.5, 0.5, "the same (0.05) offset in x and y"); 256 257 ## Set up legend arrays with the correct size, type. In octave this may 258 ## be done by clearing the array (in case it was used before) and then 259 ## writing the last element of the array with a placeholder of the right 260 ## type. Note that for strings the right placeholder length doesn't 261 ## matter. Octave keeps track of the longest string in each array and pads 262 ## out all other members with blanks to that length if a subsequent string 263 ## assignment for an array element exceeds that length. 264 nlegend = 1; 265 266 opt_array = 0; 267 text_colors = 0; 268 text = " "; 269 box_colors = 0; 270 box_patterns = 0; 271 box_scales = 0.; 272 box_line_widths = 0.; 273 line_colors = 0; 274 line_styles = 0; 275 line_widths = 0.; 276 symbol_colors = 0; 277 symbol_scales = 0.; 278 symbol_numbers = 0; 279 symbols = " "; 280 281 opt_array(nlegend,1) = 0; 282 text_colors(nlegend,1) = 0; 283 text(nlegend,1:length(" ")) = " "; 284 line_colors(nlegend,1) = 0; 285 line_styles(nlegend,1) = 0; 286 line_widths(nlegend,1) = 0.; 287 symbol_colors(nlegend,1) = 0; 288 symbol_scales(nlegend,1) = 0.; 289 symbol_numbers(nlegend,1) = 0; 290 symbols(nlegend,1:length(" ")) = " "; 291 292 ## Only specify legend data that are required according to the 293 ## value of opt_array for that entry. 294 opt_base = bitor(PL_LEGEND_BACKGROUND, PL_LEGEND_BOUNDING_BOX); 295 opt_array(1) = bitor(PL_LEGEND_LINE, PL_LEGEND_SYMBOL); 296 line_styles(1) = 1; 297 line_widths(1) = 1.; 298 symbol_scales(1) = 1.; symbol_numbers(1) = 4; 299 symbols(1,1:length("#(728)")) = "#(728)"; 300 301 ## Use monotype fonts so that all legends are the same size. 302 plsfont( PL_FCI_MONO , -1, -1); 303 plscol0a( 15, 32, 32, 32, 0.70 ); 304 305 for k=0:15 306 position = position_options(k+1); 307 opt = opt_base; 308 string = sprintf("%2.2d", k); 309 text(1,1:length(string)) = string; 310 text_colors(1) = 1 + mod(k, 8); 311 line_colors(1) = 1 + mod(k, 8); 312 symbol_colors(1) = 1 + mod(k, 8); 313 314 [legend_width, legend_height] = ... 315 pllegend( opt, position, 0.05, 0.05, 316 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, 1.0, 2.0, 317 1., text_colors, text, 318 [], [], [], [], 319 line_colors, line_styles, line_widths, 320 symbol_colors, symbol_scales, symbol_numbers, symbols ); 321 endfor 322 ## Second page illustrating effect of nrow, ncolumn for the same legend 323 ## data. 324 pladv(0); 325 plvpor(0.25, 0.75, 0.25, 0.75); 326 plwind(0.0, 1.0, 0.0, 1.0); 327 plbox("bc", 0.0, 0, "bc", 0.0, 0); 328 plsfont(PL_FCI_SANS, -1, -1); 329 plmtex("t", 8.0, 0.5, 0.5, "The effect of nrow, ncolumn, PL_LEGEND_ROW_MAJOR,"); 330 plmtex("t", 6.0, 0.5, 0.5, "and position for the same legend data"); 331 332 ## Set up legend arrays with the correct size, type. In octave this may 333 ## be done by clearing the array (in case it was used before) and then 334 ## writing the last element of the array with a placeholder of the right 335 ## type. Note that for strings the right placeholder length doesn't 336 ## matter. Octave keeps track of the longest string in each array and pads 337 ## out all other members with blanks to that length if a subsequent string 338 ## assignment for an array element exceeds that length. 339 nlegend = 7; 340 341 opt_array = 0; 342 text_colors = 0; 343 text = " "; 344 box_colors = 0; 345 box_patterns = 0; 346 box_scales = 0.; 347 box_line_widths = 0.; 348 line_colors = 0; 349 line_styles = 0; 350 line_widths = 0.; 351 symbol_colors = 0; 352 symbol_scales = 0.; 353 symbol_numbers = 0; 354 symbols = " "; 355 356 opt_array(nlegend,1) = 0; 357 text_colors(nlegend,1) = 0; 358 text(nlegend,1:length(" ")) = " "; 359 line_colors(nlegend,1) = 0; 360 line_styles(nlegend,1) = 0; 361 line_widths(nlegend,1) = 0.; 362 symbol_colors(nlegend,1) = 0; 363 symbol_scales(nlegend,1) = 0.; 364 symbol_numbers(nlegend,1) = 0; 365 symbols(nlegend,1:length(" ")) = " "; 366 367 ## Only specify legend data that are required according to the 368 ## value of opt_array for that entry. 369 opt_base = bitor(PL_LEGEND_BACKGROUND, PL_LEGEND_BOUNDING_BOX); 370 for k=0:nlegend-1 371 opt_array(k+1) = bitor(PL_LEGEND_LINE, PL_LEGEND_SYMBOL); 372 line_styles(k+1) = 1; 373 line_widths(k+1) = 1.; 374 symbol_scales(k+1) = 1.; 375 symbol_numbers(k+1) = 2; 376 symbols(k+1,1:length("#(728)")) = "#(728)"; 377 string = sprintf("%2.2d",k); 378 text(k+1,1:length(string)) = string; 379 text_colors(k+1) = 1 + mod(k,8); 380 line_colors(k+1) = 1 + mod(k,8); 381 symbol_colors(k+1) = 1 + mod(k,8); 382 endfor 383 384 ## Use monotype fonts so that all legends are the same size. 385 plsfont(PL_FCI_MONO, -1, -1); 386 plscol0a( 15, 32, 32, 32, 0.70 ); 387 388 position = bitor(PL_POSITION_TOP, PL_POSITION_OUTSIDE); 389 opt = opt_base; 390 x = 0.; 391 y = 0.1; 392 nrow = 1; 393 ncolumn = nlegend; 394 [legend_width, legend_height] = ... 395 pllegend( opt, position, x, y, 396 0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0, 397 1., text_colors, text, 398 [], [], [], [], 399 line_colors, line_styles, line_widths, 400 symbol_colors, symbol_scales, symbol_numbers, symbols ); 401 402 position = bitor(PL_POSITION_BOTTOM, PL_POSITION_OUTSIDE); 403 opt = opt_base; 404 x = 0.; 405 y = 0.1; 406 nrow = 1; 407 ncolumn = nlegend; 408 [legend_width, legend_height] = ... 409 pllegend( opt, position, x, y, 410 0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0, 411 1., text_colors, text, 412 [], [], [], [], 413 line_colors, line_styles, line_widths, 414 symbol_colors, symbol_scales, symbol_numbers, symbols ); 415 416 417 position = bitor(PL_POSITION_LEFT, PL_POSITION_OUTSIDE); 418 opt = opt_base; 419 x = 0.1; 420 y = 0.; 421 nrow = nlegend; 422 ncolumn = 1; 423 [legend_width, legend_height] = ... 424 pllegend( opt, position, x, y, 425 0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0, 426 1., text_colors, text, 427 [], [], [], [], 428 line_colors, line_styles, line_widths, 429 symbol_colors, symbol_scales, symbol_numbers, symbols ); 430 431 position = bitor(PL_POSITION_RIGHT, PL_POSITION_OUTSIDE); 432 opt = opt_base; 433 x = 0.1; 434 y = 0.; 435 nrow = nlegend; 436 ncolumn = 1; 437 [legend_width, legend_height] = ... 438 pllegend( opt, position, x, y, 439 0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0, 440 1., text_colors, text, 441 [], [], [], [], 442 line_colors, line_styles, line_widths, 443 symbol_colors, symbol_scales, symbol_numbers, symbols ); 444 445 position = bitor(PL_POSITION_LEFT, bitor(PL_POSITION_TOP, PL_POSITION_INSIDE)); 446 opt = opt_base; 447 x = 0.; 448 y = 0.; 449 nrow = 6; 450 ncolumn = 2; 451 [legend_width, legend_height] = ... 452 pllegend( opt, position, x, y, 453 0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0, 454 1., text_colors, text, 455 [], [], [], [], 456 line_colors, line_styles, line_widths, 457 symbol_colors, symbol_scales, symbol_numbers, symbols ); 458 459 position = bitor(PL_POSITION_RIGHT, bitor(PL_POSITION_TOP, PL_POSITION_INSIDE)); 460 opt = bitor(opt_base, PL_LEGEND_ROW_MAJOR); 461 x = 0.; 462 y = 0.; 463 nrow = 6; 464 ncolumn = 2; 465 [legend_width, legend_height] = ... 466 pllegend( opt, position, x, y, 467 0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0, 468 1., text_colors, text, 469 [], [], [], [], 470 line_colors, line_styles, line_widths, 471 symbol_colors, symbol_scales, symbol_numbers, symbols ); 472 473 position = bitor(PL_POSITION_BOTTOM, PL_POSITION_INSIDE); 474 opt = bitor(opt_base, PL_LEGEND_ROW_MAJOR); 475 x = 0.; 476 y = 0.; 477 nrow = 3; 478 ncolumn = 3; 479 [legend_width, legend_height] = ... 480 pllegend( opt, position, x, y, 481 0.05, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 2.0, 482 1., text_colors, text, 483 [], [], [], [], 484 line_colors, line_styles, line_widths, 485 symbol_colors, symbol_scales, symbol_numbers, symbols ); 486 487 ## Third page demonstrating legend alignment 488 pladv(0); 489 plvpor(0.0, 1.0, 0.0, 0.9); 490 plwind(0.0, 1.0, 0.0, 1.0); 491 plsfont(PL_FCI_SANS, -1, -1); 492 plmtex("t", 2.0, 0.5, 0.5, "Demonstrate legend alignment"); 493 494 x = 0.1; 495 y = 0.1; 496 nturn = 4; 497 nlegend = 0; 498 position = bitor(bitor(PL_POSITION_LEFT, PL_POSITION_TOP), PL_POSITION_SUBPAGE); 499 opt_base = bitor(PL_LEGEND_BACKGROUND, PL_LEGEND_BOUNDING_BOX); 500 opt = opt_base; 501 for i=0:8 502 ## Set up legend arrays with the correct size, type. In octave this may 503 ## be done by clearing the array (in case it was used before) and then 504 ## writing the last element of the array with a placeholder of the right 505 ## type. Note that for strings the right placeholder length doesn't 506 ## matter. Octave keeps track of the longest string in each array and pads 507 ## out all other members with blanks to that length if a subsequent string 508 ## assignment for an array element exceeds that length. 509 if( i <= nturn) 510 nlegend += 1; 511 else 512 nlegend -= 1; 513 endif 514 nlegend = max(1, nlegend); 515 516 opt_array = 0; 517 text_colors = 0; 518 text = " "; 519 box_colors = 0; 520 box_patterns = 0; 521 box_scales = 0.; 522 box_line_widths = 0.; 523 line_colors = 0; 524 line_styles = 0; 525 line_widths = 0.; 526 symbol_colors = 0; 527 symbol_scales = 0.; 528 symbol_numbers = 0; 529 symbols = " "; 530 531 opt_array(nlegend,1) = 0; 532 text_colors(nlegend,1) = 0; 533 text(nlegend,1:length(" ")) = " "; 534 box_colors(nlegend,1) = 0; 535 box_patterns(nlegend,1) = 0; 536 box_scales(nlegend,1) = 0.; 537 box_line_widths(nlegend,1) = 0.; 538 line_colors(nlegend,1) = 0; 539 line_styles(nlegend,1) = 0; 540 line_widths(nlegend,1) = 0.; 541 symbol_colors(nlegend,1) = 0; 542 symbol_scales(nlegend,1) = 0.; 543 symbol_numbers(nlegend,1) = 0; 544 symbols(nlegend,1:length(" ")) = " "; 545 546 ## Only specify legend data that are required according to the 547 ## value of opt_array for that entry. 548 for k=0:nlegend-1 549 opt_array(k+1) = bitor(PL_LEGEND_LINE, PL_LEGEND_SYMBOL); 550 line_styles(k+1) = 1; 551 line_widths(k+1) = 1.; 552 symbol_scales(k+1) = 1.; 553 symbol_numbers(k+1) = 2; 554 symbols(k+1,1:length("#(728)")) = "#(728)"; 555 string = sprintf("%2.2d",k); 556 text(k+1,1:length(string)) = string; 557 text_colors(k+1) = 1 + mod(k,8); 558 line_colors(k+1) = 1 + mod(k,8); 559 symbol_colors(k+1) = 1 + mod(k,8); 560 endfor 561 562 ## Use monotype fonts so that all legends are the same size. 563 plsfont(PL_FCI_MONO, -1, -1); 564 plscol0a( 15, 32, 32, 32, 0.70 ); 565 566 nrow = min(3, nlegend); 567 ncolumn = 0; 568 569 [legend_width, legend_height] = ... 570 pllegend( opt, position, x, y, 571 0.025, 15, 1, 1, nrow, ncolumn, opt_array, 1.0, 1.0, 1.5, 572 1., text_colors, text, 573 [], [], [], [], 574 line_colors, line_styles, line_widths, 575 symbol_colors, symbol_scales, symbol_numbers, symbols ); 576 if(i == nturn) 577 position = bitor(bitor(PL_POSITION_RIGHT, PL_POSITION_TOP), PL_POSITION_SUBPAGE); 578 opt = opt_base; 579 x = 1. - x; 580 y += legend_height; 581 else 582 x += legend_width; 583 y += legend_height; 584 endif 585 endfor 586 587 ## Fourth page illustrating various kinds of legends 588 max_height = 0.; 589 xstart = 0.0; 590 ystart = 0.1; 591 x = xstart; 592 y = ystart; 593 text_scale = 0.90; 594 pladv(0); 595 plvpor(0.0, 1., 0.0, 0.90); 596 plwind(0.0, 1.0, 0.0, 1.0); 597 ## plbox("bc", 0.0, 0, "bc", 0.0, 0); 598 plsfont(PL_FCI_SANS, -1, -1); 599 plmtex("t", 2.0, 0.5, 0.5, "Demonstrate Various Kinds of Legends"); 600 601 ## Set up legend arrays with the correct size, type. In octave this may 602 ## be done by clearing the array (in case it was used before) and then 603 ## writing the last element of the array with a placeholder of the right 604 ## type. Note that for strings the right placeholder length doesn't 605 ## matter. Octave keeps track of the longest string in each array and pads 606 ## out all other members with blanks to that length if a subsequent string 607 ## assignment for an array element exceeds that length. 608 nlegend = 5; 609 610 opt_array = 0; 611 text_colors = 0; 612 text = " "; 613 box_colors = 0; 614 box_patterns = 0; 615 box_scales = 0.; 616 box_line_widths = 0.; 617 line_colors = 0; 618 line_styles = 0; 619 line_widths = 0.; 620 symbol_colors = 0; 621 symbol_scales = 0.; 622 symbol_numbers = 0; 623 symbols = " "; 624 625 opt_array(nlegend,1) = 0; 626 text_colors(nlegend,1) = 0; 627 text(nlegend,1:length(" ")) = " "; 628 box_colors(nlegend,1) = 0; 629 box_patterns(nlegend,1) = 0; 630 box_scales(nlegend,1) = 0.; 631 box_line_widths(nlegend,1) = 0.; 632 line_colors(nlegend,1) = 0; 633 line_styles(nlegend,1) = 0; 634 line_widths(nlegend,1) = 0.; 635 symbol_colors(nlegend,1) = 0; 636 symbol_scales(nlegend,1) = 0.; 637 symbol_numbers(nlegend,1) = 0; 638 symbols(nlegend,1:length(" ")) = " "; 639 640 ## Only specify legend data that are required according to the 641 ## value of opt_array for that entry. 642 position = bitor(PL_POSITION_LEFT, PL_POSITION_TOP); 643 opt_base = bitor(PL_LEGEND_BACKGROUND, bitor(PL_LEGEND_BOUNDING_BOX, PL_LEGEND_TEXT_LEFT)); 644 645 ## Set up None, Box, Line, Symbol, and Line & Symbol legend entries. 646 opt_array(1) = PL_LEGEND_NONE; 647 text(1,1:length("None")) = "None"; 648 text_colors(1) = 1; 649 650 opt_array(2) = PL_LEGEND_COLOR_BOX; 651 text(2,1:length("Box")) = "Box"; 652 text_colors(2) = 2; 653 box_colors(2) = 2; 654 box_patterns(2) = 0; 655 box_scales(2) = 0.8; 656 box_line_widths(2) = 1.; 657 658 opt_array(3) = PL_LEGEND_LINE; 659 text(3,1:length("Line")) = "Line"; 660 text_colors(3) = 3; 661 line_colors(3) = 3; 662 line_styles(3) = 1; 663 line_widths(3) = 1.; 664 665 opt_array(4) = PL_LEGEND_SYMBOL; 666 text(4,1:length("Symbol")) = "Symbol"; 667 text_colors(4) = 4; 668 symbol_colors(4) = 4; 669 symbol_scales(4) = text_scale; 670 symbol_numbers(4) = 4; 671 symbols(4,1:length(special_symbols(3,:))) = special_symbols(3,:); 672 673 opt_array(5) = bitor(PL_LEGEND_SYMBOL, PL_LEGEND_LINE); 674 text(5,1:length("L & S")) = "L & S"; 675 text_colors(5) = 5; 676 line_colors(5) = 5; 677 line_styles(5) = 1; 678 line_widths(5) = 1.; 679 symbol_colors(5) = 5; 680 symbol_scales(5) = text_scale; 681 symbol_numbers(5) = 4; 682 symbols(5,1:length(special_symbols(3,:))) = special_symbols(3,:); 683 684 opt = opt_base; 685 plscol0a( 15, 32, 32, 32, 0.70 ); 686 [legend_width, legend_height] = ... 687 pllegend( opt, position, x, y, 688 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0, 689 0., text_colors, text, 690 box_colors, box_patterns, box_scales, box_line_widths, 691 line_colors, line_styles, line_widths, 692 symbol_colors, symbol_scales, symbol_numbers, symbols ); 693 max_height = max(max_height, legend_height); 694 695 ## Set up symbol legend entries with various symbols. 696 ## Reset text and symbols, because otherwise legend may come out with 697 ## the wrong length text/symbol with prior results embedded. 698 text = " "; 699 text(nlegend,1:length(" ")) = " "; 700 symbols = " "; 701 symbols(nlegend,1:length(" ")) = " "; 702 703 for i=0:nlegend-1 704 opt_array(i+1) = PL_LEGEND_SYMBOL; 705 string = ["Symbol ",special_symbols(i+1,:)]; 706 text(i+1,1:length(string)) = string; 707 text_colors(i+1) = i+1; 708 symbol_colors(i+1) = i+1; 709 symbol_scales(i+1) = text_scale; 710 symbol_numbers(i+1) = 4; 711 symbols(i+1,1:length(special_symbols(i+1,:))) = special_symbols(i+1,:); 712 endfor 713 714 opt = opt_base; 715 x += legend_width; 716 plscol0a( 15, 32, 32, 32, 0.70 ); 717 [legend_width, legend_height] = ... 718 pllegend( opt, position, x, y, 719 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0, 720 0., text_colors, text, 721 [], [], [], [], 722 [], [], [], 723 symbol_colors, symbol_scales, symbol_numbers, symbols ); 724 max_height = max(max_height, legend_height); 725 726 ## Set up symbol legend entries with various numbers of symbols. 727 ## Reset text and symbols, because otherwise legend may come out with 728 ## the wrong length text/symbol with prior results embedded. 729 text = " "; 730 text(nlegend,1:length(" ")) = " "; 731 symbols = " "; 732 symbols(nlegend,1:length(" ")) = " "; 733 734 for i=0:nlegend-1 735 opt_array(i+1) = PL_LEGEND_SYMBOL; 736 string = sprintf("Symbol Number %d", (i+2)); 737 text(i+1,1:length(string)) = string; 738 text_colors(i+1) = i+1; 739 symbol_colors(i+1) = i+1; 740 symbol_scales(i+1) = text_scale; 741 symbol_numbers(i+1) = i+2; 742 symbols(i+1,1:length(special_symbols(3,:))) = special_symbols(3,:); 743 endfor 744 745 opt = opt_base; 746 x += legend_width; 747 plscol0a( 15, 32, 32, 32, 0.70 ); 748 [legend_width, legend_height] = ... 749 pllegend( opt, position, x, y, 750 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0, 751 0., text_colors, text, 752 [], [], [], [], 753 [], [], [], 754 symbol_colors, symbol_scales, symbol_numbers, symbols ); 755 max_height = max(max_height, legend_height); 756 757 ## Set up box legend entries with various colours. 758 ## Reset text and symbols, because otherwise legend may come out with 759 ## the wrong length text/symbol with prior results embedded. 760 text = " "; 761 text(nlegend,1:length(" ")) = " "; 762 symbols = " "; 763 symbols(nlegend,1:length(" ")) = " "; 764 765 for i=0:nlegend-1 766 opt_array(i+1) = PL_LEGEND_COLOR_BOX; 767 string = sprintf("%s %d", "Box Color",i+1); 768 text(i+1,1:length(string)) = string; 769 text_colors(i+1) = i+1; 770 box_colors(i+1) = i+1; 771 box_patterns(i+1) = 0; 772 box_scales(i+1) = 0.8; 773 box_line_widths(i+1) = 1.; 774 endfor 775 776 opt = opt_base; 777 ## Use new origin 778 x = xstart; 779 y += max_height; 780 max_height = 0.; 781 plscol0a( 15, 32, 32, 32, 0.70 ); 782 [legend_width, legend_height] = ... 783 pllegend( opt, position, x, y, 784 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0, 785 0., text_colors, text, 786 box_colors, box_patterns, box_scales, box_line_widths, 787 [], [], [], 788 [], [], [], [] ); 789 max_height = max(max_height, legend_height); 790 791 ## Set up box legend entries with various patterns. 792 ## Reset text and symbols, because otherwise legend may come out with 793 ## the wrong length text/symbol with prior results embedded. 794 text = " "; 795 text(nlegend,1:length(" ")) = " "; 796 symbols = " "; 797 symbols(nlegend,1:length(" ")) = " "; 798 799 for i=0:nlegend-1 800 opt_array(i+1) = PL_LEGEND_COLOR_BOX; 801 string = sprintf("%s %d", "Box Pattern",i); 802 text(i+1,1:length(string)) = string; 803 text_colors(i+1) = 2; 804 box_colors(i+1) = 2; 805 box_patterns(i+1) = i; 806 box_scales(i+1) = 0.8; 807 box_line_widths(i+1) = 1.; 808 endfor 809 810 opt = opt_base; 811 x += legend_width; 812 plscol0a( 15, 32, 32, 32, 0.70 ); 813 [legend_width, legend_height] = ... 814 pllegend( opt, position, x, y, 815 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0, 816 0., text_colors, text, 817 box_colors, box_patterns, box_scales, box_line_widths, 818 [], [], [], 819 [], [], [], [] ); 820 max_height = max(max_height, legend_height); 821 822 ## Set up box legend entries with various box pattern line widths. 823 ## Reset text and symbols, because otherwise legend may come out with 824 ## the wrong length text/symbol with prior results embedded. 825 text = " "; 826 text(nlegend,1:length(" ")) = " "; 827 symbols = " "; 828 symbols(nlegend,1:length(" ")) = " "; 829 830 for i=0:nlegend-1 831 opt_array(i+1) = PL_LEGEND_COLOR_BOX; 832 string = sprintf("%s %d", "Box Line Width",i+1); 833 text(i+1,1:length(string)) = string; 834 text_colors(i+1) = 2; 835 box_colors(i+1) = 2; 836 box_patterns(i+1) = 3; 837 box_scales(i+1) = 0.8; 838 box_line_widths(i+1) = double(i+1); 839 endfor 840 841 opt = opt_base; 842 x += legend_width; 843 plscol0a( 15, 32, 32, 32, 0.70 ); 844 [legend_width, legend_height] = ... 845 pllegend( opt, position, x, y, 846 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0, 847 0., text_colors, text, 848 box_colors, box_patterns, box_scales, box_line_widths, 849 [], [], [], 850 [], [], [], [] ); 851 max_height = max(max_height, legend_height); 852 853 ## Set up line legend entries with various colours. 854 ## From here on use the cell array of strings paradigm for 855 ## text (and symbols) to show that the PLplot interface works properly for 856 ## this case (and also to demonstrate how to use a cell array of strings 857 ## with PLplot). 858 ## Reset text and symbols cell arrays. 859 text = {}; 860 text{nlegend} = ""; 861 symbols = {}; 862 symbols{nlegend} = ""; 863 864 for i=0:nlegend-1 865 opt_array(i+1) = PL_LEGEND_LINE; 866 text{i+1} = sprintf("%s %d", "Line Color",i+1); 867 text_colors(i+1) = i+1; 868 line_colors(i+1) = i+1; 869 line_styles(i+1) = 1; 870 line_widths(i+1) = 1; 871 endfor 872 873 opt = opt_base; 874 ## Use new origin 875 x = xstart; 876 y += max_height; 877 max_height = 0.; 878 plscol0a( 15, 32, 32, 32, 0.70 ); 879 [legend_width, legend_height] = ... 880 pllegend( opt, position, x, y, 881 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0, 882 0., text_colors, text', 883 [], [], [], [], 884 line_colors, line_styles, line_widths, 885 [], [], [], [] ); 886 max_height = max(max_height, legend_height); 887 888 ## Set up line legend entries with various styles 889 ## Reset text and symbols cell arrays. 890 text = {}; 891 text{nlegend} = ""; 892 symbols = {}; 893 symbols{nlegend} = ""; 894 895 for i=0:nlegend-1 896 opt_array(i+1) = PL_LEGEND_LINE; 897 text{i+1} = sprintf("%s %d", "Line Style",i+1); 898 text_colors(i+1) = 2; 899 line_colors(i+1) = 2; 900 line_styles(i+1) = i+1; 901 line_widths(i+1) = 1; 902 endfor 903 opt = opt_base; 904 x += legend_width; 905 plscol0a( 15, 32, 32, 32, 0.70 ); 906 [legend_width, legend_height] = ... 907 pllegend( opt, position, x, y, 908 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0, 909 0., text_colors, text', 910 [], [], [], [], 911 line_colors, line_styles, line_widths, 912 [], [], [], [] ); 913 max_height = max(max_height, legend_height); 914 915 ## Set up line legend entries with various widths. 916 ## Reset text and symbols cell arrays. 917 text = {}; 918 text{nlegend} = ""; 919 symbols = {}; 920 symbols{nlegend} = ""; 921 922 for i=0:nlegend-1 923 opt_array(i+1) = PL_LEGEND_LINE; 924 text{i+1} = sprintf("%s %d", "Line Width",i+1); 925 text_colors(i+1) = 2; 926 line_colors(i+1) = 2; 927 line_styles(i+1) = 1; 928 line_widths(i+1) = i+1; 929 endfor 930 931 opt = opt_base; 932 x += legend_width; 933 plscol0a( 15, 32, 32, 32, 0.70 ); 934 [legend_width, legend_height] = ... 935 pllegend( opt, position, x, y, 936 0.1, 15, 1, 1, 0, 0, opt_array, 1.0, text_scale, 2.0, 937 0., text_colors, text', 938 [], [], [], [], 939 line_colors, line_styles, line_widths, 940 [], [], [], [] ); 941 max_height = max(max_height, legend_height); 942 943 # Color bar examples 944 values_small = [ -1.0e-20, 1.0e-20 ]; 945 values_uneven = [ -1.0e-20, 2.0e-20, 2.6e-20, 3.4e-20, 6.0e-20, 7.0e-20, 8.0e-20, 9.0e-20, 10.0e-20 ]; 946 values_even = [ -2.0e-20, -1.0e-20, 0.0e-20, 1.0e-20, 2.0e-20, 3.0e-20, 4.0e-20, 5.0e-20, 6.0e-20 ]; 947 948 # Use unsaturated green background colour to contrast with black caps. 949 plscolbg( 70, 185, 70 ); 950 # Cut out the greatest and smallest bits of the color spectrum to 951 # leave colors for the end caps. 952 plscmap1_range( 0.01, 0.99 ); 953 954 # We can only test image and gradient colorbars with two element arrays 955 for i = 3:COLORBAR_KINDS 956 plcolorbar_example( "cmap1_blue_yellow.pal", i, 0, 0, values_small ); 957 endfor 958 # Test shade colorbars with larger arrays 959 for i = 1:2 960 plcolorbar_example( "cmap1_blue_yellow.pal", i, 4, 2, values_even ); 961 endfor 962 for i = 1:2 963 plcolorbar_example( "cmap1_blue_yellow.pal", i, 0, 0, values_uneven ); 964 endfor 965 plend1(); 966endfunction 967 968ix33c() 969