Drawing on top of an existing graph Python Matplotlib -
Then I am writing a program that is using matplotlib to plot the initial original graph and then Puts points on it What I was aiming to do was to place the mouse on a certain point in the graph and click to add points I can not find any such form that clearly tells how the input point is actually as the plot of the initial graph After the mouse is clicked on. Even what I have so far
Import matplotlib.pyplot as plt import nmpy as npy x, y, vx, vy = npy.loadtxt ('issmplotdat.txt', delimiter = ',' Unpack = true ) Element = npy.loadtxt ('issmplotdatelements.txt', delimiter = ',') vel = npy.sqrt (vx ** 2 + vy ** 2) fig = plt.figure () plt.tricontourf (X, y, Element, or) plt.hold (True) plt.plot (3,9, 'ro') def on_keyboard (Event): print "You pressed", event.key, "\ nat:", event.xdata, event. Print 'plot' def on_click (event): print ('ehllo') print 'you pressed:', event.button, '\ nat:', Event.xdata, Event.ydata plt.plot (event.xdata, event.ydata, 'ro') zing = fig.canvas.mpl_connect ('button_press_event', on_click) ding = fig.canvas.mpl_connect ('key_press_event', a lot in advance Thanks!
After placing the plot you will see the You must update the plot by calling figure.canvas.draw ()
.function.
[Note that you must use the global encoder variable to do this]
Then in your case, the on_click
callback function will be:
def on_click (event): plt.plot (event.xdata, event.ydata, 'ro ') Global fig fig.canvas.draw ()
Comments
Post a Comment