如何更改matplotlib数字的默认窗口位置?

如何更改matplotlib数字的默认窗口位置?

问题描述:

当我创建使用pyplot一个新的身影,在我的屏幕的左上方会自动打开。我希望它在另一个位置打开(例如我的屏幕右上角)。 我迄今已做的是改变位置后使用:如何更改matplotlib数字的默认窗口位置?

import matplotlib.pyplot as plt 
plt.figure() # opens on the top left 
(x,y,w,h) = ... # The desired position 
plt.get_current_fig_manager().window.setGeometry(x,y,w,h) 

有什么办法,我可以设置为默认Matplotlib所需的位置?我抬头看着matplotlibrc文件,但没有发现任何可以帮助我的...任何想法?

+0

的问题是,用于移动窗口的方法是不同的不同后端。所以我不认为有这样做的通用方法,因此它没有出现在'matplotlibrc'文件中。见http://*.com/questions/7449585/how-do-you-set-the-absolute-position-of-figure-windows-with-matplotlib?rq=1 – tom

+0

谢谢,但你提到的话题是关于手动设置位置,并且我想将它设置为默认参数一次。我必须找出这些默认设置,而在于是否能覆盖它们... – user7605211

+0

我的观点是,因为它是为所有的后端不同的做法,我不认为有一种方法在全球范围内覆盖它们。但好运气找... – tom

谢谢你们对你的答案。我知道这些默认设置不受Python支配。 我找到的解决方案是定义一个函数来打开一个新的人物,在正确的地方移动。这样一来,虽然我必须定义或我每次打开一个IPython的控制台一次导入的功能,我不会有事后移动每个人物:

# in file mymodule.py 
import matplotlib.pyplot as plt 

def newfigure(num=None): 
     hfig = plt.figure(num) 
     plt.get_current_fig_manager().window.setGeometry(x,y,w,h) 
     return hfig 

# in a python script, or in the interactive console: 
import matplotlib.pyplot as plt 
import mymodule as mm 

plt.figure() # Opens where I don't want it to 
mm.newfigure() # Opens at position (x,y) and with width and height (w,h)