1

I was trying to make Andrew's curves work with this code:

import pandas as pd
from pandas.plotting import andrews_curves

def andrews_curves(df, class_column, normalize = False):
    plt.style.use("ggplot")  
    plt.figure()
    andrews_curves(df, class_column)
    plt.draw()

andrews_curves(players, "RANK")

plt.show()

Where players is my dataframe. And it gave up with a warning:

More than 20 figures have been opened

And then:

RecursionError: maximum recursion depth exceeded while calling a Python object

This only happens with Andrew's Curves, since Parallel Coordinates works fine with almost the same code:

def parallel_coords(df, class_column):
    plt.style.use("ggplot")
    plt.figure()
    parallel_coordinates(df, class_column = class_column, cols = list(df), alpha = 0.4)
    plt.draw()

parallel_coords(players, "RANK")
plt.show()

I've tried to use clear('all'), clf(), and cla() methods, but they all have zero effect.

CDspace
  • 2,639
  • 18
  • 30
  • 36
Alex Green
  • 195
  • 1
  • 1
  • 7

1 Answers1

2

You need to rename the function andrews_curves in your code.

It seems that what you want to do, is call pandas.plotting.andrews_curves, within your own andrews_curves function.

Trouble is, as soon as you define andrews_curves, this replaces the other object of the same name, so the effect of calling your function is that it calls itself recursively, until it hits pythons recursion limit:

Why does Python have a maximum recursion depth?

This doesn't effect parallel_coords, because the function you're calling within there has a different name.

In short, rename your andrews_curves function something else:

def plot_andrews_curves(df, class_column, normalize = False):
    plt.style.use("ggplot")  
    plt.figure()
    andrews_curves(df, class_column)
    plt.draw()

and you won't have this issue.

greg_data
  • 2,247
  • 13
  • 20