0

SO I have recently started trying to use ipython, I am finding I cannot get it to produce an output graph. I am running the following code in ipython:

from sklearn import linear_model
regr = linear_model.LinearRegression()

regr.fit(x, y)
pl.plot(x, y, 'o')
pl.plot(x_test, regr.predict(x_test))

and I am recieving the output:

[<matplotlib.lines.Line2D at 0x21d453b0>]

With no image attatched.

I installed ipython using the pythonxy package. Any thoughts of suggestions on methods to get plots outputting correctly in ipython

See attached image:
enter image description here

4
  • 1
    are you using ipython with the -pylab option ? Commented Nov 19, 2013 at 21:25
  • @joaquin yes I think so, see comment to answer provided by elyase Commented Nov 19, 2013 at 22:18
  • Which version of IPython are you on? Technically, I realize you tried using --pylab=inline. Can you just try running %matplotlib in a cell and then re-execute that code? Commented Nov 19, 2013 at 22:41
  • I am running ipython-1.1.0-py2.7.egg-info I tried to use Using %matplotlib and i recieved matplotlib backend: Qt4Agg Commented Nov 19, 2013 at 22:52

2 Answers 2

6

Try running in a cell:

%pylab inline    # or
%matplotlib inline

After that the plots should be displayed inline. Alternatively start the notebook using the inline option in the command line:

ipython notebook --pylab=inline
Sign up to request clarification or add additional context in comments.

2 Comments

My IPython is already running as follows: C:\Python27\Scripts\ipython.exe notebook --pylab=inline
@AEA, hmm, your code runs ok in my notebook, can you try resetting your matplotlib settings rm .matplotlib/matplotlibrc? Look here if you are on windows for the location of your matplotlibrc.
0
from IPython.display import display
from IPython.display import Image

# your code here

Image(data=<your_image_data_here>, embed=True)

3 Comments

received the error: ERROR:astropy:TypeError: <matplotlib.lines.Line2D object at 0x225DADB0> is not JSON serializable
I'm not sure what format is output from plot() but it needs to be png or else pass the argument format='jpg' to Image()
For reference this is the tutorial I was following. I made it 3 mins in before I hit issues. :( youtube.com/watch?v=uX4ZirOiWkw

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.