Absolute positions in mpld3 graphs

137 views Asked by At

I'm trying to define a custom plugin for mpld3, and I'm struggling with positions. More particularly, by default, SVG generated by mpld3 come with Move and Zoom buttons, which change the view of the graph. When I was trying to display things (like text), I stumbled upon a strange behavior where positions are set relatively to the current view. It means that if I display a text next to a point A(10,10) and then move the view, the point will still be at (10,10) but the text will move because its position is relative to the current view.

So I wanted to think again and start with a minimal example which should work : this example from the mpld3 documentation. In the demo, you can see the behavior I want : positions are absolute (when you move the view, cursor position is set according to the grid).enter image description here.

But if I copy-paste the exact same code in Pycharm and execute it, positions are relative to the view which is even more strange : enter image description here

My guess is it's a version problem. I don't know which versions are used in the hosted demo example. I use mpld3==0.5.1, matplotlib==3.2.1 and numpy==1.19.2.

Do you have an idea so I can manage to deal with absolute positions like in the example ?

1

There are 1 answers

0
Bastien Broussard On

I've managed to make it work. It turns out that downgrading mpld3 to version 0.3 does what I want. I'm sure there is a better solution (because I can't take advantage of the latest version) but it gets the job done.