Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Assume that I have some data, and I want to create a plot of this data by passing it to a custom plotting function (myplot()). I am using the matplotlib's modules in myplot().

I would like myplot() to return the handle to a figure, and not plot display the plot when I call this function. Here is a sample code and output from iPython.

enter image description here

I have two questions regarding this:

  1. Why do I still see a plot, even though I am assigning the output of myplot() to f?
  2. What do I need to supress this plot when I am assigning the output of myplot() to a variable?
share|improve this question
This is only an iPython Notebook feature, right? Because I don't see a plot when I pass the figures around in IDLE. – Sukrit Kalra Jul 9 at 13:44

2 Answers

up vote 3 down vote accepted

Start ipython with

ipython notebook

rather than

ipython notebook --pylab=inline

enter image description here

share|improve this answer
I think you do not have to start the whole notebook-session in non-inline-modus. You can control the inline-backend-behaviour with the following command. %config InlineBackend.close_figures = False This will prevent your plots from beeing closed (thus shown inside the browser) immediately. – ala Jul 9 at 14:16

If you do not want to start the whole notebook in non-inline-modus you can just use the following code:

%config InlineBackend.close_figures = False

def myplot(t,x):
    fig = figure()
    x = plot(t,x)
    fig.savefig('plot.png') # This is just to show the figure is still generated
    return fig

t = arange(0,6,0.01)
x = sin(t)

f = myplot(t,x)
share|improve this answer
This did not work. I still get the same output as shown in my question. – siva82kb Jul 10 at 13:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.