1

I am trying to make an interactive plot a bit more useful. I started by adding my own format_coords function to show me the data in the plot rather than the mouse position.

The plots grew in complexity, and now there are numerous series in the plot. The formatted coordinates (one value for each series) no longer fits in the tool bar any longer. I did some things to work around this problem( adding spaces and newlines), but it's just ugly and difficult to read.

Is there a way to create an external window that isn't in the matplotlib figure in which I could use to display the current data where the mouse pointer is?

I've seen a number of things about using matplotlib within another application (e.g. How can I create a frontend for matplotlib?), but I want to go the other direction, if possible.

I don't want to create a whole new application, but I do want to create a frame with a column/grid of name: value pairs that get updated any time format_coord gets called.

Is such a thing possible (and feasible)?

ADDENDUM

I'm primarily plotting ordinary numerical data as lines ('.-'). In order to get to the correct data inside format_coord, I set some (custom) attributes of the axes object, though for a simple example, this would not be necessary. The data could look like this:

      Timestamp  Axis0.ActualPosition  Axis0.ActualVelocity
1000  639699159             -146323.0                  -323
1001  639699160             -146646.0                  -323
1002  639699161             -146969.0                  -323
1003  639699162             -147295.0                  -326
1004  639699163             -147624.0                  -329
        ...                   ...                   ...
1095  639699254             -177474.0                  -328
1096  639699255             -177803.0                  -329
1097  639699256             -178132.0                  -329
1098  639699257             -178460.0                  -328
1099  639699258             -178787.0                  -327

I imagine the "reporting" window to look something like this:

example dialog

I'd prefer to be able to apply some formatter function to the values, which is what I'm currently doing inside my format_coord function. My current code has all that, it's just creating and handling the other window that I don't know how to do.

The button(s) at the bottom of the window would be extra cool, because they'd allow me to do some useful stuff, but they're not essential to the problem that having this external window would solve.

I expect that the data in the extra dialog/frame would get updated every time format_coord is invoked.

mojo
  • 4,050
  • 17
  • 24
  • 1
    Maybe [mplcursors](https://mplcursors.readthedocs.io/) is an alternative? It shows a customizable annotation upon hovering. – JohanC Jan 21 '22 at 19:25
  • It can be done, but it will grow in complexity... a lot. Let me find some time to code it. Can you share some code to see what information you want to show? – azelcer Jan 22 '22 at 15:37
  • @azelcer, My current script is 1300 lines long, but most of it is details that aren't particularly pertinent to the question. What kind of code would be helpful to see? – mojo Jan 24 '22 at 13:40
  • @JohanC mplcursors sounds interesting. The thing that it doesn't (seem to) do is show all the different series values at once. One of the things I'm trying to do is align all these series by time (independent axis) so that I can see _when_ things are happening and which things come first. It would be much better for me to be able to see all the data for a given timestamp at once. – mojo Jan 24 '22 at 13:43
  • Well, mplcursors is fully customizable, you can add whatever information you like. Without code and without reproducible test data it is hard to tell the details about how it would fit into your code. You can have a look at the [online examples](https://mplcursors.readthedocs.io/en/stable/examples/index.html) and at related [StackOverflow posts](https://stackoverflow.com/questions/tagged/mplcursors). – JohanC Jan 24 '22 at 13:51
  • @JohanC Curiously, mplcursors uses the results of `format_coord`, which is quite useful in my case (I had to change to using non-breaking spaces for the formatting I was employing). It does a very good job of showing me the data at a single point. What I want more is something like the default behavior of matplotlib where it shows you the current "data" whenever you move the cursor. I'm looking at something like a timing diagram, and I want to be able to see _when_ things change. – mojo Jan 24 '22 at 15:12
  • `format_coord` just serves as the default annotation. Much more is possible. Did you check the [dataframe example](https://mplcursors.readthedocs.io/en/stable/examples/dataframe.html#sphx-glr-examples-dataframe-py)? – JohanC Jan 24 '22 at 19:24

0 Answers0