简体   繁体   中英

How do I combine the %pylab and %run magic commands in IPython?

I am having trouble using pylab in a .py file that I am using the %run command on in IPython.

If I use the IPython interpreter and type

%pylab
plot([1,2,3])

A graph appears, but if I save a file plotting.py with the text

plot([1,2,3])

then use the IPython interpreter and type

%pylab %run plotting.py

I get NameError: name 'plot' is not defined. Is there any way for the file I'm using the %run command on to see the namespaces in my IPython interpreter? Alternatively, is there an easy way to duplicate the %pylab magic function in a .py file?

You can use the -i flag to run in the IPython namespace instead of an empty one:

%run -i plotting.py

See here for other useful flags which you can use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM