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 测试是否可以将界面显示在本地窗口



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

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

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

Xshell : Python实现的简单shell

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

没有GUI时使用matplotlib绘图

需添加: import matplotlib as mpl mpl.use('Agg') 而且必须添加在import matplotlib.pyplot之前,否则无效 最后在pl...

人脸特征点检测:VanillaCNN

《Facial Landmark Detection with Tweaked Convolutional Neural Networks》论文解读论文地址: http://www.openu.a...

Tensorflow一些常用基本概念与函数

原文地址:http://blog.csdn.net/lenbow/article/details/52152766 1、tensorflow的基本运作 为了快速的熟悉TensorF...

xshell无法打开virt-manager的图形界面

之前一直在windows上用xshell来管理远程的服务器,也可以打开virt-manager的图形界面。后来重装了一下windows系统,发现图形界面打不开了,同事的xshell可以正常打开,所以定...
  • cnyyx
  • cnyyx
  • 2015年01月23日 10:36
  • 7205

python的图形界面库wxpython的快速简单使用

以wxpython库为基础的python图形界面的设计与实现

XShell+Xmanager实现在XShell中显示远程服务器的图形界面

第一种方法:   你可以使用Xmanager软件,远程安装Oracle软件,Linux操作系统使用字符安装并不影响这种方式的使用。这个方案也可以大大优化你的Linux系统的性能,进而提高你的数据库...

python小图形界面程序

  • 2014年07月01日 20:52
  • 15KB
  • 下载

wxpython python开发图形界面

  • 2012年05月29日 23:05
  • 13.59MB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:python库matplotlib如何通过xshell生成图形界面
举报原因:
原因补充:

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