Search code examples
numpymatplotlibscipyscatter-plothierarchical-clustering

TypeError: scatter() got multiple values for argument 'c'


I am trying to do hierarchy clustering on my MFCC array 'signal_mfcc' which is an ndarray with dimensions of (198, 12). 198 audio frames/observation and 12 coefficients/dimensions?

I am using a random threshold of '250' with 'distance' for the criterion as shown below:

    thresh = 250
    print(signal_mfcc.shape)
    clusters = hcluster.fclusterdata(signal_mfcc, thresh,    criterion="distance")

With the specified threshold, the output variable 'cluster' is a sequence [1 1 1 ... 1] with the length of 198 or (198,) which I assume points all the data to a single cluster. Then, I am using pyplot to plot scatter() with the following code:

    # plotting
    print(*(signal_mfcc.T).shape)
    plt.scatter(*np.transpose(signal_mfcc), c=clusters)
    plt.axis("equal")
    title = "threshold: %f, number of clusters: %d" % (thresh) len(set(clusters)))
    plt.title(title)
    plt.show()

The output is:

    plt.scatter(*np.transpose(signal_mfcc), c=clusters)
    TypeError: scatter() got multiple values for argument 'c'

The scatter plot would not show. Any clues to what may went wrong? Thanks in advance!


Solution

  • From this SO Thread, you can see why you have this error.

    Fom the Scatter documentation, c is the 2nd optional argument, and the 4th argument total. This error means that your unpacking on np.transpose(signal_mfcc) returns more than 4 items. And as you define c later on, it is defined twice and it cannot choose which one is correct.

    Example :

    def temp(n, c=0):
        pass
    temp(*[1, 2], c=1)
    # Traceback (most recent call last):
    #   File "<stdin>", line 1, in <module>
    # TypeError: temp() got multiple values for argument 'c'