你如何用matplotlib设置图形窗口的绝对位置? [英] How do you set the absolute position of figure windows with matplotlib?

查看:82
本文介绍了你如何用matplotlib设置图形窗口的绝对位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个简单的 Python 应用程序,它使用 matplotlib 在屏幕上显示一些数字.生成的图形数量基于用户输入和应用程序生命周期中的变化.用户可以发出绘图"命令来生成带有所选数据系列的新图形窗口.为了改善用户体验,我想提供另一个命令,该命令可以通过编程方式以某种方便的方式排列所有打开的图形窗口(例如,在可用的屏幕空间上平铺它们).

I'm writing a simple Python application that uses matplotlib to display a few figures on screen. The number of figures generated is based on user input and changes throughout the application's life. The user has the ability to issue a "plot" command to generate a new figure window with the selected data series. In order to improve the user experience, I would like to provide another command that would programmatically arrange all open figure windows in some convenient arrangement (e.g. tile them across the available screen space).

我相信已经找到允许我调整图形窗口大小(以像素为单位)的 API,但在找到设置它们在屏幕上的绝对位置的方法方面没有取得任何成功.有没有办法在不深入研究正在使用的任何后端的细节的情况下做到这一点?我希望以与后端无关的方式执行此操作,这样我就可以避免依赖将来可能会更改的实现细节.

I believe to have found APIs that allow me to adjust the size of the figure window (in pixels), but haven't had any success in finding a way to set their absolute position on screen. Is there a way to do this without delving into the details of whatever backend is in use? I would like to do this in a backend-agnostic way so I can avoid relying upon implementation details that might change in the future.

推荐答案

我不知道一种后端不可知的方法来做到这一点,但对于一些常见的后端,例如 WX、tkagg,绝对可以做到这一点等

there is not that I know a backend-agnostic way to do this, but definitely it is possible to do it for some common backends, e.g., WX, tkagg etc.

import matplotlib
matplotlib.use("wx")
from pylab import *
figure(1)
plot([1,2,3,4,5])
thismanager = get_current_fig_manager()
thismanager.window.SetPosition((500, 0))
show()

每个@tim 在下面的评论部分,你可能想切换到

per @tim at the comment section below, you might wanna switch to

thismanager.window.wm_geometry("+500+0")

相反.对于TkAgg,只需将其更改为

instead. For TkAgg, just change it to

thismanager.window.wm_geometry("+500+0")

所以我认为你可以用尽所有能够做到这一点的后端,如果强加某个后端不是一种选择.

So I think you can exhaust through all the backends that are capable of doing this, if imposing a certain one is not an option.

这篇关于你如何用matplotlib设置图形窗口的绝对位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆