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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19992023/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 15:11:47  来源:igfitidea点击:

How to pop up an interactive matplotlib figure in IPython?

pythonmatplotlibipythonipython-notebook

提问by Sibbs Gambling

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 作为操作系统。

回答by David Ketcheson

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

为了澄清这个问题,我相信您问的是 IPython notebook,而不是 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.

对您链接的答案的评论表明在内联和非内联之间来回切换不适用于所有平台。

回答by Shital Shah

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?.

首先,您需要停止使用%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

回答by Shekhar

You can do this: %matplotlib qt5

你可以这样做: %matplotlib qt5

And when you want to switch back: %matplotlib inline

当你想切换回来时: %matplotlib inline