Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pop up an interactive matplotlib figure in IPython?

Currently, all my figures are inline. I wish to read the coordinates of my mouse locations in an interactive plot.

This answer here

In [2]: %pylab inline 
In [3]: plot(...)

In [4]: %pylab qt  # wx, gtk, osx or tk
In [5]: plot(...) 

does not work for me.

How to pop up an interactive matplotlib figure in IPython?

I am using Window 7 as OS.

like image 854
Sibbs Gambling Avatar asked Nov 15 '13 01:11

Sibbs Gambling


Video Answer


2 Answers

First you need to stop using %pylab. Whatever this command does is not reversible, meaning that you can't switch from inline to some other mode. This command was designed as transition tool and is not longer recommended. You can see more info in my other answer What is %pylab?.

If you want the ability to switch from inline to interactive mode for plots then use following at the start of your notebook:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

When you want to have plot popout, just do this:

%matplotlib qt

You can switch back to inline mode again by doing:

%matplotlib inline
like image 105
Shital Shah Avatar answered Oct 28 '22 05:10

Shital Shah


To clarify the question, I believe you are asking about the IPython notebook, not the IPython command line interpreter.

In the notebook, as with the interpreter, the default is for plots to appear in a separate, interactive window. You are changing this default by calling

%pylab inline

If you remove that line (and also don't use the --pylab inline argument when you launch the notebook), then plots will appear in a separate window.

The comments on the answer you linked to indicate that switching back and forth between inline and not-inline doesn't work on all platforms.

like image 24
David Ketcheson Avatar answered Oct 28 '22 06:10

David Ketcheson