[Matplotlib-users] mouse cursor coordinates

grivet grivet at cnrs-orleans.fr
Fri Jun 3 09:58:13 EDT 2016


I know the examples in
        http://matplotlib.org/users/event_handling.html
but they don't do what I want.
The next example is quite complex, and I don't understand much of it.
> https://gist.github.com/tacaswell/d1afcf015fc202c311bdcc477e1ca3bd and 
> http://matplotlib.org/users/event_handling.html
>
I am used to programming in Scilab (or Matlab) and I wish to emulate the 
following piece of code, in which I place 4
electric charges (of both signs) inside a rectangle in order to compute 
later the resulting electric field.

//define plot window
a = gca(); a.tight_limits = "on";
xsetech(wrect=[0,0,1,1],frect=[-5,-5,5,5],arect = 0.99*[1,1,1,1]);

np = 4; i = 1;
xinfo(""left click in window to place a charge (4 in all)");
while i <= np
     [ib,xx,yy] = xclick();                              //retrieve 
button number and pointer coordinates
     if abs(xx) < 5 & abs(yy) < 5 & ib==3  //inside plot and left button
           xs(i) = xx; ys(i)=yy;
         charge(i) = evstr(x_dialog("charge value: ","1"));
         if charge(i) >0 then
             plot2d(xs(i),ys(i),style = -4,strf="002")  //blue dot
         else
             plot2d(xs(i),ys(i),style = -5,strf="002")  //red dot
         end
         i = i+1;
     end
     xinfo("left click in window to place a charge (" + string(5-i) + " 
charge(s) remaining)");
end
.......

Is it possible to write an analogous Python code ?



More information about the Matplotlib-users mailing list