Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8440217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:13:46+00:00 2026-06-10T08:13:46+00:00

I’m trying to build an interactive plot. This one is supposed to clear the

  • 0

I’m trying to build an interactive plot. This one is supposed to clear the figure if clicked within axes and draw a circle at a random place. The code is as follows:

import matplotlib.pyplot as plt
import random


def draw_circle(event):
    if event.inaxes:
        print(event.xdata, event.ydata)
        plt.cla()
        a = random.randint(0,100)
        b = random.randint(0,100)
        s, = plt.plot(a,b,'o', ms=100, color="blue",visible=True )
        plt.show()


fig = plt.figure()
ax = plt.subplot(111)
s, = plt.plot(1,2,'o', ms=100, color="blue",visible=True )
plt.connect("button_press_event", draw_circle)
plt.show() 

After clicking for 42 times, the program breaks and I get the following traceback:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1413, in __call__
    return self.func(*args)
  File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py", line 286, in button_press_event
    FigureCanvasBase.button_press_event(self, x, y, num, guiEvent=event)
  File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 1632, in button_press_event
    self.callbacks.process(s, mouseevent)
  File "/usr/lib/pymodules/python2.7/matplotlib/cbook.py", line 262, in process
    proxy(*args, **kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/cbook.py", line 192, in __call__
    return mtd(*args, **kwargs)
  File "/home/almarahat/Dropbox/python/GUI/Testing site/test_rt/baud_test.py", line 8, in draw_circle
    plt.cla()
  File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2784, in cla
    ret =  gca().cla()
  File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 842, in cla
    spine.cla()
  File "/usr/lib/pymodules/python2.7/matplotlib/spines.py", line 157, in cla
    self.axis.cla()
  File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 731, in cla
    self.reset_ticks()
  File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 744, in reset_ticks
    self.majorTicks.extend([self._get_tick(major=True)])
  File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 1553, in _get_tick
    return XTick(self.axes, 0, '', major=major, **tick_kw)
  File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 141, in __init__
    self.tick2line = self._get_tick2line()
  File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 401, in _get_tick2line
    l.set_transform(self.axes.get_xaxis_transform(which='tick2'))
  File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 586, in get_xaxis_transform
    return self.spines['top'].get_spine_transform()
  File "/usr/lib/pymodules/python2.7/matplotlib/spines.py", line 374, in get_spine_transform
    self._ensure_position_is_set()
  File "/usr/lib/pymodules/python2.7/matplotlib/spines.py", line 140, in _ensure_position_is_set
    self.set_position(self._position)
  File "/usr/lib/pymodules/python2.7/matplotlib/spines.py", line 365, in set_position
    self.axis.cla()
  File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 731, in cla
    self.reset_ticks()
  File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 744, in reset_ticks
    self.majorTicks.extend([self._get_tick(major=True)])
  File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 1553, in _get_tick
    return XTick(self.axes, 0, '', major=major, **tick_kw)
  File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 140, in __init__
    self.tick1line = self._get_tick1line()
  File "/usr/lib/pymodules/python2.7/matplotlib/axis.py", line 383, in _get_tick1line
    zorder=self._zorder,
  File "/usr/lib/pymodules/python2.7/matplotlib/lines.py", line 195, in __init__
    self._marker = MarkerStyle()
  File "/usr/lib/pymodules/python2.7/matplotlib/markers.py", line 112, in __init__
    self.set_marker(marker)
  File "/usr/lib/pymodules/python2.7/matplotlib/markers.py", line 171, in set_marker
    self._recache()
  File "/usr/lib/pymodules/python2.7/matplotlib/markers.py", line 116, in _recache
    self._path = Path(np.empty((0,2)))
  File "/usr/lib/pymodules/python2.7/matplotlib/path.py", line 112, in __init__
    if ma.isMaskedArray(vertices):
  File "/usr/local/lib/python2.7/dist-packages/numpy-1.6.2-py2.7-linux-x86_64.egg/numpy/ma/core.py", line 5683, in isMaskedArray
    return isinstance(x, MaskedArray)
RuntimeError: maximum recursion depth exceeded while calling a Python object

At this point, I am not certain where the recursion occurs and how to alleviate this error.

I understand (from other Q&As) that I could enhance my stack limit and get around the problem. However, I don’t consider that as a solution in this particular case and would like to get to the bottom of this.

Any help would be appreciate.

Thanks in advance.

Additional Information:

  • The main functionality that matters include clearing the figure and drawing something new on clicking the canvas.
  • The clicking does not raise this error, if I am not trying to plot something. Thus, I suspect, I’m missing something in handling matplotlib.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:13:48+00:00Added an answer on June 10, 2026 at 8:13 am

    Instead of plt.show(), from within your callback call plt.draw(). The problem is that plt.show runs a mainloop of the GUI library; you just want to update what is shown within the existing mainloop. Using the Qt backend, your code would show the error QCoreApplication::exec: The event loop is already running.

    See What is interactive mode? for more guidance on how to use Matplotlib interactively.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.