Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python - error while using matplotlib.pyplot.scatter function for the first time

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?

like image 655
Simon Avatar asked Dec 09 '13 16:12

Simon


People also ask

How do I get rid of Xticks and Yticks in Matplotlib?

Matplotlib removes both labels and ticks by using xaxis. set_visible() set_visible() method removes axis ticks, axis tick labels, and axis labels also.

How do I get rid of Ylabel in Matplotlib?

To hide or remove X-axis labels, use set(xlabel=None). To display the figure, use show() method.


1 Answers

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.

like image 76
Lev Levitsky Avatar answered Oct 07 '22 23:10

Lev Levitsky