0

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.

5
  • You should only have to run this once per ipython session. Why don't you just run it once (at the top) and then use your code as normal?
    – Ffisegydd
    Commented Jan 16, 2015 at 14:28
  • I want the plotting functions in the script to be executed once loaded (imported)
    – JudyJiang
    Commented Jan 16, 2015 at 14:32
  • That's fine, you can have the plotting functions in the script anyway, all %matplotlib inline does is tell IPython to plot things inline...
    – Ffisegydd
    Commented Jan 16, 2015 at 14:32
  • @Ffisegydd so there's no way to add this inside the script?
    – JudyJiang
    Commented Jan 16, 2015 at 14:35
  • Would putting this in your ipython profile solve your problem? ipython.org/ipython-doc/dev/config/intro.html
    – Håken Lid
    Commented Jan 16, 2015 at 15:15

1 Answer 1

3

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.