Drak
Drak

Reputation: 129

python AttributeError: 'tuple' object has no attribute 'show' using matplotlib

Weird error maybe caused by matplotlib?

asd=bp.plot_measurements(ps[:, 0], ps[:, 1])
asd.show()

The error:

AttributeError: 'tuple' object has no attribute 'show'

and this is the definition:

def plot_measurements(xs, ys=None, color='k', lw=2,  label='Measurements', lines=False, **kwargs):
    """ Helper function to give a consistant way to display
    measurements in the book.
    """

    plt.autoscale(tight=True)
    if lines:
        if ys is not None:
            return plt.plot(xs, ys, color=color, lw=lw, ls='--', 
    label=label, **kwargs)
        else:
            return plt.plot(xs, color=color, lw=lw, ls='--', label=label, 
    **kwargs)
    else:
        if ys is not None:
            return plt.scatter(xs, ys, edgecolor=color, facecolor='none',
                        lw=2, label=label, **kwargs),
        else:
            return plt.scatter(range(len(xs)), xs, edgecolor=color, 
    facecolor='none', lw=2, label=label, **kwargs)

Any idea what could cause this?

Upvotes: 2

Views: 5598

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339705

The function plot_measurements has several possible return types. It can be a tuple of lines (if lines == True) or a Collection or a tuple of Collections (if lines ==False).

In all of the three possible cases, the return type is an object which does not have a show() method.

Instead you probably want to call plt.show(), where plt is matplotlib.pyplot.

Upvotes: 2

Related Questions