> I would like to be able to do the following.
> Assume that f(x) is defined.
> 1. Generate an empty plot window.
> 2. Pick the points in the window with the mouse and generate a line
> segment on the plot.
> 3. Perhaps with the use of another key pressed, generate the image of
> the line segment and plot it (just as the commands above do).
>
> Thus, I want a graphic interface to the selection of the line segment
> and the plotting of its image.
>
> Any ideas will be appreciated.
>
> -sen
Hello,
I don't know if it is possible to send information generated by Gnuplot
back to Maxima through the pipe. That would be very nice. But it is
possible to write some information into a file from Gnuplot and then let
Maxima read it and make something with it.
The script below is an example. First, you middle clic on the window to
select the points; after every clic, press the 'x' key to save the
coordinates into file 'data_for_maxima'. Once you have finished your
selections, press the 'd' key and the polygonal line should be plotted.
Once you press 'd', Gnuplot writes into file 'message_for_maxima.mac'
the code 'message:1$'. Meanwhile, Maxima is repeating an endless
while-loop; during every iteration, Maxima reads if variable 'message'
has changed from 0 to 1. When it is equal to 1, Maxima reads the
contents of 'data_for_maxima' and plots the segments.
See also embedded comments.
/**************** begin Maxima code *****************/
/*
An example of interacting plot.
The script creates two files:
data_for_maxima, where points are saved after clicking
with middle button and then pressing the
'x' key.
message_for_maxima.mac, where gnuplot saves messages for
Maxima; message:0 means don't plot, and
message:1 means read data from data_for_maxima
and plot the line segments.
When interactive_draw is called, both files are initialized, so that
no interferences occur between two consecutive calls.
Once you have selected the point, press the 'd' key.
Communication channels are:
Maxima --> Gnuplot, via pipes
Gnuplot --> Maxima, via files
*/
load ("draw.lisp") $
/* [x1, x2] and [y1, y2] are the x and y ranges*/
interactive_draw(x1, x2, y1, y2) :=
block([plotted: false, message, data],
/* create file with messages for Maxima */
/* initial message is "no" */
with_stdout (
"message_for_maxima.mac",
print("message:0$")),
/* initial data file is empty */
with_stdout (
"data_for_maxima"),
/* set draw defaults */
set_draw_defaults(
/*terminal = wxt,*/
xrange = [x1, x2],
yrange = [y1, y2],
grid = true),
/* open empty window */
draw2d(
xy_file = "data_for_maxima",
user_preamble =
"bind 'd' 'system \"echo message:1$ > message_for_maxima.mac\" ",
points([[x1,y1]])),
/* while-loop until a '1' messsage is read */
while (not plotted) do (
load("message_for_maxima.mac"),
if message = 1
then (plotted: true,
data: read_matrix("data_for_maxima"),
draw2d(
points_joined = true,
points(data)) )),
'done ) $
interactive_draw(1,10,1,10);
/**************** end Maxima code *****************/
I have tested this in Linux, both with x11 and wxt terminals.
In Windows, the user_preamble option should be changed according to
msdos commands. Since in Windows the pipe concept doesn't exist, the
global behaviour may be different.
--
Mario