Mercurial > hg > octave-nkf
comparison scripts/plot/__go_draw_axes__.m @ 7222:dd8b3bbeeaf9
[project @ 2007-11-30 06:23:25 by jwe]
author | jwe |
---|---|
date | Fri, 30 Nov 2007 06:23:26 +0000 |
parents | 66081694ffb8 |
children | 868101dc4404 |
comparison
equal
deleted
inserted
replaced
7221:2636c0846924 | 7222:dd8b3bbeeaf9 |
---|---|
245 data_idx = 0; | 245 data_idx = 0; |
246 data = cell (); | 246 data = cell (); |
247 is_image_data = []; | 247 is_image_data = []; |
248 hidden_removal = NaN; | 248 hidden_removal = NaN; |
249 | 249 |
250 xminp = yminp = zminp = cminp = Inf; | 250 xlim = axis_obj.xlim |
251 xmax = ymax = zmax = cmax = -Inf; | 251 ylim = axis_obj.ylim |
252 xmin = ymin = zmin = cmin = Inf; | 252 zlim = axis_obj.zlim |
253 | 253 clim = axis_obj.clim |
254 ## This has to be done here as some of the code below depends on the | 254 |
255 ## final clim. | 255 if (! cautoscale && clim(1) == clim(2)) |
256 if (cautoscale) | 256 clim(2)++; |
257 for i = 1:length (kids) | |
258 obj = get (kids(i)); | |
259 if (isfield (obj, "cdata")) | |
260 cdat = obj.cdata(:); | |
261 [cmin, cmax, cminp] = get_data_limits (cmin, cmax, cminp, cdat); | |
262 endif | |
263 endfor | |
264 if (cmin == cmax) | |
265 cmax = cmin + 1; | |
266 endif | |
267 clim = [cmin, cmax]; | |
268 else | |
269 clim = axis_obj.clim; | |
270 if (clim(1) == clim(2)) | |
271 clim = [clim(1), clim(1) + 1]; | |
272 endif | |
273 endif | 257 endif |
274 | 258 |
275 [view_cmd, view_fcn, view_zoom] = image_viewer (); | 259 [view_cmd, view_fcn, view_zoom] = image_viewer (); |
276 use_gnuplot_for_images = (ischar (view_fcn) | 260 use_gnuplot_for_images = (ischar (view_fcn) |
277 && strcmp (view_fcn, "gnuplot_internal")); | 261 && strcmp (view_fcn, "gnuplot_internal")); |
315 else | 299 else |
316 dy = 1; | 300 dy = 1; |
317 endif | 301 endif |
318 x_origin = min (img_xdata); | 302 x_origin = min (img_xdata); |
319 y_origin = min (img_ydata); | 303 y_origin = min (img_ydata); |
320 | |
321 if (nd == 2) | |
322 if (xautoscale) | |
323 xmin = min (xmin, min (img_xdata) - dx/2); | |
324 xmax = max (xmax, max (img_xdata) + dx/2); | |
325 xminp = min (xminp, min (img_xdata((img_xdata - dx/2)>0)) - dx/2); | |
326 endif | |
327 if (yautoscale) | |
328 ymin = min (ymin, min (img_ydata) - dy/2); | |
329 ymax = max (ymax, max (img_ydata) + dy/2); | |
330 yminp = min (yminp, min (img_ydata((img_ydata - dy/2)>0)) - dy/2); | |
331 endif | |
332 else | |
333 ## Can have images in 3D, but the image routines don't seem | |
334 ## to have a means of arbitrary projection. | |
335 endif | |
336 | 304 |
337 if (ndims (img_data) == 3) | 305 if (ndims (img_data) == 3) |
338 data{data_idx} = permute (img_data, [3, 1, 2])(:); | 306 data{data_idx} = permute (img_data, [3, 1, 2])(:); |
339 format = "1:2:3"; | 307 format = "1:2:3"; |
340 imagetype = "rgbimage"; | 308 imagetype = "rgbimage"; |
383 nd = 3; | 351 nd = 3; |
384 xdat = obj.xdata(:); | 352 xdat = obj.xdata(:); |
385 ydat = obj.ydata(:); | 353 ydat = obj.ydata(:); |
386 zdat = obj.zdata(:); | 354 zdat = obj.zdata(:); |
387 | 355 |
388 if (xautoscale) | |
389 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat); | |
390 endif | |
391 if (yautoscale) | |
392 [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ydat); | |
393 endif | |
394 if (zautoscale) | |
395 [zmin, zmax, zminp] = get_data_limits (zmin, zmax, zminp, zdat); | |
396 endif | |
397 data{data_idx} = [xdat, ydat, zdat]'; | 356 data{data_idx} = [xdat, ydat, zdat]'; |
398 usingclause{data_idx} = "using ($1):($2):($3)"; | 357 usingclause{data_idx} = "using ($1):($2):($3)"; |
399 fputs (plot_stream, "set parametric;\n"); | 358 fputs (plot_stream, "set parametric;\n"); |
400 fputs (plot_stream, "set style data lines;\n"); | 359 fputs (plot_stream, "set style data lines;\n"); |
401 fputs (plot_stream, "set surface;\n"); | 360 fputs (plot_stream, "set surface;\n"); |
447 if (isempty (xudat)) | 406 if (isempty (xudat)) |
448 xhi = xdat; | 407 xhi = xdat; |
449 else | 408 else |
450 xhi = xdat+xudat; | 409 xhi = xdat+xudat; |
451 endif | 410 endif |
452 if (xautoscale) | |
453 tx = [xdat; xlo; xhi]; | |
454 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, tx); | |
455 endif | |
456 data{data_idx} = [xdat, ydat, xlo, xhi, ylo, yhi]'; | 411 data{data_idx} = [xdat, ydat, xlo, xhi, ylo, yhi]'; |
457 usingclause{data_idx} = "using ($1):($2):($3):($4):($5):($6)"; | 412 usingclause{data_idx} = "using ($1):($2):($3):($4):($5):($6)"; |
458 withclause{data_idx} = "with xyerrorbars"; | 413 withclause{data_idx} = "with xyerrorbars"; |
459 else | 414 else |
460 if (xautoscale) | |
461 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat); | |
462 endif | |
463 data{data_idx} = [xdat, ydat, ylo, yhi]'; | 415 data{data_idx} = [xdat, ydat, ylo, yhi]'; |
464 usingclause{data_idx} = "using ($1):($2):($3):($4)"; | 416 usingclause{data_idx} = "using ($1):($2):($3):($4)"; |
465 withclause{data_idx} = "with yerrorbars"; | 417 withclause{data_idx} = "with yerrorbars"; |
466 endif | 418 endif |
467 elseif (xerr) | 419 elseif (xerr) |
468 if (isempty (xldat)) | |
469 xlo = xdat; | |
470 else | |
471 xlo = xdat-xldat; | |
472 endif | |
473 if (isempty (xudat)) | |
474 xhi = xdat; | |
475 else | |
476 xhi = xdat+xudat; | |
477 endif | |
478 if (xautoscale) | |
479 tx = [xdat; xlo; xhi]; | |
480 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, tx); | |
481 endif | |
482 if (yautoscale) | |
483 [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ydat); | |
484 endif | |
485 data{data_idx} = [xdat, ydat, xlo, xhi]'; | 420 data{data_idx} = [xdat, ydat, xlo, xhi]'; |
486 usingclause{data_idx} = "using ($1):($2):($3):($4)"; | 421 usingclause{data_idx} = "using ($1):($2):($3):($4)"; |
487 withclause{data_idx} = "with xerrorbars"; | 422 withclause{data_idx} = "with xerrorbars"; |
488 else | 423 else |
489 if (xautoscale) | |
490 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat); | |
491 endif | |
492 if (yautoscale) | |
493 [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ydat); | |
494 endif | |
495 data{data_idx} = [xdat, ydat]'; | 424 data{data_idx} = [xdat, ydat]'; |
496 usingclause{data_idx} = sprintf ("using ($1):($2) axes %s%s", | 425 usingclause{data_idx} = sprintf ("using ($1):($2) axes %s%s", |
497 xaxisloc_using, yaxisloc_using); | 426 xaxisloc_using, yaxisloc_using); |
498 endif | 427 endif |
499 endif | 428 endif |
521 ycol = obj.ydata(:,i); | 450 ycol = obj.ydata(:,i); |
522 if (! isempty (obj.zdata)) | 451 if (! isempty (obj.zdata)) |
523 zcol = obj.zdata(:,i); | 452 zcol = obj.zdata(:,i); |
524 else | 453 else |
525 zcol = []; | 454 zcol = []; |
526 endif | |
527 | |
528 if (xautoscale) | |
529 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xcol); | |
530 endif | |
531 if (yautoscale) | |
532 [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ycol); | |
533 endif | |
534 if (! isempty (obj.zdata) && ! strncmp(obj.edgecolor, "none", 4)) | |
535 if (zautoscale) | |
536 [zmin, zmax, zminp] = get_data_limits (zmin, zmax, zminp, zcol); | |
537 endif | |
538 endif | 455 endif |
539 | 456 |
540 if (! isnan (xcol) && ! isnan (ycol)) | 457 if (! isnan (xcol) && ! isnan (ycol)) |
541 ## Is the patch closed or not | 458 ## Is the patch closed or not |
542 if (strncmp (obj.facecolor, "none", 4)) | 459 if (strncmp (obj.facecolor, "none", 4)) |
869 xdat = obj.xdata; | 786 xdat = obj.xdata; |
870 ydat = obj.ydata; | 787 ydat = obj.ydata; |
871 zdat = obj.zdata; | 788 zdat = obj.zdata; |
872 cdat = obj.cdata; | 789 cdat = obj.cdata; |
873 | 790 |
874 if (xautoscale) | |
875 tx = xdat(:); | |
876 [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, tx); | |
877 endif | |
878 if (yautoscale) | |
879 ty = ydat(:); | |
880 [ymin, ymax, yminp] = get_data_limits (ymin, ymax, yminp, ty); | |
881 endif | |
882 if (zautoscale) | |
883 tz = zdat(:); | |
884 [zmin, zmax, zminp] = get_data_limits (zmin, zmax, zminp, tz); | |
885 endif | |
886 | |
887 err = false; | 791 err = false; |
888 if (! size_equal(zdat, cdat)) | 792 if (! size_equal(zdat, cdat)) |
889 err = true; | 793 err = true; |
890 endif | 794 endif |
891 if (isvector (xdat) && isvector (ydat) && ismatrix (zdat)) | 795 if (isvector (xdat) && isvector (ydat) && ismatrix (zdat)) |
1051 fputs (plot_stream, "unset hidden3d;\n"); | 955 fputs (plot_stream, "unset hidden3d;\n"); |
1052 endif | 956 endif |
1053 | 957 |
1054 have_data = (! (isempty (data) || any (cellfun (@isempty, data)))); | 958 have_data = (! (isempty (data) || any (cellfun (@isempty, data)))); |
1055 | 959 |
1056 if (xautoscale && have_data) | 960 if (isempty (xlim)) |
1057 xlim = get_axis_limits (xmin, xmax, xminp, xlogscale); | 961 return; |
1058 if (isempty (xlim)) | |
1059 return; | |
1060 endif | |
1061 set (h, "xlim", xlim, "xlimmode", "auto"); | |
1062 else | |
1063 xlim = axis_obj.xlim; | |
1064 endif | 962 endif |
1065 if (strcmpi (axis_obj.xdir, "reverse")) | 963 if (strcmpi (axis_obj.xdir, "reverse")) |
1066 xdir = "reverse"; | 964 xdir = "reverse"; |
1067 else | 965 else |
1068 xdir = "noreverse"; | 966 xdir = "noreverse"; |
1069 endif | 967 endif |
1070 fprintf (plot_stream, "set %srange [%.15e:%.15e] %s;\n", | 968 fprintf (plot_stream, "set %srange [%.15e:%.15e] %s;\n", |
1071 xaxisloc, xlim, xdir); | 969 xaxisloc, xlim, xdir); |
1072 | 970 |
1073 if (yautoscale && have_data) | 971 if (isempty (ylim)) |
1074 ylim = get_axis_limits (ymin, ymax, yminp, ylogscale); | 972 return; |
1075 if (isempty (ylim)) | |
1076 return; | |
1077 endif | |
1078 set (h, "ylim", ylim, "ylimmode", "auto"); | |
1079 else | |
1080 ylim = axis_obj.ylim; | |
1081 endif | 973 endif |
1082 if (strcmpi (axis_obj.ydir, "reverse")) | 974 if (strcmpi (axis_obj.ydir, "reverse")) |
1083 ydir = "reverse"; | 975 ydir = "reverse"; |
1084 else | 976 else |
1085 ydir = "noreverse"; | 977 ydir = "noreverse"; |
1086 endif | 978 endif |
1087 fprintf (plot_stream, "set %srange [%.15e:%.15e] %s;\n", | 979 fprintf (plot_stream, "set %srange [%.15e:%.15e] %s;\n", |
1088 yaxisloc, ylim, ydir); | 980 yaxisloc, ylim, ydir); |
1089 | 981 |
1090 if (nd == 3) | 982 if (nd == 3) |
1091 if (zautoscale && have_data) | 983 if (isempty (zlim)) |
1092 zlim = get_axis_limits (zmin, zmax, zminp, zlogscale); | 984 return; |
1093 if (isempty (zlim)) | |
1094 return; | |
1095 endif | |
1096 set (h, "zlim", zlim, "zlimmode", "auto"); | |
1097 else | |
1098 zlim = axis_obj.zlim; | |
1099 endif | 985 endif |
1100 if (strcmpi (axis_obj.zdir, "reverse")) | 986 if (strcmpi (axis_obj.zdir, "reverse")) |
1101 zdir = "reverse"; | 987 zdir = "reverse"; |
1102 else | 988 else |
1103 zdir = "noreverse"; | 989 zdir = "noreverse"; |
1104 endif | 990 endif |
1105 fprintf (plot_stream, "set zrange [%.15e:%.15e] %s;\n", zlim, zdir); | 991 fprintf (plot_stream, "set zrange [%.15e:%.15e] %s;\n", zlim, zdir); |
1106 endif | 992 endif |
1107 | 993 |
1108 if (cautoscale && have_data) | |
1109 set (h, "clim", clim, "climmode", "auto"); | |
1110 endif | |
1111 if (! any (isinf (clim))) | 994 if (! any (isinf (clim))) |
1112 fprintf (plot_stream, "set cbrange [%g:%g];\n", clim); | 995 fprintf (plot_stream, "set cbrange [%g:%g];\n", clim); |
1113 endif | 996 endif |
1114 | 997 |
1115 if (strcmpi (axis_obj.box, "on")) | 998 if (strcmpi (axis_obj.box, "on")) |
1271 fflush (plot_stream); | 1154 fflush (plot_stream); |
1272 | 1155 |
1273 else | 1156 else |
1274 print_usage (); | 1157 print_usage (); |
1275 endif | 1158 endif |
1276 | |
1277 endfunction | |
1278 | |
1279 function [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat) | |
1280 if (! isempty (xdat)) | |
1281 xdat = xdat(! isinf (xdat)); | |
1282 xmin = min (xmin, min (xdat)); | |
1283 xmax = max (xmax, max (xdat)); | |
1284 tmp = min (xdat(xdat > 0)); | |
1285 if (! isempty (tmp)) | |
1286 xminp = min (xminp, tmp); | |
1287 endif | |
1288 endif | |
1289 endfunction | |
1290 | |
1291 ## Attempt to make "nice" limits from the actual max and min of the | |
1292 ## data. For log plots, we will also use the smallest strictly positive | |
1293 ## value. | |
1294 | |
1295 function lim = get_axis_limits (min_val, max_val, min_pos, logscale) | |
1296 | |
1297 if (! (isinf (min_val) || isinf (max_val))) | |
1298 if (logscale) | |
1299 if (isinf (min_pos)) | |
1300 lim = []; | |
1301 warning ("axis: logscale with no positive values to plot"); | |
1302 return; | |
1303 endif | |
1304 if (min_val <= 0) | |
1305 warning ("axis: omitting nonpositive data in log plot"); | |
1306 min_val = min_pos; | |
1307 endif | |
1308 ## FIXME -- maybe this test should also be relative? | |
1309 if (abs (min_val - max_val) < sqrt (eps)) | |
1310 min_val *= 0.9; | |
1311 max_val *= 1.1; | |
1312 endif | |
1313 min_val = 10 ^ floor (log10 (min_val)); | |
1314 max_val = 10 ^ ceil (log10 (max_val)); | |
1315 else | |
1316 if (min_val == 0 && max_val == 0) | |
1317 min_val = -1; | |
1318 max_val = 1; | |
1319 ## FIXME -- maybe this test should also be relative? | |
1320 elseif (abs (min_val - max_val) < sqrt (eps)) | |
1321 min_val -= 0.1 * abs (min_val); | |
1322 max_val += 0.1 * abs (max_val); | |
1323 endif | |
1324 ## FIXME -- to do a better job, we should consider the tic spacing. | |
1325 scale = 10 ^ floor (log10 (max_val - min_val) - 1); | |
1326 min_val = scale * floor (min_val / scale); | |
1327 max_val = scale * ceil (max_val / scale); | |
1328 endif | |
1329 endif | |
1330 | |
1331 lim = [min_val, max_val]; | |
1332 | 1159 |
1333 endfunction | 1160 endfunction |
1334 | 1161 |
1335 function [style, typ, with] = do_linestyle_command (obj, idx, plot_stream) | 1162 function [style, typ, with] = do_linestyle_command (obj, idx, plot_stream) |
1336 | 1163 |