9

I just wanted to get started on using the matplotlib library for the first time.

So I type the following commands:

import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
data = sp.genfromtxt("web_traffic.tsv", delimiter = "\t");
x = data[:, 0];
y = data[:, 1];
x = x[~sp.isnan(y)];
y = y[~sp.isnan(y)];
plt.scatter(x, y);

And I have received the following error :

<matplotlib.collections.PathCollection object at 0x246abd0>

I have no idea what is causing this, I have just installed the required packages, scipy, matplotlib and it returned to me that particular error. I tried to google it but with no results.

I am using openSuse as OS and python came by default. My main purpose is to start learning using the scykit learn package.

Can you give me any advice on how to get over this error?

Simon
  • 4,999
  • 21
  • 69
  • 97
  • that is basically output of `__repr__`, see [this](http://docs.python.org/2/reference/datamodel.html#object.__repr__) and [this](http://stackoverflow.com/a/121508/625914) – behzad.nouri Dec 09 '13 at 16:53
  • I would recommend `np.isfinite` in place of `~np.isnan`. – askewchan Dec 09 '13 at 23:02

2 Answers2

17

It's not an error message. It's a string representation of an object.

If you ran the code above in an interactive shell, then what you see is a string representation of the value returned by the plt.scatter function.

To actually open the window, you usually need to call plt.show() at the end.

Or if you want it to be interactive, it is suggested to set interactive: True in your .matplotlibrc.

On an unrelated note, semicolons are not needed at the end of the line in Python.

Lev Levitsky
  • 63,701
  • 20
  • 147
  • 175
2

As shown in the matplotlib example for plt.scatter():

"""
Simple demo of a scatter plot.
"""
import numpy as np
import matplotlib.pyplot as plt


N = 50
x = np.random.rand(N)
y = np.random.rand(N)
area = np.pi * (15 * np.random.rand(N))**2 # 0 to 15 point radiuses

plt.scatter(x, y, s=area, alpha=0.5)
plt.show()

As the previous answer stated, you will have to call plt.show() to actually render the plot.

Aaron H
  • 159
  • 1
  • 4