简体   繁体   English

使用带有MacOSX后端的python matplotlib设置图形的绝对位置

[英]Setting the absolute position of a figure using python matplotlib with the MacOSX backend

Is it possible to set the absolute position of a figure on the screen using matplotlib with the MacOSX backend? 是否可以使用带有MacOSX后端的matplotlib在屏幕上设置图形的绝对位置?

This answer 这个答案

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

says it can be done for other backends, but doesn't mention how to do it with the MacOSX backend. 表示可以在其他后端执行此操作,但未提及如何在MacOSX后端执行此操作。

With the MacOSX backend there is no way to set the window position of a matplotlib window. 使用MacOSX后端 ,无法设置matplotlib窗口的窗口位置。 However under MacOSX generally speaking you can use other matplotlib backends which allow for this. 但是一般来讲, 在MacOSX下,您可以使用其他允许这样做的matplotlib后端。 The TkAgg backend (using Tcl/Tk via the Tkinter binding in the Python standard library) should be installed automatically. 应该自动安装TkAgg后端(通过Python标准库中的Tkinter绑定使用Tcl/Tk )。

In your python script, before anything else, switch to this backend, then create your plot, show it and now you can move the window with 在您的python脚本中,首先,请切换到此后端,然后创建您的绘图并显示它,现在您可以使用

get_current_fig_manager().window.wm_geometry("+<x-pos>+<y-pos>")

Here a working example: 这是一个工作示例:

import matplotlib
matplotlib.use("TkAgg") # set the backend
import matplotlib.pyplot as plt

plt.figure()
plt.plot([0,1,2,0,1,2]) # draw something
plt.show(block=False)

plt.get_current_fig_manager().window.wm_geometry("+600+400") # move the window

If you install the IMHO nicer Qt4 GUI framework with the PyQt bindings, then you position the window with 如果您安装带有PyQt绑定的IMHO更好的Qt4 GUI框架,则使用

get_current_fig_manager().window.setGeometry(<x-pos>,<x-pos>,<width>,<height>)

Again the full example: 再次是完整的示例:

import matplotlib
matplotlib.use("Qt4Agg") # set the backend
import matplotlib.pyplot as plt

plt.figure()
plt.plot([0,1,2,0,1,2]) # draw something
plt.show(block=False)

plt.get_current_fig_manager().window.setGeometry(600,400,1000,800)

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

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