Discussion:
Data cursor in Octave
roland65
2017-02-08 14:56:40 UTC
Permalink
Hi there,

is there a way in Octave to get a data cursor like the datatip in Matlab ?

I know I can use the ginput() function but I'd like to get the coordinates
of a point of the data series and not of any point in the figure...



--
View this message in context: http://octave.1599824.n4.nabble.com/Data-cursor-in-Octave-tp4681800.html
Sent from the Octave - General mailing list archive at Nabble.com.
roland65
2017-02-08 14:57:08 UTC
Permalink
Hi there,

is there a way in Octave to get a data cursor like the datatip in Matlab ?

I know I can use the ginput() function but I'd like to get the coordinates
of a point of the data series and not of any point in the figure...

Thanks,
RB



--
View this message in context: http://octave.1599824.n4.nabble.com/Data-cursor-in-Octave-tp4681801.html
Sent from the Octave - General mailing list archive at Nabble.com.
Pantxo Diribarne
2017-02-09 12:16:58 UTC
Permalink
There is nothing like this currently in Octave but it had been a while
since I wanted to give it a try.
I attached a draft function that should do what you want. It only works
when there is a single axes in the figure and only points to line objects:

plot (rand (20, 4)
h = datacursor ();

%% get the coordinates of the data cursor
x = get (h, "x")(2);
y = get (h, "y")(2);


Pantxo
Pantxo Diribarne
2017-02-09 13:04:27 UTC
Permalink
Post by Pantxo Diribarne
There is nothing like this currently in Octave but it had been a while
since I wanted to give it a try.
I attached a draft function that should do what you want. It only works
plot (rand (20, 4)
h = datacursor ();
%% get the coordinates of the data cursor
x = get (h, "x")(2);
y = get (h, "y")(2);
Pantxo
I attached an updated version, the previous one had problems in the
displayed coordinates and didn't handle log coordinates.
roland65
2017-02-09 17:26:14 UTC
Permalink
Thanks a lot ! This exactly what I was looking for...

It works well with the fltk and qt graphics toolkits.

However, there is a minor issue with the qt toolkit: when using the
datacursor() function, the coordinates that are displayed at the bottom of
the plot become normalized between 0 and 1, and thus are wrong.

I found that this issue is related to the annotation() function you use. So
it is easly to reproduce the issue like this (with the qt toolkit) :

% Plot a sinus ; the display coordinates are OK
close all; clear all; x=[0:0.01:2*pi]; y=sin(x);plot(x,y);

% Annotate the figure ; the display coordinates are between 0 and 1
annotation("textbox",[0.5 0.5 0 0],"string","TEXT")

Note the issue is also present when using the "Insert text" menu.

Perhaps I shall fill a bug report, or is it a known issue ?

Anyway, many thanks for your very useful function.
RB



--
View this message in context: http://octave.1599824.n4.nabble.com/Data-cursor-in-Octave-tp4681801p4681836.html
Sent from the Octave - General mailing list archive at Nabble.com.
Pantxo
2017-02-10 07:39:54 UTC
Permalink
Post by roland65
However, there is a minor issue with the qt toolkit: when using the
datacursor() function, the coordinates that are displayed at the bottom of
the plot become normalized between 0 and 1, and thus are wrong
....
Perhaps I shall fill a bug report, or is it a known issue ?
RB
Yes please do so. The coordinates you see are those of the annotation
transparent axes, which is above any other axes but should not be taken into
account when displaying the coordinates of the mouse cursor in the status
bar.



Pantxo



--
View this message in context: http://octave.1599824.n4.nabble.com/Data-cursor-in-Octave-tp4681801p4681839.html
Sent from the Octave - General mailing list archive at Nabble.com.
roland65
2017-02-10 08:31:25 UTC
Permalink
Post by Pantxo
Yes please do so.
OK, I filled a bug report (https://savannah.gnu.org/bugs/index.php?50272).

Another question: would it be difficult to add a menu that calls the
datacursor() function to the figure window? I looked at the source code, but
I couldn't understand how to call an Octave function from within the C++.




--
View this message in context: http://octave.1599824.n4.nabble.com/Data-cursor-in-Octave-tp4681801p4681840.html
Sent from the Octave - General mailing list archive at Nabble.com.
Pantxo
2017-02-10 09:59:21 UTC
Permalink
Post by roland65
Post by Pantxo
Yes please do so.
OK, I filled a bug report (https://savannah.gnu.org/bugs/index.php?50272).
Another question: would it be difficult to add a menu that calls the
datacursor() function to the figure window? I looked at the source code,
but I couldn't understand how to call an Octave function from within the
C++.
See [1] for how to call m code from c++, basically with feval function.
It is thus not very difficult, but it has to be implemented for both fltk
and Qt.

As a temporary workaround you can add the menu yourself. See uimenu.



[1]
https://www.gnu.org/software/octave/doc/interpreter/Calling-Octave-Functions-from-Oct_002dFiles.html#Calling-Octave-Functions-from-Oct_002dFiles



--
View this message in context: http://octave.1599824.n4.nabble.com/Data-cursor-in-Octave-tp4681801p4681841.html
Sent from the Octave - General mailing list archive at Nabble.com.
roland65
2017-02-10 13:50:42 UTC
Permalink
Post by Pantxo
It is thus not very difficult, but it has to be implemented for both fltk
and Qt.
OK, thanks for the tips, it helped me a lot.

I tried to add a menu to the qt figure. It almost works. Indeed, when I
click on my custom "Data cursor" menu item, the datacursor() function is
executed (I see the coordinates that changes at the bottom) but the
annotation is not shown. For the whole thing to work, I have to go to the
Octave terminal and press the enter key once. Then, the datacursor works as
expected.

Do you have any idea about this strange behaviour?

Here is my code (in libgui/graphics/Figure.cc):


void
Figure::createFigureToolBarAndMenuBar (void)
{

<...>

editMenu->addSeparator ();
editMenu->addActions (m_mouseModeGroup->actions ());
editMenu->addAction (tr ("&Data cursor"), this, SLOT (dataCursor (void)));

< ... >
}

void
Figure::dataCursor (void)
{
octave_link::post_event (this, &Figure::datacursor_callback);
}

void
Figure::datacursor_callback (void)
{
figure::properties& fp = properties<figure> ();
octave_value fnum = fp.get___myhandle__ ().as_octave_value ();

Ffeval (ovl ("datacursor", fnum));

//redraw (); // Needed ?
}






--
View this message in context: http://octave.1599824.n4.nabble.com/Data-cursor-in-Octave-tp4681801p4681842.html
Sent from the Octave - General mailing list archive at Nabble.com.
Pantxo Diribarne
2017-02-10 19:01:55 UTC
Permalink
I went the .m file/uimenu route and it seems to works correctly. I attched
the preliminary files. Usage:

plot (rand (20, 4))
datacursor_menu

Pantxo
roland65
2017-02-11 08:46:29 UTC
Permalink
Post by Pantxo Diribarne
I went the .m file/uimenu route and it seems to works correctly. I attched
the preliminary files.
Nice! It works as expected, thanks a lot!

Anyway, I'd like to understand what goes wrong in my code. I tried to
replace the feval(ovl(datacursor...) code with a call to the disp() function
and the behaviour is the same. I have to press the return key, otherwise the
disp() function gets stuck.

Do you think I'll have to fill a bug report again, or did I miss something ?




--
View this message in context: http://octave.1599824.n4.nabble.com/Data-cursor-in-Octave-tp4681801p4681845.html
Sent from the Octave - General mailing list archive at Nabble.com.
Pantxo
2017-02-13 10:09:15 UTC
Permalink
Post by roland65
Post by Pantxo Diribarne
I went the .m file/uimenu route and it seems to works correctly. I attched
the preliminary files.
Nice! It works as expected, thanks a lot!
Anyway, I'd like to understand what goes wrong in my code. I tried to
replace the feval(ovl(datacursor...) code with a call to the disp()
function and the behaviour is the same. I have to press the return key,
otherwise the disp() function gets stuck.
Do you think I'll have to fill a bug report again, or did I miss something ?
I remember having seen such behavior reported (need pressing <enter> in the
command window for plotting to proceed) but I fail to find the original
report. Can you file a bug report.

Pantxo



--
View this message in context: http://octave.1599824.n4.nabble.com/Data-cursor-in-Octave-tp4681801p4681852.html
Sent from the Octave - General mailing list archive at Nabble.com.
roland65
2017-02-14 15:01:59 UTC
Permalink
Post by Pantxo
Can you file a bug report
Done! It's here: http://savannah.gnu.org/bugs/?50295





--
View this message in context: http://octave.1599824.n4.nabble.com/Data-cursor-in-Octave-tp4681801p4681867.html
Sent from the Octave - General mailing list archive at Nabble.com.
roland65
2017-02-21 13:05:39 UTC
Permalink
Post by Pantxo Diribarne
I went the .m file/uimenu route and it seems to works correctly. I attched
the preliminary files.
I found an issue in the datacursor.m function. Indeed, if you have two
figures (1 and 2) and figure 2 is the current figure, then datacursor(1)
displays the cursor on the current figure (figure 2), not on figure 1.

I guess you simply forgot to add the figure handle to the annotation()
function call. So I attach the fixed datacursor.m function.

datacursor.m
<http://octave.1599824.n4.nabble.com/file/n4681956/datacursor.m>



--
View this message in context: http://octave.1599824.n4.nabble.com/Data-cursor-in-Octave-tp4681801p4681956.html
Sent from the Octave - General mailing list archive at Nabble.com.
Continue reading on narkive:
Loading...