octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: graphics crossroads


From: John W. Eaton
Subject: Re: graphics crossroads
Date: Fri, 17 Nov 2006 14:42:34 -0500

On 17-Nov-2006, Søren Hauberg wrote:

| To me it makes perfect sense to save *everything* -- I'm actually 
| surprised that it's not the case in the current implementation.

Originally, nothing about the plot was saved.  I assumed that it was
OK to just send commands to gnuplot as soon as possible, and not
remember them.  That was a bad assumption, but since I thought it was
OK at the time, I didn't see any need for saving the plot data and
settings if they were just going to be sent to gnuplot immediately.

This approach actually works OK most of the time, but fails for a few
things.  For example, the legend keys and line styles cause trouble
because they are embedded in the plot command itself rather than being
managed by separate "set" commands.  So there is no way to do

  plot <something>
  set legend for line 1 to "foobar"
  replot

and the whole "set" system for setting properties breaks down with
gnuplot's multiplot mode (it seems that the multiplot mode doesn't
really know about multiple plots and instead just sets plot areas, and
set/show certainly doesn't).

| One possibility would be to remove plotting support from octave. Then 
| have a package containing the current plotting functions, and another 
| package containing the development graphics object based system. That 
| way it would be easier to release 3.0 if the objects based system takes 
| time to develop.
| (I'm not sure if this is a good idea, but I thought I'd mention it...)

For minimum surprise, I think we would have to go back a few weeks on
the plotting functions.  But then we would not have a reliable legend
command or plotting on top of images in 3.0.

| It's fine with me if the __gnuplot_raw__ calls fails. But if we really 
| want people to stop using these commands it might be helpful to provide 
| some functions to write your data to a file that gnuplot can read.

In the current CVS, I have

  FILE = __gnuplot_save_data__ (VAL, NDIM, PARAMETRIC)

to save VAL to a file that gnuplot can read.  NDIM should be either 2
or 3 (default is 2), and parametric should be true or false (used only
for 3-d data).  For example, with this function you can write

  x = (-10:0.1:10)';
  data = [x, sin(x)];
  file = __gnuplot_save_data__ (data);
  __gnuplot_raw__ (sprintf ("plot '%s' with lines;\n", file));

VAL may have more than two columns for 2-d data so you can write

  x = (-10:0.1:10)';
  data = [x, sin(x), cos(x)];
  file = __gnuplot_save_data__ (data);
  fmt = "plot '%s' u 1:2 w l t 'sin', '%s' u 1:3 w l t 'cos' ;\n";
  __gnuplot_raw__ (sprintf (fmt, file, file));

The temporary file that is created by __gnuplot_save_data__ is cleaned
up when Octave exits, or by the purge_tmp_files command (as before).

In the current CVS, I also have

  __gnuplot_send_inline_data__ (VAL, NDIM, PARAMETRIC)

which works much like __gnuplot_save_file__, but sends the data down
the pipe that is connected to the gnuplot process that is drawing the
current figure.  The data are sent in text form, followed by a single
line with "e" to mark the end.  With this function, you can write
something like

  x = (-10:0.1:10)';
  data = [x, sin(x)];
  __gnuplot_raw__ ("plot '-' with lines;\n");
  __gnuplot_send_inline_data__ (data);

This method avoids the temporary file.  For multiple lines, you can
write

  x = (-10:0.1:10)';
  data_sin = [x, sin(x)];
  data_cos = [x, cos(x)];
  __gnuplot_raw__ ("plot '-' w l t 'sin', '-' w l t 'cos';\n");
  __gnuplot_send_inline_data__ (data_sin);
  __gnuplot_send_inline_data__ (data_cos);

jwe



reply via email to

[Prev in Thread] Current Thread [Next in Thread]