简体   繁体   English

如何在IPython中弹出交互式matplotlib图?

[英]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? 如何在IPython中弹出交互式matplotlib图?

I am using Window 7 as OS. 我使用Window 7作为操作系统。

To clarify the question, I believe you are asking about the IPython notebook, not the IPython command line interpreter. 为了澄清这个问题,我相信你问的是IPython笔记本,而不是IPython命令行解释器。

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. 如果删除该行(并且在启动笔记本时也不使用--pylab内联参数),则绘图将显示在单独的窗口中。

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. 对您链接的答案的评论表明,在内联和非内联之间来回切换并不适用于所有平台。

First you need to stop using %pylab . 首先,您需要停止使用%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? 您可以在我的其他答案中看到更多信息什么是%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

You can do this: %matplotlib qt5 你可以这样做: %matplotlib qt5

And when you want to switch back: %matplotlib inline 当你想要切换回来时: %matplotlib inline

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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