1

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?

5
  • Where are you doing this, in the command line or in IPython? I'm assuming the latter, so just use prepend your code with %pylab inline. Commented Feb 28, 2015 at 6:39
  • No I'm doing it in the command line Commented Feb 28, 2015 at 6:56
  • Your second issue is caused by the [[ and ]] around your list: you're creating a list inside a list. Use one set of [ ...] and your example plots fine. Commented Feb 28, 2015 at 15:44
  • Please do not import pylab, use import matplotlib.pyplot as plt instead. Commented Feb 28, 2015 at 17:18
  • The Line2D.. is the repr of the objects returned be the call to plot. Commented Feb 28, 2015 at 17:24

1 Answer 1

1

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().

Sign up to request clarification or add additional context in comments.

2 Comments

Hi,I'm facing an issue when I try plotting multiple floating point numbers.Why is this?I've updated this in the question
@JoseKurian I'm no expert on matplotlib. I think you'd be best accepting my answer to your first question, editing out your second question, and then posting it as another question. You'll get way more response that way!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.