Plot rescales the first few clicks - how to disallow overlapping ?

Hello everyone,

I was playing around with matplotlib, created a plot that allows users to add nodes (axis is set off as it’s going to be used for graph data structuer purposes, hence don’t want the y-x axis, is there another way to hide them as well?).

Basically the program below allows person press the ‘n’ button, and then can click on any point on the plot and a small circular marker will appear.

I have two questions:

  1. You will notice that during the first 2 marker inputs, the plot rescales it self. I don’t really know why that’s happening, any idea?

  2. Is it possible to disallow users of creating to marker points ontop of each other, so that no markers will overlap
    (even if the edges)?

Thank you.

Code

from pylab import *

from matplotlib.widgets import *

fig = plt.figure()

ax = fig.add_subplot(111)

fig.set_facecolor(‘w’)

ax.set_axis_off()

ax.set_title(‘Test 1’)

cid = None

def onClick(event):

"""docstring for onClick"""

ax.plot([event.xdata], [event.ydata], 'bo', picker=5, markersize=15)

draw()

fig.canvas.mpl_disconnect(cid)

def
onPick(event):

"""docstring for onPick"""

artist = event.artist

artist.set_color('r')

draw()

def add_node(event):

"""docstring for press"""

if event.key=="n":

	global cid

	fig.canvas.mpl_disconnect(cid)

	 cid =

fig.canvas.mpl_connect(‘button_press_event’,onClick)

fig.canvas.mpl_connect(‘key_press_event’, add_node)

fig.canvas.mpl_connect(‘pick_event’,onPick)

plt.show()