简体   繁体   English

如何在本地机器上显示matplotlib图?

[英]how to display matplotlib plots on local machine?

I am running ipython remotely on a remote server. 我在远程服务器上远程运行ipython。 I access it using serveraddress:8888/ etc to write code for my notebooks. 我使用serveraddress:8888 / etc访问它来为我的笔记本编写代码。

When I use matplotlib of course the plots are inline. 当我使用matplotlib时,这些图是内联的。 Is there any way to remotely send data so that plot window opens up? 有没有办法远程发送数据,以便打开绘图窗口? I want the whole interactive environment on matplotlib on my local machine and all the number crunching on the server machine? 我想在我的本地机器上matplotlib上的整个交互式环境以及服务器机器上的所有数字运算? This is something very basic....but somehow after rumaging through google for quite a while i can't figure it out. 这是一个非常基本的东西....但不知何故,经过谷歌相当长一段时间后,我无法弄明白。

The upcoming release (1.4.0, should be out by end of August 2014, release candidates are available) will ship with the nbagg backend which provides interactive figures with out needing to go to native clients or resorting to using d3. 即将发布的版本(1.4.0,将于2014年8月底发布,发布候选版本可用)将随nbagg后端一起提供,该后端提供交互式数据,无需去本地客户或使用d3。 All you need to do in your note book is: 您在笔记本中所需要做的就是:

import matplotlib
matplotlib.use('nbagg')
from matplotlib import pyplot as plt

And then to plot 然后去绘制

plt.plot(range(3))
plt.show()

If you want to try this now either build from source or look at one of the release candidates. 如果您现在想要尝试这个,请从源代码构建或查看其中一个候选版本。

There are two major difference between using nbagg and mpld3/bokeh. 使用nbagg和mpld3 / bokeh有两个主要区别。

First, you don't have interface across library interfaces (or learn js!). 首先,您没有跨库接口的接口(或学习js!)。 My understanding is that both of them create a figure, scrap it (which isn't perfect because mpl was not designed with making this easy in mind). 我的理解是,他们都创造了一个人物,废弃它(这并不完美,因为mpl不是为了让这一点变得容易而设计的)。 With nbagg mouse and keyboard call backs should work with no translation, I don't think they can currently be exported to d3. 使用nbagg鼠标和键盘回调应该没有翻译,我认为他们目前不能导出到d3。

The second is that with nbagg all the rendering happens on the server, with the d3-based libraries all of the data must be naively shipped to the browser (bokeh is working on making this smarter and only shipping you data you can see at a useful resolution). 第二个是nbagg所有渲染都发生在服务器上,基于d3的库所有数据必须天真地运送到浏览器(散景正在努力使这个更聪明,只发送你可以看到有用的数据解析度)。 With nbagg the only thing that comes across the network is png deltas. 对于nbagg ,唯一能够通过网络nbagg的是png deltas。

There are a few possibilities 有几种可能性

  1. If your remote machine is somehow unixish, you may use the X Windows (then your session is on the remote machine and display on the local machine) 如果您的远程计算机有点不合适,您可以使用X Windows(然后您的会话在远程计算机上并显示在本地计算机上)

  2. mpld3

  3. bokeh and iPython notebook bokeh和iPython笔记本

  4. nbagg backend of matplotlib nbagg matplotlib后端

Alternative #1 requires you to have an X server on your machine and a connection between the two machines (possibly tunneled through ssh, etc.) So, this is OS dependent, and the performance depends on the connection between the two machines. 备选方案#1要求您在计算机上安装X服务器,并在两台计算机之间建立连接(可能通过ssh进行隧道连接等)。因此,这取决于操作系统,性能取决于两台计算机之间的连接。

Alternatives #2 and #3 are very new but promising. 替代品#2和#3是非常新的,但很有希望。 They have quite different approaches, mpl3d enables the use of standard matplotlib plotting commands, but with large datasets bokeh may be more useful. 它们有不同的方法, mpl3d可以使用标准的matplotlib绘图命令,但是对于大型数据集, bokeh可能更有用。

Alternative #4 is probably the ultimate solution (see tcaswell 's comments), but not yet available without using a development version of matplotlib (ie there may be some installation challenges). 备选方案#4可能是最终解决方案(请参阅tcaswell的评论),但尚未使用matplotlib的开发版本(即可能存在一些安装挑战)尚未提供。 On the other hand, if you can hold your breath for a week, 1.4.0 will be out. 另一方面,如果你能屏住呼吸一周,1.4.0就会消失。

You want to get the regular (zoomable) plot window, right? 你想获得常规(可缩放)绘图窗口,对吧? I think you can not do it in the same kernel as, unfortunately, you can't switch from inline to qt and such because the backend has already been chosen: your calls to matplotlib.use() are always before pylab . 我认为你不能在同一个内核中执行它,不幸的是,你不能从内联切换到qt等因为后端已被选中:你对matplotlib.use()调用总是在pylab之前。

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

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