0

I am trying to learn Python in several environments. I can't figure out why this script, provided by armatita works perfectly in CodeRunner for Mac, but does not provide touch functions in Anaconda/Spyder or Pythonista for iOS. Is there something I can do to make in work for all three?

import matplotlib.pyplot as plt

def onclick(event):
    print(event.xdata, event.ydata)

fig,ax = plt.subplots()
ax.plot(range(10))
fig.canvas.mpl_connect('button_press_event', onclick)
plt.show()
djl
  • 15
  • 4
  • create a virtualenv to be sure that you can't be confused about the environment that your code running into or create a docker image then run it using a container – Ghassen Jun 23 '19 at 22:00
  • 1
    You need an interactive backend for events to be processed. Spyder provides options to change the matplotlib backend in the preferences. Not sure about Pythonista. – ImportanceOfBeingErnest Jun 23 '19 at 22:01
  • Selecting the backend solved the problem in Spyder. I still wonder about Pythonista. – djl Jun 24 '19 at 02:06
  • Probably Pythonista doesn't have an option to select an interactive backend, so you need to do that by hand. Matplotlib has a function to do that. – Carlos Cordoba Jun 24 '19 at 13:54

0 Answers0