Python Forum

Full Version: matplotlib recursion error when repeatedly displaying a surface
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
When I scroll through my data on a matplotlib 3d surface I get a recursion eror although there is no explicit place where recursion is used.


my code to display the surface (z data stored in zlines array) is:
import matplotlib.pyplot as plt
...
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
...
def display_plot(currentFrameNumber):
    Z = zlines[currentFrameNumber]
    ax.clear()
    ax.set_zlim(0.0, 400.0)
    ax.plot_surface(X, Y, Z, cmap="magma")
    plt.show() 
I scroll through the zlines using a button:
from matplotlib.widgets import Button
...
class Index(object):
    def next(self, event):
        self.__frameNumber  += 1
        display_plot(self.__frameNumber )
...
callback = Index()
axnext = plt.axes([0.81, 0.05, 0.09, 0.075])
bnext = Button(axnext, '>')
bnext.on_clicked(callback.next)
When I press the next button the display correctly shows the next zlines frame. If I do this about 43 times then I get the recursion error:
Error:
RuntimeError: maximum recursion depth exceeded Traceback (most recent call last): File "C:\Python27\lib\site-packages\matplotlib\cbook\__init__.py", line 387, in process proxy(*args, **kwargs) ... File "C:\Python27\lib\site-packages\matplotlib\__init__.py", line 949, in __getitem__ val = dict.__getitem__(self, key) RuntimeError: maximum recursion depth exceeded in cmp
it is something to do with plt.show() because if i remove that call then although it isn't displayed correctly I get no recursion error.
I'm sort of new to python and matplotlib so maybe someone more experienced can more clearly see the error ?
Huh