Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have a function return a figure in python (using matplotlib)?

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?
like image 926
siva82kb Avatar asked Jul 09 '13 13:07

siva82kb


1 Answers

Start ipython with

ipython notebook

rather than

ipython notebook --pylab=inline

enter image description here

like image 68
unutbu Avatar answered Sep 29 '22 09:09

unutbu