Jose Kurian
Jose Kurian

Reputation: 11

Unexpected response while ploting using matplotlib in Python

I'm trying to plot a simple sine wave using the module matplotlib in Python.My code is as follows

>>> import numpy as np
>>> import scipy as sp
>>> import matplotlib.pylab as plt
>>> t = np.linspace(0,0.02,100)
>>> from math import pi
>>> y = np.sin(2*pi*50*t)
>>> plt.plot(t,y)

But for this code I'm getting the following response.

matplotlib.lines.Line2D object at 0xb0243ec

The plot is not generated. What does this mean?

[Issue Update]

I used the function show() as mentioned in the answer below.It worked fine.I changed the x and y values to the following values

  >>> x = [[1.6667,2.815,3.926,4.4,5.295,5.9256,7.827,8.888, 9.11,11.56]]
  >>> y = [[ 10.45356339,11.18586915,11.94317905,12.28168673,12.94723261,13.43770791,15.03196546,16.00241726,16.21326609,18.7330932]]
  >>> plt.plot(x,y)

The response I got was

matplotlib.lines.Line2D object at 0x960f1cc>, , , , , , , , ,

I then used the function show()

plt.show()

The plot window opened.But I couldn't see the curve.

How do I solve this?

Upvotes: 1

Views: 200

Answers (1)

Others
Others

Reputation: 3013

The first example on this page may be informative:

import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()

It looks like your logic is right, you just need to call plt.show().

Upvotes: 1

Related Questions