comparison scripts/plot/__go_draw_axes__.m @ 7119:d22ad51b9cf8

[project @ 2007-11-07 21:06:27 by jwe]
author jwe
date Wed, 07 Nov 2007 21:09:05 +0000
parents 926fc75fb02e
children a2174fb073d4
comparison
equal deleted inserted replaced
7118:d32f867e4dda 7119:d22ad51b9cf8
235 if (use_gnuplot_for_images) 235 if (use_gnuplot_for_images)
236 236
237 data_idx++; 237 data_idx++;
238 is_image_data(data_idx) = true; 238 is_image_data(data_idx) = true;
239 parametric(data_idx) = false; 239 parametric(data_idx) = false;
240 have_cdata(data_idx) = false;
240 241
241 [y_dim, x_dim] = size (img_data(:,:,1)); 242 [y_dim, x_dim] = size (img_data(:,:,1));
242 if (x_dim > 1) 243 if (x_dim > 1)
243 dx = abs (img_xdata(2)-img_xdata(1))/(x_dim-1); 244 dx = abs (img_xdata(2)-img_xdata(1))/(x_dim-1);
244 else 245 else
298 299
299 case "line" 300 case "line"
300 data_idx++; 301 data_idx++;
301 is_image_data(data_idx) = false; 302 is_image_data(data_idx) = false;
302 parametric(data_idx) = true; 303 parametric(data_idx) = true;
304 have_cdata(data_idx) = false;
303 if (isempty (obj.keylabel)) 305 if (isempty (obj.keylabel))
304 titlespec{data_idx} = "title \"\""; 306 titlespec{data_idx} = "title \"\"";
305 else 307 else
306 tmp = undo_string_escapes (obj.keylabel); 308 tmp = undo_string_escapes (obj.keylabel);
307 titlespec{data_idx} = strcat ("title \"", tmp, "\""); 309 titlespec{data_idx} = strcat ("title \"", tmp, "\"");
318 if (! isempty (obj.zdata)) 320 if (! isempty (obj.zdata))
319 nd = 3; 321 nd = 3;
320 xdat = obj.xdata(:); 322 xdat = obj.xdata(:);
321 ydat = obj.ydata(:); 323 ydat = obj.ydata(:);
322 zdat = obj.zdata(:); 324 zdat = obj.zdata(:);
325
323 if (xautoscale) 326 if (xautoscale)
324 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat); 327 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat);
325 endif 328 endif
326 if (yautoscale) 329 if (yautoscale)
327 [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ydat); 330 [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ydat);
330 [zmin, zmax, zminp] = get_data_limits (zmin, zmax, zminp, zdat); 333 [zmin, zmax, zminp] = get_data_limits (zmin, zmax, zminp, zdat);
331 endif 334 endif
332 data{data_idx} = [xdat, ydat, zdat]'; 335 data{data_idx} = [xdat, ydat, zdat]';
333 usingclause{data_idx} = "using ($1):($2):($3)"; 336 usingclause{data_idx} = "using ($1):($2):($3)";
334 fputs (plot_stream, "set parametric;\n"); 337 fputs (plot_stream, "set parametric;\n");
335 fputs (plot_stream, "unset hidden3d;\n"); 338 fputs (plot_stream, "set hidden3d;\n");
336 fputs (plot_stream, "set style data lines;\n"); 339 fputs (plot_stream, "set style data lines;\n");
337 fputs (plot_stream, "set surface;\n"); 340 fputs (plot_stream, "set surface;\n");
338 fputs (plot_stream, "unset contour;\n"); 341 fputs (plot_stream, "unset contour;\n");
339 else 342 else
340 nd = 2; 343 nd = 2;
444 if (! isnan (xcol) && ! isnan (ycol)) 447 if (! isnan (xcol) && ! isnan (ycol))
445 ## Is the patch closed or not 448 ## Is the patch closed or not
446 data_idx++; 449 data_idx++;
447 is_image_data(data_idx) = false; 450 is_image_data(data_idx) = false;
448 parametric(data_idx) = false; 451 parametric(data_idx) = false;
452 have_cdata(data_idx) = false;
449 titlespec{data_idx} = "title \"\""; 453 titlespec{data_idx} = "title \"\"";
450 usingclause{data_idx} = ""; 454 usingclause{data_idx} = "";
451 if (isfield (obj, "facecolor") && isfield (obj, "cdata")) 455 if (isfield (obj, "facecolor") && isfield (obj, "cdata"))
452 if (strncmp (obj.facecolor, "none", 4)) 456 if (strncmp (obj.facecolor, "none", 4))
453 color = [1, 1, 1]; 457 color = [1, 1, 1];
454 458
455 elseif (strncmp (obj.facecolor, "flat", 4) || 459 elseif (strncmp (obj.facecolor, "flat", 4)
456 strncmp (obj.facecolor, "interp", 6)) 460 || strncmp (obj.facecolor, "interp", 6))
457 if (ndims (obj.cdata) == 2 && ... 461 if (ndims (obj.cdata) == 2
458 ((nr > 3 && size (obj.cdata, 2) == nc) ... 462 && ((nr > 3 && size (obj.cdata, 2) == nc)
459 || (size (obj.cdata, 1) > 1 && ... 463 || (size (obj.cdata, 1) > 1
460 size (obj.cdata, 2) == nc))) 464 && size (obj.cdata, 2) == nc)))
461 ccol = obj.cdata (:, i); 465 ccol = obj.cdata (:, i);
462 elseif (ndims (obj.cdata) == 3) 466 elseif (ndims (obj.cdata) == 3)
463 ccol = permute (obj.cdata (:, i, :), [1, 3, 2]); 467 ccol = permute (obj.cdata (:, i, :), [1, 3, 2]);
464 else 468 else
465 ccol = obj.cdata; 469 ccol = obj.cdata;
466 endif 470 endif
467 if (strncmp (obj.facecolor, "flat", 4)) 471 if (strncmp (obj.facecolor, "flat", 4))
468 if (numel(ccol) == 3) 472 if (numel(ccol) == 3)
469 color = ccol; 473 color = ccol;
470 else 474 else
471 r = 1 + round ((size (cmap, 1) - 1) * ... 475 r = 1 + round ((size (cmap, 1) - 1)
472 (ccol - clim(1))/(clim(2) - clim(1))); 476 * (ccol - clim(1))/(clim(2) - clim(1)));
473 r = max (1, min (r, size (cmap, 1))); 477 r = max (1, min (r, size (cmap, 1)));
474 color = cmap(r, :); 478 color = cmap(r, :);
475 endif 479 endif
476 elseif (strncmp (obj.facecolor, "interp", 6)) 480 elseif (strncmp (obj.facecolor, "interp", 6))
477 warning ("\"interp\" not supported, using 1st entry of cdata") 481 warning ("\"interp\" not supported, using 1st entry of cdata")
485 else 489 else
486 color = [0, 1, 0]; 490 color = [0, 1, 0];
487 endif 491 endif
488 492
489 if (have_newer_gnuplot) 493 if (have_newer_gnuplot)
490 withclause{data_idx} = ... 494 withclause{data_idx} ...
491 sprintf ("with filledcurve lc rgb \"#%02x%02x%02x\"", ... 495 = sprintf ("with filledcurve lc rgb \"#%02x%02x%02x\"",
492 round (255*color)); 496 round (255*color));
493 else 497 else
494 if (isequal (color, [0,0,0])) 498 if (isequal (color, [0,0,0]))
495 typ = -1; 499 typ = -1;
496 elseif (isequal (color, [1,0,0])) 500 elseif (isequal (color, [1,0,0]))
497 typ = 1; 501 typ = 1;
518 522
519 ## patch outline 523 ## patch outline
520 data_idx++; 524 data_idx++;
521 is_image_data(data_idx) = false; 525 is_image_data(data_idx) = false;
522 parametric(data_idx) = false; 526 parametric(data_idx) = false;
527 have_cdata(data_idx) = false;
523 titlespec{data_idx} = "title \"\""; 528 titlespec{data_idx} = "title \"\"";
524 usingclause{data_idx} = ""; 529 usingclause{data_idx} = "";
525 if (isfield (obj, "edgecolor")) 530 if (isfield (obj, "edgecolor"))
526 if (strncmp (obj.edgecolor, "none", 4)) 531 if (strncmp (obj.edgecolor, "none", 4))
527 color = [1, 1, 1]; 532 color = [1, 1, 1];
536 endif 541 endif
537 else 542 else
538 color = [0, 0, 0]; 543 color = [0, 0, 0];
539 endif 544 endif
540 if (have_newer_gnuplot) 545 if (have_newer_gnuplot)
541 withclause{data_idx} = ... 546 withclause{data_idx} ...
542 sprintf ("with lines lc rgb \"#%02x%02x%02x\"", ... 547 = sprintf ("with lines lc rgb \"#%02x%02x%02x\"",
543 round (255*color)); 548 round (255*color));
544 else 549 else
545 if (isequal (color, [0,0,0])) 550 if (isequal (color, [0,0,0]))
546 typ = -1; 551 typ = -1;
547 elseif (isequal (color, [1,0,0])) 552 elseif (isequal (color, [1,0,0]))
548 typ = 1; 553 typ = 1;
562 typ = -1; 567 typ = -1;
563 endif 568 endif
564 withclause{data_idx} = sprintf ("with lines lt %d", typ); 569 withclause{data_idx} = sprintf ("with lines lt %d", typ);
565 endif 570 endif
566 571
567 if (!isnan (xcol) && !isnan (ycol)) 572 if (!isnan (xcol) && ! isnan (ycol))
568 data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)]]'; 573 data{data_idx} = [[xcol; xcol(1)], [ycol; ycol(1)]]';
569 else 574 else
570 data{data_idx} = [xcol, ycol]'; 575 data{data_idx} = [xcol, ycol]';
571 endif 576 endif
572 usingclause{data_idx} = "using ($1):($2)"; 577 usingclause{data_idx} = "using ($1):($2)";
573 endfor 578 endfor
574 579
575 case "surface" 580 case "surface"
576 nd = 4; 581 nd = 3;
577 if (! (strncmp (obj.edgecolor, "none", 4) 582 if (! (strncmp (obj.edgecolor, "none", 4)
578 && strncmp (obj.facecolor, "none", 4))) 583 && strncmp (obj.facecolor, "none", 4)))
579 data_idx++; 584 data_idx++;
580 is_image_data(data_idx) = false; 585 is_image_data(data_idx) = false;
581 parametric(data_idx) = false; 586 parametric(data_idx) = false;
587 have_cdata(data_idx) = true;
582 [style, typ, with] = do_linestyle_command (obj, data_idx, plot_stream); 588 [style, typ, with] = do_linestyle_command (obj, data_idx, plot_stream);
583 if (isempty (obj.keylabel)) 589 if (isempty (obj.keylabel))
584 titlespec{data_idx} = "title \"\""; 590 titlespec{data_idx} = "title \"\"";
585 else 591 else
586 tmp = undo_string_escapes (obj.keylabel); 592 tmp = undo_string_escapes (obj.keylabel);
662 fputs (plot_stream, "set style data lines;\n"); 668 fputs (plot_stream, "set style data lines;\n");
663 fputs (plot_stream, "set surface;\n"); 669 fputs (plot_stream, "set surface;\n");
664 fputs (plot_stream, "unset contour;\n"); 670 fputs (plot_stream, "unset contour;\n");
665 fprintf (plot_stream, "set cbrange [%g:%g];\n", cmin, cmax); 671 fprintf (plot_stream, "set cbrange [%g:%g];\n", cmin, cmax);
666 672
667 if (have_newer_gnuplot) 673 ## Interpolation does not work for flat surfaces (e.g. pcolor)
668 ## Interpolation does not work for flat surfaces (e.g. pcolor) 674 ## and color mapping --> currently set empty.
669 ## and color mapping --> currently set empty. 675 interp_str = "";
670 interp_str = ""; 676 surf_colormap = parent_figure_obj.colormap;
671 surf_colormap = parent_figure_obj.colormap; 677 flat_interp_face = (strncmp (obj.facecolor, "flat", 4)
672 flat_interp_face = (strncmp (obj.facecolor, "flat", 4) 678 || strncmp (obj.facecolor, "interp", 6));
673 || strncmp (obj.facecolor, "interp", 6)); 679 flat_interp_edge = (strncmp (obj.edgecolor, "flat", 4)
674 flat_interp_edge = (strncmp (obj.edgecolor, "flat", 4) 680 || strncmp (obj.edgecolor, "interp", 6));
675 || strncmp (obj.edgecolor, "interp", 6)); 681 palette_data = [];
676 palette_data = []; 682
677 683 if (flat_interp_face
678 if (flat_interp_face 684 || (flat_interp_edge && strncmp (obj.facecolor, "none", 4)))
679 || (flat_interp_edge && strncmp (obj.facecolor, "none", 4))) 685 palette_data = [1:rows(surf_colormap); surf_colormap'];
680 palette_data = [1:rows(surf_colormap); surf_colormap']; 686 endif
681 endif 687
682 688 if (isnumeric (obj.facecolor))
683 if (isnumeric (obj.facecolor)) 689 palette_data = [1:2; [obj.facecolor; obj.facecolor]'];
684 palette_data = [1:2; [obj.facecolor; obj.facecolor]']; 690 endif
685 endif 691
686 692 if (strncmp (obj.facecolor, "none", 4)
687 if (strncmp (obj.facecolor, "none", 4) 693 && isnumeric (obj.edgecolor))
688 && isnumeric (obj.edgecolor)) 694 palette_data = [1:2; [obj.edgecolor; obj.edgecolor]'];
689 palette_data = [1:2; [obj.edgecolor; obj.edgecolor]']; 695 endif
690 endif 696
691 697 if (strncmp (obj.facecolor, "none", 4))
692 if (strncmp (obj.facecolor, "none", 4)) 698 elseif (flat_interp_face && strncmp (obj.edgecolor, "flat", 4))
693 elseif (flat_interp_face && strncmp (obj.edgecolor, "flat", 4)) 699 fprintf (plot_stream, "set pm3d at s %s;\n", interp_str);
700 else
701 if (strncmp (obj.edgecolor, "none", 4))
694 fprintf (plot_stream, "set pm3d at s %s;\n", interp_str); 702 fprintf (plot_stream, "set pm3d at s %s;\n", interp_str);
695 else 703 else
696 if (strncmp(obj.edgecolor, "none", 4)) 704 edgecol = obj.edgecolor;
697 fprintf (plot_stream, "set pm3d at s %s;\n", interp_str); 705 if (ischar (obj.edgecolor))
698 else 706 edgecol = [0,0,0];
699 edgecol = obj.edgecolor; 707 endif
700 if (ischar(obj.edgecolor)) 708 fprintf (plot_stream, "set pm3d at s hidden3d %d %s;\n", data_idx, interp_str);
701 edgecol = [0 0 0]; 709
702 endif 710 if (have_newer_gnuplot)
703 fprintf (plot_stream, "set pm3d at s hidden3d %d %s;\n", data_idx, interp_str);
704 fprintf (plot_stream, 711 fprintf (plot_stream,
705 "set style line %d linecolor rgb \"#%02x%02x%02x\" lw %f;\n", 712 "set style line %d linecolor rgb \"#%02x%02x%02x\" lw %f;\n",
706 data_idx, round (255*edgecol), obj.linewidth); 713 data_idx, round (255*edgecol), obj.linewidth);
707 endif 714 else
715 if (isequal (edgecol, [0,0,0]))
716 typ = -1;
717 elseif (isequal (edgecol, [1,0,0]))
718 typ = 1;
719 elseif (isequal (edgecol, [0,1,0]))
720 typ = 2;
721 elseif (isequal (edgecol, [0,0,1]))
722 typ = 3;
723 elseif (isequal (edgecol, [1,0,1]))
724 typ = 4;
725 elseif (isequal (edgecol, [0,1,1]))
726 typ = 5;
727 elseif (isequal (edgecol, [1,1,1]))
728 typ = -1;
729 elseif (isequal (edgecol, [1,1,0]))
730 typ = 7;
731 else
732 typ = -1;
733 endif
734 fprintf (plot_stream,
735 "set style line %d lt %d lw %f;\n",
736 data_idx, typ, obj.linewidth);
737 endif
708 endif 738 endif
709 739 endif
740
741 if (have_newer_gnuplot)
710 if (length(palette_data) > 0) 742 if (length(palette_data) > 0)
711 fprintf (plot_stream, 743 fprintf (plot_stream,
712 "set palette positive color model RGB maxcolors %i;\n", 744 "set palette positive color model RGB maxcolors %i;\n",
713 columns(palette_data)); 745 columns(palette_data));
714 fprintf (plot_stream, 746 fprintf (plot_stream,
819 ydir = "noreverse"; 851 ydir = "noreverse";
820 endif 852 endif
821 fprintf (plot_stream, "set %srange [%.15e:%.15e] %s;\n", 853 fprintf (plot_stream, "set %srange [%.15e:%.15e] %s;\n",
822 yaxisloc, ylim, ydir); 854 yaxisloc, ylim, ydir);
823 855
824 if (nd == 3 || nd == 4) 856 if (nd == 3)
825 if (zautoscale && have_data) 857 if (zautoscale && have_data)
826 zlim = get_axis_limits (zmin, zmax, zminp, zlogscale); 858 zlim = get_axis_limits (zmin, zmax, zminp, zlogscale);
827 if (isempty (zlim)) 859 if (isempty (zlim))
828 return; 860 return;
829 endif 861 endif
838 endif 870 endif
839 fprintf (plot_stream, "set zrange [%.15e:%.15e] %s;\n", zlim, zdir); 871 fprintf (plot_stream, "set zrange [%.15e:%.15e] %s;\n", zlim, zdir);
840 endif 872 endif
841 873
842 if (strcmpi (axis_obj.box, "on")) 874 if (strcmpi (axis_obj.box, "on"))
843 if (nd == 3 || nd == 4) 875 if (nd == 3)
844 fputs (plot_stream, "set border 4095;\n"); 876 fputs (plot_stream, "set border 4095;\n");
845 else 877 else
846 fputs (plot_stream, "set border 431;\n"); 878 fputs (plot_stream, "set border 431;\n");
847 endif 879 endif
848 else 880 else
849 if (nd == 3 || nd == 4) 881 if (nd == 3)
850 fputs (plot_stream, "set border 895;\n"); 882 fputs (plot_stream, "set border 895;\n");
851 else 883 else
852 fputs (plot_stream, "set border 3;\n"); 884 fputs (plot_stream, "set border 3;\n");
853 fputs (plot_stream, "set xtics nomirror; set ytics nomirror;\n"); 885 fputs (plot_stream, "set xtics nomirror; set ytics nomirror;\n");
854 endif 886 endif
869 if (ischar (keypos)) 901 if (ischar (keypos))
870 keypos = lower (keypos); 902 keypos = lower (keypos);
871 keyout = findstr (keypos, "outside"); 903 keyout = findstr (keypos, "outside");
872 if (! isempty (keyout)) 904 if (! isempty (keyout))
873 inout = "outside"; 905 inout = "outside";
874 keypos = keypos (1:keyout-1); 906 keypos = keypos(1:keyout-1);
875 endif 907 endif
876 endif 908 endif
877 switch (keypos) 909 switch (keypos)
878 case -1 910 case -1
879 pos = "right top"; 911 pos = "right top";
949 fputs (plot_stream, ";\n"); 981 fputs (plot_stream, ";\n");
950 for i = 1:data_idx 982 for i = 1:data_idx
951 if (is_image_data(i)) 983 if (is_image_data(i))
952 fwrite (plot_stream, data{i}, "float32"); 984 fwrite (plot_stream, data{i}, "float32");
953 else 985 else
954 __gnuplot_write_data__ (plot_stream, data{i}, nd, parametric(i)); 986 __gnuplot_write_data__ (plot_stream, data{i}, nd, parametric(i),
987 have_cdata(i));
955 endif 988 endif
956 endfor 989 endfor
957 else 990 else
958 fputs (plot_stream, "plot \"-\";\nInf Inf\ne\n"); 991 fputs (plot_stream, "plot \"-\";\nInf Inf\ne\n");
959 endif 992 endif
965 endif 998 endif
966 999
967 endfunction 1000 endfunction
968 1001
969 function [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat, tx) 1002 function [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat, tx)
970 if (! (isempty (xdat) || isempty (tx))) 1003 if (! (isempty (xdat) || (nargin > 4 && isempty (tx))))
971 xdat = xdat(! isinf (xdat)); 1004 xdat = xdat(! isinf (xdat));
972 xmin = min (xmin, min (xdat)); 1005 xmin = min (xmin, min (xdat));
973 xmax = max (xmax, max (xdat)); 1006 xmax = max (xmax, max (xdat));
974 if (nargin == 5) 1007 if (nargin == 5)
975 tx = tx(! isinf (xdat) & tx > 0); 1008 tx = tx(! isinf (xdat) & tx > 0);
1188 1221
1189 fputs (plot_stream, ";\n"); 1222 fputs (plot_stream, ";\n");
1190 1223
1191 endfunction 1224 endfunction
1192 1225
1193 function __gnuplot_write_data__ (plot_stream, data, nd, parametric) 1226 function __gnuplot_write_data__ (plot_stream, data, nd, parametric, cdata)
1194 1227
1195 ## DATA is already transposed. 1228 ## DATA is already transposed.
1196 1229
1197 ## FIXME -- this may need to be converted to C++ for speed. 1230 ## FIXME -- this may need to be converted to C++ for speed.
1198 1231
1226 ## FIXME -- handle NaNs here too? 1259 ## FIXME -- handle NaNs here too?
1227 if (parametric) 1260 if (parametric)
1228 fprintf (plot_stream, "%.15g %.15g %.15g\n", data); 1261 fprintf (plot_stream, "%.15g %.15g %.15g\n", data);
1229 else 1262 else
1230 nc = columns (data); 1263 nc = columns (data);
1231 for j = 1:3:nc 1264 if (cdata)
1232 fprintf (plot_stream, "%.15g %.15g %.15g\n", data(:,j:j+2)'); 1265 for j = 1:4:nc
1233 fputs (plot_stream, "\n"); 1266 fprintf (plot_stream, "%.15g %.15g %.15g %.15g\n", data(:,j:j+3)');
1234 endfor 1267 fputs (plot_stream, "\n");
1235 endif 1268 endfor
1236 elseif (nd == 4) 1269 else
1237 ## FIXME -- handle NaNs here too? 1270 for j = 1:3:nc
1238 if (parametric) 1271 fprintf (plot_stream, "%.15g %.15g %.15g\n", data(:,j:j+2)');
1239 fprintf (plot_stream, "%.15g %.15g %.15g\n", data); 1272 fputs (plot_stream, "\n");
1240 else 1273 endfor
1241 nc = columns (data); 1274 endif
1242 for j = 1:4:nc
1243 fprintf (plot_stream, "%.15g %.15g %.15g %.15g\n", data(:,j:j+3)');
1244 fputs (plot_stream, "\n");
1245 endfor
1246 endif 1275 endif
1247 endif 1276 endif
1248 fputs (plot_stream, "e\n"); 1277 fputs (plot_stream, "e\n");
1249 1278
1250 endfunction 1279 endfunction