如何在IPython笔记本中打开交互式matplotlib窗口?
我将IPython与如何在IPython笔记本中打开交互式matplotlib窗口?,python,matplotlib,jupyter-notebook,Python,Matplotlib,Jupyter Notebook,我将IPython与--pylab=inline一起使用,有时我想快速切换到交互式、可缩放的matplotlib GUI以查看绘图(在终端Python控制台中绘图时弹出的绘图)。我怎么能这么做?最好不要离开或重新启动我的笔记本 IPy笔记本中的内联绘图的问题是,它们的分辨率有限,我无法放大它们以查看一些较小的部分。使用从终端开始的maptlotlib GUI,我可以选择要放大的图形矩形,并相应地调整轴。我试着用它做实验 from matplotlib import interactive int
--pylab=inline
一起使用,有时我想快速切换到交互式、可缩放的matplotlib GUI以查看绘图(在终端Python控制台中绘图时弹出的绘图)。我怎么能这么做?最好不要离开或重新启动我的笔记本
IPy笔记本中的内联绘图的问题是,它们的分辨率有限,我无法放大它们以查看一些较小的部分。使用从终端开始的maptlotlib GUI,我可以选择要放大的图形矩形,并相应地调整轴。我试着用它做实验
from matplotlib import interactive
interactive(True)
及
但那没用。我在网上也找不到任何提示。根据,您应该能够像这样来回切换:
In [2]: %matplotlib inline
In [3]: plot(...)
In [4]: %matplotlib qt # wx, gtk, osx, tk, empty uses default
In [5]: plot(...)
这将弹出一个常规绘图窗口(可能需要重新启动笔记本电脑)
我希望这有帮助。根据,您应该能够像这样来回切换:
In [2]: %matplotlib inline
In [3]: plot(...)
In [4]: %matplotlib qt # wx, gtk, osx, tk, empty uses default
In [5]: plot(...)
这将弹出一个常规绘图窗口(可能需要重新启动笔记本电脑)
我希望这会有所帮助。如果您只想从内联打印切换到交互式打印,然后再切换回来(以便可以平移/缩放),最好使用%matplotlib magic
#interactive plotting in separate window
%matplotlib qt
然后返回html
#normal charts inside notebooks
%matplotlib inline
%pylab magic导入了许多其他东西,甚至可能导致冲突。它是“从pylab导入*”
您还可以使用新的笔记本后端(在matplotlib 1.4中添加):
如果您想在图表中增加交互性,可以查看mpld3和bokeh。mpld3非常好,如果您没有大量的数据点(例如如果您只想从内联打印切换到交互式打印再切换回来(以便可以平移/缩放),那么最好使用%matplotlib magic
#interactive plotting in separate window
%matplotlib qt
然后返回html
#normal charts inside notebooks
%matplotlib inline
%pylab magic导入了一系列其他东西,甚至可能导致冲突。它确实“来自pylab import*”
您还可以使用新的笔记本后端(在matplotlib 1.4中添加):
如果您想在图表中增加交互性,可以查看mpld3和bokeh。如果您没有大量的数据点,mpld3非常棒(例如,对于您的问题,更好的解决方案可能是使用库。它使您能够使用优秀的javascript库制作漂亮的交互式绘图。Highcharts使用HTML
svg
标记,因此您的所有图表实际上都是矢量图像
一些特点:
- 矢量图,您可以下载为.png、.jpg和.svg格式,这样您就不会遇到分辨率问题
- 交互式图表(缩放、滑动、悬停在点上等)
- 可用于IPython笔记本电脑
- 使用异步绘图功能,同时探索数百个数据结构
免责声明:我是该库的开发人员。解决您问题的更好方法可能是使用该库。它使您能够使用优秀的javascript库制作漂亮的交互式绘图。Highcharts使用HTML
svg
标记,因此您的所有图表实际上都是矢量图像
一些特点:
- 矢量图,您可以下载为.png、.jpg和.svg格式,这样您就不会遇到分辨率问题
- 交互式图表(缩放、滑动、悬停在点上等)
- 可用于IPython笔记本电脑
- 使用异步绘图功能,同时探索数百个数据结构
免责声明:我是该库的开发人员从matplotlib 1.4.0开始,现在有一个交互式后端可用于笔记本电脑
%matplotlib notebook
有几个版本的IPython没有注册该别名,但有以下缺点:
%matplotlib nbagg
如果不起作用,请更新IPython
要玩这个,后藤
粘贴
%matplotlib notebook
import pandas as pd
import numpy as np
import matplotlib
from matplotlib import pyplot as plt
import seaborn as sns
ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
ts = ts.cumsum()
df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index,
columns=['A', 'B', 'C', 'D'])
df = df.cumsum()
df.plot(); plt.legend(loc='best')
进入一个代码单元(或者只是修改现有的python演示笔记本)从matplotlib 1.4.0开始,现在有一个交互式后端可在笔记本中使用
%matplotlib notebook
有几个版本的IPython没有注册该别名,但有以下缺点:
%matplotlib nbagg
如果不起作用,请更新IPython
要玩这个,后藤
粘贴
%matplotlib notebook
import pandas as pd
import numpy as np
import matplotlib
from matplotlib import pyplot as plt
import seaborn as sns
ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
ts = ts.cumsum()
df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index,
columns=['A', 'B', 'C', 'D'])
df = df.cumsum()
df.plot(); plt.legend(loc='best')
进入代码单元(或者只修改现有的python演示笔记本)重新启动内核并清除输出(如果不是从新笔记本开始),然后运行
%matplotlib tk
有关更多信息,请转到重新启动内核并清除输出(如果不是从新笔记本开始),然后运行
%matplotlib tk
有关更多信息,请访问2017年5月28日Anaconda网站www.continuum.io/downloads上的“jupyter QTConsole”中的ipython
下面是一个使用ipython magic在单独窗口和内联打印模式之间来回切换的示例
>>> import matplotlib.pyplot as plt
# data to plot
>>> x1 = [x for x in range(20)]
# Show in separate window
>>> %matplotlib
>>> plt.plot(x1)
>>> plt.close()
# Show in console window
>>> %matplotlib inline
>>> plt.plot(x1)
>>> plt.close()
# Show in separate window
>>> %matplotlib
>>> plt.plot(x1)
>>> plt.close()
# Show in console window
>>> %matplotlib inline
>>> plt.plot(x1)
>>> plt.close()
# Note: the %matplotlib magic above causes:
# plt.plot(...)
# to implicitly include a:
# plt.show()
# after the command.
#
# (Not sure how to turn off this behavior
# so that it matches behavior without using %matplotlib magic...)
# but its ok for interactive work...
我正在使用Anaconda网站www.continuum.io/downloads上2017年5月28日发布的“jupyter QTConsole”中的ipython
下面是一个使用ipython magic在单独窗口和内联打印模式之间来回切换的示例
>>> import matplotlib.pyplot as plt
# data to plot
>>> x1 = [x for x in range(20)]
# Show in separate window
>>> %matplotlib
>>> plt.plot(x1)
>>> plt.close()
# Show in console window
>>> %matplotlib inline
>>> plt.plot(x1)
>>> plt.close()
# Show in separate window
>>> %matplotlib
>>> plt.plot(x1)
>>> plt.close()
# Show in console window
>>> %matplotlib inline
>>> plt.plot(x1)
>>> plt.close()
# Note: the %matplotlib magic above causes:
# plt.plot(...)
# to implicitly include a:
# plt.show()
# after the command.
#
# (Not sure how to turn off this behavior
# so that it matches behavior without using %matplotlib magic...)
# but its ok for interactive work...
你可以用
%matplotlib qt
如果出现错误
ImportError:无法导入任何qt绑定
,请将PyQt5安装为:pip安装PyQt5
,它对我有效。您可以使用
%matplotlib qt
如果出现错误
ImportError:无法导入任何qt绑定
,请将PyQt5安装为:pip安装PyQt5
,它对我有效。这是%pylab qt
。在OS X中不起作用。可能在Ubuntu中会有所帮助。不幸的是,您无法来回切换。如果您在开始使用pylab=inline或pyl后尝试切换ab=qt,您将得到:对matplotlib.use()的调用无效,因为已选择了后端;在首次导入pylab、matplotlib.pyplot或matplotlib.backends之前,必须调用matplotlib.use()。我对此投了反对票,因为它对我不起作用,而且仍然不起作用