JudyJiang
JudyJiang

Reputation: 2227

use ipython %matplotlib inline inside python script

I'm writing plot functions in python scripts and using ipython to show them. I want to show the figures inside the page ,so that I used

%matplotlib inline

After that I can show the figures inside.

Is there a way to put this line inside the plot.py script so in ipython I just import the .py without specifying the %matplot code?

Thanks.

Upvotes: 0

Views: 1829

Answers (1)

Ffisegydd
Ffisegydd

Reputation: 53718

You should only have to run %matplotlib inline once per IPython session. All it does it tell matplotlib to plot graphs inline, as opposed to in a separate window.

Running it more than once (say once per script) seems pointless as it won't actually do anything. You could just run it at the top of your session and then not worry about it, your plots will still plot and you can still have plotting functions inside the Python files.

That aside, adding it inside a script is just not possible. It just returns a SyntaxError because you effectively run it as a Python script, not in the IPython terminal where it's set up to handle the magic methods.

Upvotes: 3

Related Questions