Mercurial > octave-nkf
comparison scripts/plot/__go_draw_axes__.m @ 7115:926fc75fb02e
[project @ 2007-11-07 15:42:46 by jwe]
author | jwe |
---|---|
date | Wed, 07 Nov 2007 15:42:46 +0000 |
parents | 0e63f1126f01 |
children | d22ad51b9cf8 |
comparison
equal
deleted
inserted
replaced
7114:a67d30883ee0 | 7115:926fc75fb02e |
---|---|
780 obj.type); | 780 obj.type); |
781 endswitch | 781 endswitch |
782 | 782 |
783 endfor | 783 endfor |
784 | 784 |
785 have_data = ! isempty (data); | 785 have_data = (! (isempty (data) |
786 || isinf (xmin) || isinf (xmax) | |
787 || isinf (ymin) || isinf (ymax) | |
788 || isinf (zmin) || isinf (zmax))); | |
786 | 789 |
787 if (xautoscale && have_data) | 790 if (xautoscale && have_data) |
788 xlim = get_axis_limits (xmin, xmax, xminp, xlogscale); | 791 xlim = get_axis_limits (xmin, xmax, xminp, xlogscale); |
789 if (isempty (xlim)) | 792 if (isempty (xlim)) |
790 return; | 793 return; |
796 if (strcmpi (axis_obj.xdir, "reverse")) | 799 if (strcmpi (axis_obj.xdir, "reverse")) |
797 xdir = "reverse"; | 800 xdir = "reverse"; |
798 else | 801 else |
799 xdir = "noreverse"; | 802 xdir = "noreverse"; |
800 endif | 803 endif |
801 fprintf (plot_stream, "set %srange [%.15e:%.15e] %s;\n", xaxisloc, xlim, xdir); | 804 fprintf (plot_stream, "set %srange [%.15e:%.15e] %s;\n", |
805 xaxisloc, xlim, xdir); | |
802 | 806 |
803 if (yautoscale && have_data) | 807 if (yautoscale && have_data) |
804 ylim = get_axis_limits (ymin, ymax, yminp, ylogscale); | 808 ylim = get_axis_limits (ymin, ymax, yminp, ylogscale); |
805 if (isempty (ylim)) | 809 if (isempty (ylim)) |
806 return; | 810 return; |
961 endif | 965 endif |
962 | 966 |
963 endfunction | 967 endfunction |
964 | 968 |
965 function [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat, tx) | 969 function [xmin, xmax, xminp] = get_data_limits (xmin, xmax, xminp, xdat, tx) |
966 xdat = xdat(! isinf (xdat)); | 970 if (! (isempty (xdat) || isempty (tx))) |
967 xmin = min (xmin, min (xdat)); | 971 xdat = xdat(! isinf (xdat)); |
968 xmax = max (xmax, max (xdat)); | 972 xmin = min (xmin, min (xdat)); |
969 if (nargin == 5) | 973 xmax = max (xmax, max (xdat)); |
970 tx = tx(! isinf (xdat) & tx > 0); | 974 if (nargin == 5) |
971 if (! isempty (tx)) | 975 tx = tx(! isinf (xdat) & tx > 0); |
972 xminp = min (xminp, min (tx)); | 976 if (! isempty (tx)) |
973 endif | 977 xminp = min (xminp, min (tx)); |
974 else | 978 endif |
975 tmp = min (xdat(xdat > 0)); | 979 else |
976 if (! isempty (tmp)) | 980 tmp = min (xdat(xdat > 0)); |
977 xminp = min (xminp, tmp); | 981 if (! isempty (tmp)) |
982 xminp = min (xminp, tmp); | |
983 endif | |
978 endif | 984 endif |
979 endif | 985 endif |
980 endfunction | 986 endfunction |
981 | 987 |
982 ## Attempt to make "nice" limits from the actual max and min of the | 988 ## Attempt to make "nice" limits from the actual max and min of the |
983 ## data. For log plots, we will also use the smallest strictly positive | 989 ## data. For log plots, we will also use the smallest strictly positive |
984 ## value. | 990 ## value. |
985 | 991 |
986 function lim = get_axis_limits (min_val, max_val, min_pos, logscale) | 992 function lim = get_axis_limits (min_val, max_val, min_pos, logscale) |
987 | 993 |
988 if (logscale) | 994 if (! (isinf (min_val) || isinf (max_val))) |
989 if (isinf (min_pos)) | 995 if (logscale) |
990 lim = []; | 996 if (isinf (min_pos)) |
991 warning ("axis: logscale with no positive values to plot"); | 997 lim = []; |
992 return; | 998 warning ("axis: logscale with no positive values to plot"); |
993 endif | 999 return; |
994 if (min_val <= 0) | 1000 endif |
995 warning ("axis: omitting nonpositive data in log plot"); | 1001 if (min_val <= 0) |
996 min_val = min_pos; | 1002 warning ("axis: omitting nonpositive data in log plot"); |
997 endif | 1003 min_val = min_pos; |
998 ## FIXME -- maybe this test should also be relative? | 1004 endif |
999 if (abs (min_val - max_val) < sqrt (eps)) | 1005 ## FIXME -- maybe this test should also be relative? |
1000 min_val *= 0.9; | 1006 if (abs (min_val - max_val) < sqrt (eps)) |
1001 max_val *= 1.1; | 1007 min_val *= 0.9; |
1002 endif | 1008 max_val *= 1.1; |
1003 min_val = 10 ^ floor (log10 (min_val)); | 1009 endif |
1004 max_val = 10 ^ ceil (log10 (max_val)); | 1010 min_val = 10 ^ floor (log10 (min_val)); |
1005 else | 1011 max_val = 10 ^ ceil (log10 (max_val)); |
1006 if (min_val == 0 && max_val == 0) | 1012 else |
1007 min_val = -1; | 1013 if (min_val == 0 && max_val == 0) |
1008 max_val = 1; | 1014 min_val = -1; |
1009 ## FIXME -- maybe this test should also be relative? | 1015 max_val = 1; |
1010 elseif (abs (min_val - max_val) < sqrt (eps)) | 1016 ## FIXME -- maybe this test should also be relative? |
1011 min_val -= 0.1 * abs (min_val); | 1017 elseif (abs (min_val - max_val) < sqrt (eps)) |
1012 max_val += 0.1 * abs (max_val); | 1018 min_val -= 0.1 * abs (min_val); |
1013 endif | 1019 max_val += 0.1 * abs (max_val); |
1014 ## FIXME -- to do a better job, we should consider the tic spacing. | 1020 endif |
1015 scale = 10 ^ floor (log10 (max_val - min_val) - 1); | 1021 ## FIXME -- to do a better job, we should consider the tic spacing. |
1016 min_val = scale * floor (min_val / scale); | 1022 scale = 10 ^ floor (log10 (max_val - min_val) - 1); |
1017 max_val = scale * ceil (max_val / scale); | 1023 min_val = scale * floor (min_val / scale); |
1024 max_val = scale * ceil (max_val / scale); | |
1025 endif | |
1018 endif | 1026 endif |
1019 | 1027 |
1020 lim = [min_val, max_val]; | 1028 lim = [min_val, max_val]; |
1021 | 1029 |
1022 endfunction | 1030 endfunction |