[英]Setting the absolute position of a figure using python matplotlib with the MacOSX backend
是否可以使用带有MacOSX后端的matplotlib在屏幕上设置图形的绝对位置?
这个答案
表示可以在其他后端执行此操作,但未提及如何在MacOSX后端执行此操作。
使用MacOSX后端 ,无法设置matplotlib窗口的窗口位置。 但是,一般来讲, 在MacOSX下,您可以使用其他允许这样做的matplotlib后端。 应该自动安装TkAgg
后端(通过Python标准库中的Tkinter绑定使用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
如果您安装带有PyQt绑定的IMHO更好的Qt4 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.