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

AEA
  • 213
  • 2
  • 12
  • 34
  • 1
    are you using ipython with the -pylab option ? – joaquin Nov 19 '13 at 21:25
  • @joaquin yes I think so, see comment to answer provided by elyase – AEA Nov 19 '13 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? – Kyle Kelley Nov 19 '13 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` – AEA Nov 19 '13 at 22:52

2 Answers2

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
elyase
  • 39,479
  • 12
  • 112
  • 119
  • My IPython is already running as follows: `C:\Python27\Scripts\ipython.exe notebook --pylab=inline` – AEA Nov 19 '13 at 22:16
  • @AEA, hmm, your code runs ok in my notebook, can you try resetting your matplotlib settings `rm .matplotlib/matplotlibrc`? Look [here](http://matplotlib.org/users/customizing.html) if you are on windows for the location of your matplotlibrc. – elyase Nov 19 '13 at 23:19
0
from IPython.display import display
from IPython.display import Image

# your code here

Image(data=<your_image_data_here>, embed=True)
rdodev
  • 3,164
  • 3
  • 26
  • 34
  • received the error: `ERROR:astropy:TypeError: is not JSON serializable` – AEA Nov 19 '13 at 22:14
  • 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()` – rdodev Nov 19 '13 at 22:26
  • For reference this is the tutorial I was following. I made it 3 mins in before I hit issues. :( http://www.youtube.com/watch?v=uX4ZirOiWkw – AEA Nov 19 '13 at 22:27