如何使用matplotlib设置图形窗口的绝对位置? [英] How do you set the absolute position of figure windows with 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屋!