当前位置: 代码迷 >> python >> 使用带有MacOSX后端的python matplotlib设置图形的绝对位置
  详细解决方案

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

热度:16   发布时间:2023-06-21 10:51:07.0

是否可以使用带有MacOSX后端的matplotlib在屏幕上设置图形的绝对位置?

这个答案

表示可以在其他后端执行此操作,但未提及如何在MacOSX后端执行此操作。

使用MacOSX后端 ,无法设置matplotlib窗口的窗口位置。 但是一般来讲, 在MacOSX下,您可以使用其他允许这样做的matplotlib后端。 应该自动安装TkAgg后端(通过Python标准库中的绑定使用Tcl/Tk )。

在您的python脚本中,首先,请切换到此后端,然后创建您的绘图并显示它,现在您可以使用

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

这是一个工作示例:

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

如果您安装带有绑定的IMHO更好的 GUI框架,则使用

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

再次是完整的示例:

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)
  相关解决方案