texmacs / octave

Octave plugin for GNU TeXmacs
6 stars 2 forks source link

change plotting #7

Closed woutersj closed 3 years ago

woutersj commented 3 years ago

An attempt to resolve issue #6. tmplot already checks for an empty plot, so do we need TM_OCTAVE_PLOT_DIGEST?

Note that gcf() has the side effect of creating an empty plot if none is open, get (groot, "currentfigure"); doesn't do this Found this in the Octave docs.

da-liii commented 3 years ago

TM_OCTAVE_PLOT_DIGEST is introduced by me. I didn't write a test case for this case. Let me add some test cases for the octave plugin to clarify the functionality.

da-liii commented 3 years ago

I tried to figure out why I introduced the global digest in octave. But found that it does not work correctly. This PR looks good. And let us add some test cases for it in test/plots.tm.

woutersj commented 3 years ago

It seems that the global digest does not work well because it is hashing the current figure, which is not necessarily altered by plotting. A figure has an axis child, which in turn has objects as its children. The serialization of figure object is therefore not a one-to-one mapping with what is shown on screen.

I have done some more experiments to see how the Octave REPL handles figures. Octave handles graphics and the ans returned by the command as separate things. For example

clf;
A = rand (100);
[X, Y] = find (A > 0.95);
imshow (A);

pops up a plot window, even though there is no output on the console, because of the semicolons. In TeXmacs this code would not result in a plot.

To complicate matters a user can also open several figure in one cell:

figure(1)
fplot (@sin, [-10, 10])
figure(2)
fplot (@cos, [-10, 10])

If we plot when output is requested (no ; at the end) and clear the plot (as in this PR), then this would not behave naturally if someone enters non-plotting commands after the plotting commands, e.g.

clf;
A = rand (100);
[X, Y] = find (A > 0.95);
imshow (A);
det(A)

If on the other hand we use an improved hashing function to detect changes and only plot when a figure has been altered, this may be inconvenient if a user wants to build up a complex plot in several separate cells (layering multiple graphs, adding a legend, manipulating axes/titles etc.). The plot would show up many times, after every evaluated line. This could of course be circumvented with multiline input.

It seems to me that showing the plot in every cell that has altered a figure, independent of the presence of a semicolon, would be the closest to the Octave REPL behaviour. This would require an improvement of the figure hashing first, though.

da-liii commented 3 years ago

Thanks for your detailed explanation. All of these explanation can be kept in test/plots.tm. test/plots.tm is blank now. I wonder if I forgot to upload the test cases.

Looking into the corresponding issue of this PR, we'd better to fix it rather than to skip it by introducing other flaws.