python库matplotlib如何通过xshell生成图形界面

原创 2016年06月01日 10:50:57

以下摘自stack overflow:

X11 follows a client/server model, where the X server accepts requests for graphical output from client applications (e.g. interactive matplotlib sessions), and sends back user input from the keyboard, mouse etc. In order for this model to work, client applications need to know which X server to send their requests to. This is controlled by the $DISPLAY environment variable. In the case where you are connecting to a remote X session (for example over an SSH connection), the $DISPLAY variable in your remote session needs to point to your local X server.

The $DISPLAY variable is structured like this:

hostname:displaynumber.screennumber

Not all parts may be present - the hostname is usually omitted for local sessions, and the screen number is also omitted if there is only one screen. In a local terminal session on laptop, my $DISPLAYlooks like this:

alistair@laptop:~$ echo $DISPLAY
:0

Provided that the remote server also supports X11, it's possible to open graphical windows on the remote machine and have them appear on your local machine using X11 forwarding. For an SSH connection you do this by passing the -X (or -Y) flag.

For example:

alistair@laptop:~$ ssh -X alistair@workstation.address.co.uk
alistair@workstation:~$ echo $DISPLAY
localhost:10.0

The remote SSH server should take care of setting the $DISPLAY variable appropriately when you open the connection. In this particular case, localhost:10.0 is actually a 'proxy' X11 server running on the remote machine that listens on display 10 and relays commands to your local X server over the SSH connection (take a look at this if you're interested in the details).

Now you should be able to start a remote IPython session, import matplotlib using an interactive backend, and create plot windows which will then appear on your local machine. Since your keyboard/mouse input and the display output are now passing over an encrypted network connection, the plot windows will be less responsive than you're used to for a local session.

Another word of warning: if you have an IPython session open with an interactive matplotlib session running it is impossible to close the SSH connection without killing the IPython process. I also sometimes call matplotlib.use("Agg") before I start a long-running process that imports matplotlib - that way I can disconnect from the remote server without killing the process.

大概意思就是,用xshell远程连接linux,然后生成的图形界面必须指定$DISPLAY环境变量,然后在本地环境显示出来。这是一个解决思路。除此之外,还有一个更方便的方法:

step1:安装xmanager,注册码从网上搜索

step2:

将x11连接到本地xmanager,这样,远程的图形界面就可以通过本地xmanager显示出来。

step3:设置成功后,登陆远端Linux主机,执行 gtk-demo 测试是否可以将界面显示在本地窗口



版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

matplotlib绘图进阶

http://blog.csdn.net/pipisorry/article/details/37766161远程绘图,在matplotlib中的一个坐标轴上画一条直线光标,绘制LaTeX数学公式,对...

matplotlib绘图基础

http://blog.csdn.net/pipisorry/article/details/37742423matplotlib介绍        matplotlib 是python最著名的绘图库...

Python实现ssh批量登录并执行命令

局域网内有一百多台电脑,全部都是linux操作系统,所有电脑配置相同,系统完全相同(包括用户名和密码),ip地址是自动分配的。现在有个任务是在这些电脑上执行某些命令,者说进行某些操作,比如安装某些软件...

实习点滴(1)--Xshell如何运行Python中的某个函数

这是实习的这五天来第一次来到CSDN博客,想写个专题,来记录我的第一份实习所学习到的知识,声明:不涉及到公司的机密,只是记录所学到的技术。         来到公司,自然不仅仅会在自己的PC机上运行程...

Xshell : Python实现的简单shell

原项目为:https://github.com/supasate/yoshXshell对原项目进行了重构(面向对象)和扩展(支持重定向,管道,&) github地址:https://github.c...

matplotlib(二)——style sheets定制图、工具栏

使用style sheets定制图style package提供了对切换图表样式的支持,它里面的参数与matplotlib.rc(matplotlib中默认的样式表文件 )中的参数一样。看一下matp...

Matplotlib 中文用户指南 7.1 交互式导航

交互式导航 原文:Interactive navigation 译者:飞龙 协议:CC BY-NC-SA 4.0 所有图形窗口都带有导航工具栏,可用于浏览数据集。 以下是工具栏...

配置远程Linux云服务器+可视化工作环境+jupyter notebook

配置远程Linux云服务器+可视化环境一直希望能像“黑客军团”里的男主那样,随时随地就可以开始hack。后来才逐渐发现,他实际上登录的是一个远程服务器,在已经配置好的服务器上,开始hack&工作。并且...

一步步从零开始:使用PyCharm和SSH搭建远程TensorFlow开发环境

一般而言,大型的神经网络对硬件能力有着较高的需求――往往需要强劲的 GPU 来加速计算。但是你也许还是想拿着一台笔记本坐在咖啡店里安静地写 TensorFlow 代码,同时还能享受每秒数万亿次的浮点运...

CentOS中python输入import matplotlib.pyplot提示有错误

在CentOS中安装matplotlib(使用命令yum install python-matplotlib)后,在
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)