[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Getting info back from gnuplot for auto range values
From: |
Daniel J Sebald |
Subject: |
Getting info back from gnuplot for auto range values |
Date: |
Wed, 20 Jun 2007 01:43:38 -0500 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.3) Gecko/20041020 |
John,
Attached is a patch illustrating how to get information back from gnuplot about
auto axis ranging results if you are still interested. Rather than remove what
would be extraneous code, I simply commented out the line of code that would
use the octave computed settings. That way, this patch more clearly shows how
to get the variables of interest.
It would be nice if the communication link could be done through a pipe or stream.
However, I didn't have much luck with the pipe() command. First, it would have to be a
pipe that has a file system name so that gnuplot could use "set print
'|filename'". Second, reading from the pipe created with pipe() seems to get stuck
for me, i.e., put something into the WRITE_FD and try to read from READ_FD just hangs.
Dan
diff -Pur octave-cvs/scripts/plot/__go_draw_axes__.m
octave-mod/scripts/plot/__go_draw_axes__.m
--- octave-cvs/scripts/plot/__go_draw_axes__.m 2007-06-19 01:00:08.000000000
-0500
+++ octave-mod/scripts/plot/__go_draw_axes__.m 2007-06-20 01:32:52.285126823
-0500
@@ -511,7 +511,7 @@
if (xautoscale && have_data)
xlim = get_axis_limits (xmin, xmax, xminp, xlogscale);
- set (h, "xlim", xlim, "xlimmode", "auto");
+% set (h, "xlim", xlim, "xlimmode", "auto");
else
xlim = axis_obj.xlim;
endif
@@ -524,7 +524,7 @@
if (yautoscale && have_data)
ylim = get_axis_limits (ymin, ymax, yminp, ylogscale);
- set (h, "ylim", ylim, "ylimmode", "auto");
+% set (h, "ylim", ylim, "ylimmode", "auto");
else
ylim = axis_obj.ylim;
endif
@@ -538,7 +538,7 @@
if (nd == 3)
if (zautoscale && have_data)
zlim = get_axis_limits (zmin, zmax, zminp, zlogscale);
- set (h, "zlim", zlim, "zlimmode", "auto");
+% set (h, "zlim", zlim, "zlimmode", "auto");
else
zlim = axis_obj.zlim;
endif
@@ -637,6 +637,20 @@
fflush (plot_stream);
+ % Get information back from gnuplot about axis limits
+ if (xautoscale)
+ xlim = __gnuplot_read_limits__ (plot_stream, "X");
+ set (h, "xlim", xlim, "xlimmode", "auto");
+ endif
+ if (yautoscale)
+ ylim = __gnuplot_read_limits__ (plot_stream, "Y");
+ set (h, "ylim", ylim, "ylimmode", "auto");
+ endif
+ if (nd == 3 && zautoscale)
+ zlim = __gnuplot_read_limits__ (plot_stream, "Z");
+ set (h, "zlim", zlim, "zlimmode", "auto");
+ endif
+
else
print_usage ();
endif
@@ -896,6 +910,27 @@
endfunction
+function lim = __gnuplot_read_limits__ (plot_stream, dim)
+
+ ## Set gnuplot's print command to a file, print the values of
+ ## interest and then read them. It would be nice if this
+ ## were a pipe so that continually opening and closing files
+ ## wasn't necessary.
+
+ persistent __gpprintfile__ = "";
+
+ if (isempty (__gpprintfile__))
+ __gpprintfile__ = tmpnam ();
+ endif
+ fprintf (plot_stream, "set print \"-\";\nset print \"%s\";\n",
__gpprintfile__);
+ fprintf (plot_stream, "print GPVAL_%s_MIN;\nprint GPVAL_%s_MAX;\n", dim,
dim);
+ fputs (plot_stream, "set print \"-\";\n");
+ gpfid = fopen (__gpprintfile__);
+ lim = fscanf (gpfid, "%g", 2)(:)';
+ fclose (gpfid);
+
+endfunction
+
function do_tics (obj, plot_stream)
do_tics_1 (obj.xtickmode, obj.xtick, obj.xticklabelmode, obj.xticklabel,
"x", plot_stream);
- Getting info back from gnuplot for auto range values,
Daniel J Sebald <=