0

In an Ipython notebook, I have defined a function to plot data. I would like to import the function in my current notebook to use it. I tried to convert the mynotebook.ipynb to a mynotebook.py file and then just do

from mynotebook import myfunction

But I get an error. The problem is that I wrote the original notebook with starting ipython with the option pylab. That means that to make it work, instead of writing something like

x = arange(1,10)
y = arange(1,10)
scatter(x, y)

I should change it to the more explicit:

import numpy as np
import matplotlib as plt
x = np.arange(1,10)
y = np.arange(1,10)
plt.scatter(x, y)

In my case my file is quite complex and changing it will be a pain... Is there a way to import my notebook without modifying the .py file line by line???

1 Answer 1

1
from matplotlib.pylab import *

will take care of all of your imports, but some of the interactive stuff (show etc) might not work correctly.

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

Comments

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.